structure vs class in swift language

Posted feng9exe

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了structure vs class in swift language相关的知识,希望对你有一定的参考价值。

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的主要内容,如果未能解决你的问题,请参考以下文章

Spark Streaming vs. Structured Streaming

python Mean Squared Error vs. Structural Similarity Measure两种算法的图片比较

[Data Structure] Stack Implementation in Python

`%in%` 和 `==` 有啥区别?

Redundancy and Latency in Structured Buffer Use

[Algorithms] Tree Data Structure in JavaScript