Skip to content

Instantly share code, notes, and snippets.

@Catfish-Man
Created July 12, 2022 03:00
Show Gist options
  • Save Catfish-Man/56ece650e4af67d88b3d02eabd8c6329 to your computer and use it in GitHub Desktop.
Save Catfish-Man/56ece650e4af67d88b3d02eabd8c6329 to your computer and use it in GitHub Desktop.
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