I use NSKeyedArchiver.archivedDataWithRootObject(obj) to transform an object to NSData. The archivedDataWithRootObject(obj) method require its parameter to be an NSObject, conforming to NSCoding.
I tried archiving Swift Strings, Arrays, and Dictionarys, and it worked well. So I think String is an NSObject conforming to NSCoding.
I also checked this code in a playground, to confirm that String is an NSObject:
var str = "Hello, playground"
let isObject = (str is NSObject) // isObject is true
But when I navigate to String's definition (with Cmd + Click), it shows that String is a struct. I cannot find the code showing that String is an NSObject.
public struct String {
/// An empty `String`.
public init()
}
So, why in the String definition, can't I find the code showing that String is an NSObject? And why can a struct be an NSObject?