swift VS NSObject

來源:互聯網
上載者:User

標籤:effective   for   建立   --   pen   ocs   ons   native   stack   

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-nsobjecthttps://docs.swift.org/swift-book/LanguageGuide/Inheritance.html swift中,一個對象可以不繼承自NSObject
- 繼續自NSObject 可以使用KVC方法給屬性設定數值  =》如果是模型對象,最好還是使用NSObject
- 如果對象,沒有屬性,或者不依賴KVC , 可以建立一個沒有父類的對象!, 對象的量級比較輕,載入時,就在記憶體建立
   什麼,記憶體消耗小 49357225

swift VS NSObject

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.