Skip to content

Commit df7f9f5

Browse files
committed
NSString._fastContents: Remove use of deprecated UTF-16 String properties.
- String._guts._isContiguousUTF16 is deprecated and always returns false. - String._guts.startUTF16 is deprecated and aborts if called. - _fastContents will always return nil as Swift Strings do not store UTF-16 data so no valid pointer can be returned, only nil. So hardcode this method to return nil.
1 parent 9365168 commit df7f9f5

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

Sources/Foundation/NSString.swift

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -344,16 +344,14 @@ open class NSString : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSC
344344
}
345345
return nil
346346
}
347-
347+
348348
internal var _fastContents: UnsafePointer<UniChar>? {
349-
if type(of: self) == NSString.self || type(of: self) == NSMutableString.self {
350-
if _storage._guts._isContiguousUTF16 {
351-
return UnsafePointer<UniChar>(_storage._guts.startUTF16)
352-
}
353-
}
349+
// The string held in _storage is a Swift string, natively stored as UTF-8. There is no UTF-16 data that can be
350+
// returned here. If, in the future, CFStrings are lazy-bridged to Swift Strings and the address of the CFString
351+
// is held as a foreign object in the String then it may be possible to return a pointer here.
354352
return nil
355353
}
356-
354+
357355
internal var _encodingCantBeStoredInEightBitCFString: Bool {
358356
if type(of: self) == NSString.self || type(of: self) == NSMutableString.self {
359357
return !_storage._guts._isContiguousASCII

0 commit comments

Comments
 (0)