-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Expose __SwiftNativeNSString for Foundation's use, as well as an initializer to create Strings from them #39229
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -658,7 +658,7 @@ internal func _SwiftCreateBridgedString_DoNotCall( | |
// This allows us to subclass an Objective-C class and use the fast Swift | ||
// memory allocator. | ||
@objc @_swift_native_objc_runtime_base(__SwiftNativeNSStringBase) | ||
class __SwiftNativeNSString { | ||
@_spi(Foundation) public class __SwiftNativeNSString { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trying to minimize the ABI exposure here. I could expose __StringStorage and __SharedStringStorage, but since this is their superclass, I would need to expose it anyway, and this is sufficient for hanging @objc implementations off of that operate in terms of the new initializer. |
||
@objc internal init() {} | ||
deinit {} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,28 @@ import SwiftShims | |
internal let _cocoaASCIIEncoding:UInt = 1 /* NSASCIIStringEncoding */ | ||
internal let _cocoaUTF8Encoding:UInt = 4 /* NSUTF8StringEncoding */ | ||
|
||
extension String { | ||
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) | ||
@_spi(Foundation) | ||
public init?(_nativeStorage: AnyObject) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this used for, and is this tested anywhere? Comments? That's a lot of unsafe unchecked downcasts and it's not clear to me what is assumed about |
||
let knownOther = _KnownCocoaString(_nativeStorage) | ||
switch knownOther { | ||
case .storage: | ||
self = _unsafeUncheckedDowncast( | ||
_nativeStorage, | ||
to: __StringStorage.self | ||
).asString | ||
case .shared: | ||
self = _unsafeUncheckedDowncast( | ||
_nativeStorage, | ||
to: __SharedStringStorage.self | ||
).asString | ||
default: | ||
return nil | ||
} | ||
} | ||
} | ||
|
||
// ObjC interfaces. | ||
extension _AbstractStringStorage { | ||
@inline(__always) | ||
|
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.
This was apparently missing all along, who knew.