码迷,mamicode.com
首页 > 编程语言 > 详细

structure vs class in swift language

时间:2018-06-14 18:19:24      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:use   for   col   class   multiple   cts   multi   cannot   conf   

Both class and structure can do:

  • Define properties to store values
  • Define methods to provide functionality
  • Be extended
  • Conform to protocols
  • Define intialisers
  • Define Subscripts to provide access to their variables

Only class can do:

  • Inheritance
  • Type casting
  • Define deinitialisers
  • Allow reference counting for multiple references.

 

Major differences between Structures and Classes:

  • Structures cannot Inherit from other types.
  • Classes use type-casting to treat a class as a superclass or subclass, as well as check protocol adoption. Structs can only use the protocol adoption part.
  • Structures do not have deinitializers.
  • Structures cannot have multiple references to the same instance

https://stackoverflow.com/questions/24217586/structure-vs-class-in-swift-language

structure vs class in swift language

标签:use   for   col   class   multiple   cts   multi   cannot   conf   

原文地址:https://www.cnblogs.com/feng9exe/p/9183367.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!