Skip to content

Instantly share code, notes, and snippets.

@Catfish-Man
Created July 12, 2022 03:00
Embed
What would you like to do?
How many different kinds of NSString can we generate with the same code?
import Foundation
func examine(_ str: String) {
print("\"\(str)\"")
print("bridges as: \(type(of: str as NSString))")
str.withCString {
print("inits an NSString as: \(type(of: NSString(cString: $0, encoding: String.Encoding.ascii.rawValue)!))")
}
print("\n")
}
examine("hellohello")
examine("hellohellQ")
examine("hQllo")
examine("hëllo")
examine("hellohellohellohello")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment