| Struct | Class |
|---|---|
| Value type | Reference type |
| Copied when passed or assigned | Passed around via pointers |
| Copy on write | Automatically reference counted |
| Functional programming | Object-oriented programming |
| No inheritance | Inheritance (single) |
| “Free” init initializes ALL vars | “Free” init initializes NO vars |
| Mutability is explicit (var vs let) | Always mutable |
| Your “go to” data structure | Used in specific circumstances |
| Everything you’ve seen so far is a struct (except View which is a protocol) | The ViewModel in MVVM is always a class (also, UIKit (old style iOS) is class-based) |
Swift中Struct和Class的区别
最新推荐文章于 2024-11-26 19:13:08 发布
682

被折叠的 条评论
为什么被折叠?



