in Swift: Difference between Array VS NSArray VS [AnyObject]

前端 未结 4 1672
时光说笑
时光说笑 2020-12-04 14:17

As the title says, what\'s the difference between Array vs NSArray vs [AnyObject]?

Also, what is most recommended way of approaching this. What i mean recommended is

4条回答
  •  孤街浪徒
    2020-12-04 14:52

    Array is a Swift construct, and generic struct, which means that it can be an array of any specific type (Int, String, AnyObject, etc.)

    [T] is syntactic sugar for Array

    AnyObject is an object of any class, including Objective-C classes.

    NSArray is an Objective-C construct that can hold any Objective-C object and is transparently mapped to and from Array

提交回复
热议问题