8. Reference counting
class SampleClass {
}
var array: [SampleClass] = ....
for p in array {
// increment reference counting
...
// decrement reference counting
}
struct SampleStruct {
}
var array: [SampleStruct] = ....
for p in array {
...
}
15. create struct, when…
• data structure is simple
• properties are value type(struct)
• purpose is not to update itself, when data is
passed to a method
16. ex: CGPoint
public struct CGPoint {
public var x: CGFloat
public var y: CGFloat
public init()
public init(x: CGFloat, y: CGFloat)
}
• data structure is simple
• properties are value type
• purpose is not to update itself, when data is
passed to a method
18. many properties
• That struct is value type means it’s copied when
assigned
• the more properties a struct has, the more
memory machine needs, when copied
28. Summary
• having few properties is better for struct
• “struct or class” depends on purpose
• ex: class can be used for Data object from API
• ex: struct can be used for Request data to API