Are Swift String, Array and Dictionary NSObjects strings? Why can a structure be an NSObject?

I use NSKeyedArchiver.archivedDataWithRootObject(obj)to convert an object to NSData. A method archivedDataWithRootObject(obj)requires that its parameter be NSObjectappropriate NSCoding.

I tried archiving Swift Strings, Arrays, and Dictionarys, and it worked well. Therefore, I think it is Stringappropriate NSObject, appropriate NSCoding.

I also checked this code on the playground to confirm what Stringis NSObject:

var str = "Hello, playground"
let isObject = (str is NSObject) // isObject is true

But when I get to the definition String(using Cmd + Click), it shows what it Stringis struct. I can not find the code showing what Stringis NSObject.

public struct String {
    /// An empty `String`.
    public init()
}

, String , , String NSObject? NSObject?

+4
1

String, Array, Dictionary Objective-C (NSString, NSArray NSDictionary) .

NSObject , NSString, . (Swift) String , NSString, , .

+4

All Articles