我想知道的区别NSObject
和struct
..Following例如将解释这两种情况下
在 struct
struct UserDetails{ var userName:String var userID:String var userAge:String func userDescription()->String{ return "name " + userName + "age " + userAge } }
在NSObject
课堂上
class UserDetails: NSObject { var userName:String? var userID:String? var userAge:String? func userDescription()->String{ return "name " + userName! + "age " + userAge! } }
你能告诉我在哪里必须NSObject
上课,我必须在哪里使用struct
..?
1)结构通过值传递,类实例通过引用传递2)类可以是子类,结构不能.
Class是否是NSObject的子类(大多数)是无关紧要的.你也可以说:
class UserDetails { var userName:String? var userID:String? var userAge:String? func userDescription()->String{ return "name " + userName! + "age " + userAge! } }