Swift
Value semantics
What does this code print?
struct Point { var x = 0 }
final class Box { var x = 0 }
var p1 = Point(); var p2 = p1; p2.x = 5
let b1 = Box(); let b2 = b1; b2.x = 5
print(p1.x, b1.x)Pick one
Value semantics
What does this code print?
struct Point { var x = 0 }
final class Box { var x = 0 }
var p1 = Point(); var p2 = p1; p2.x = 5
let b1 = Box(); let b2 = b1; b2.x = 5
print(p1.x, b1.x)Pick one
Memory and ARCShort answerAdvanced
A webtoon app's Episode struct has an ImageCache property of class type. If you copy the …
#struct #class #value-semantics
SwiftShort answerBasics
In Swift, what's the fundamental difference between a struct and a class?
#struct #class
SwiftShort answerBasics
Which line in this code fails to compile, and why? …
#struct #value-semantics
SwiftShort answerBasics
When you build model types to serialize and deserialize a server's JSON response, should …
#struct #class