Skip to content

Commit 8a03fde

Browse files
committed
Redo CFStringCreateWithBytes shim
1 parent 4d96a7d commit 8a03fde

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Darwin/Foundation-swiftoverlay/String.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,28 @@ extension Substring : _ObjectiveCBridgeable {
9696
}
9797

9898
extension String: CVarArg {}
99+
100+
/*
101+
This is on NSObject so that the stdlib can call it in StringBridge.swift
102+
without having to synthesize a receiver (e.g. lookup a class or allocate)
103+
104+
In the future (once the Foundation overlay can know about SmallString), we
105+
should move the caller of this method up into the overlay and avoid this
106+
indirection.
107+
*/
108+
private extension NSObject {
109+
// The ObjC selector has to start with "new" to get ARC to not autorelease
110+
@_effects(releasenone)
111+
@objc(newTaggedNSStringWithASCIIBytes_:length_:)
112+
func createTaggedString(bytes: UnsafePointer<UInt8>,
113+
count: Int) -> AnyObject? {
114+
//TODO: update this to use _CFStringCreateTaggedPointerString once we can
115+
return CFStringCreateWithBytes(
116+
kCFAllocatorSystemDefault,
117+
bytes,
118+
count,
119+
CFStringBuiltInEncodings.UTF8.rawValue,
120+
false
121+
) as NSString as NSString? //just "as AnyObject" inserts unwanted bridging
122+
}
123+
}

0 commit comments

Comments
 (0)