Why Choose Struct Over Class?

前端 未结 16 2272

Playing around with Swift, coming from a Java background, why would you want to choose a Struct instead of a Class? Seems like they are the same thing, with a Struct offeri

16条回答
  •  醉梦人生
    2020-11-22 06:26

    Many Cocoa APIs require NSObject subclasses, which forces you into using class. But other than that, you can use the following cases from Apple’s Swift blog to decide whether to use a struct / enum value type or a class reference type.

    https://developer.apple.com/swift/blog/?id=10

提交回复
热议问题