-
Notifications
You must be signed in to change notification settings - Fork 1.1k
ObjCBool: Add boolValue property #1223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@phausler Does this look correct? |
@swift-ci please test |
What advantages/disadvantages does this have? The code looks less Swifty than before with the introduction of ObjCBool in the places that it has been used. |
Foundation/NSSwiftRuntime.swift
Outdated
@@ -25,6 +25,9 @@ import CoreFoundation | |||
#endif | |||
|
|||
public typealias ObjCBool = Bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can/should this be a struct as documented? https://developer.apple.com/documentation/objectivec/objcbool
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alblue This is part of making the unit tests run on native Darwin Foundation.
@ianpartridge I suspect yes, it may require a full implementation to match Darwin's foundation, I will investigate it.
ObjCBool is defined in https://github.com/apple/swift/blob/master/stdlib/public/SDK/ObjectiveC/ObjectiveC.swift#L27 we should probably lift the implementation instead of aliasing Bool |
I converted |
I had another think about this. The |
it doesn't have much meaning once compiled but the one thing it does do is keep us honest for compatibility - so in the spirit of the project (to offer cross platform compatibility with the fundamentals offered by Foundation and cross platform interoperation) it seems to be the best approach even though it is named perhaps inappropriately (more a naming choice by the standard library) it statically enforces our goals to offer the same API surface area for things that can be represented as a cross platform interface. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me, I think this will keep us honest for our changes.
Foundation/NSSwiftRuntime.swift
Outdated
} | ||
|
||
// Functions used to implicitly bridge ObjCBool types to Swift's Bool type. | ||
public // COMPILER_INTRINSIC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are these functions really needed? traditionally we like to avoid underscore public methods unless absolutely needed (like the reference to structure bridge methods) for functionality.
@@ -309,7 +309,7 @@ open class NSURL : NSObject, NSSecureCoding, NSCopying { | |||
|
|||
let thePath = _standardizedPath(path) | |||
|
|||
var isDir : Bool = false | |||
var isDir: ObjCBool = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why this is necessary... It's only going to get passed to an API which takes bool
so can't it stay as bool
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it calls
let _ = FileManager.default.fileExists(atPath: absolutePath, isDirectory: &isDir)
and thats defined as:
open func fileExists(atPath path: String, isDirectory: UnsafeMutablePointer<ObjCBool>?) -> Bool
and ObjCBool
is not a simple Bool
anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohhhh, thanks.
1ed409c
to
e481b2a
Compare
@phausler I removed the |
@swift-ci please test and merge |
Found after testing Darwin compatibility where the ObjCBool type has a
boolValue
property