swift VS NSObject

Any class that does not inherit from another class is known as a base class.

Swift classes do not inherit from a universal base class. Classes you define without specifying a superclass automatically become base classes for you to build upon.

 

Swift classes do not inherit from a universal base class. Classes you define without specifying a superclass automatically become base classes for you to build upon.

 

According to the language reference, there is no requirement for classes to subclass any standard root class, so you can include or omit a superclass as needed.

Note that omitting a superclass from the class declaration, doesn't assign a implicit base superclass of any kind. It defines a base class, which will effectively become the root for an independent class hierarchy.

From the language reference:

Swift classes do not inherit from a universal base class. Classes you define without specifying a superclass automatically become base classes for you to build upon.

Trying to reference super from a class without a super class (i.e. a base class) will result in a compile time error

'super' members cannot be referenced in a root class
 
https://stackoverflow.com/questions/24057525/swift-native-base-class-or-nsobject
https://docs.swift.org/swift-book/LanguageGuide/Inheritance.html
 
swift中,一个对象可以不继承自NSObject
- 继续自NSObject 可以使用KVC方法给属性设置数值  =》如果是模型对象,最好还是使用NSObject
- 如果对象,没有属性,或者不依赖KVC , 可以建立一个没有父类的对象!, 对象的量级比较轻,加载时,就在内存创建
   什么,内存消耗小
 
https://blog.csdn.net/hsf_study/article/details/49357225

转载于:https://www.cnblogs.com/feng9exe/p/9416043.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值