FlashKeepers

Swift · College · College and University

Swift II: Structs, Classes and Protocols

Value versus reference types, properties, initializers, protocols, extensions, enums with associated values and generics.

About this set

42 basic cards for College Swift. Set 2 of 4 in Swift. It opens with "What is a struct in Swift?" and "What is a class in Swift?". Study it alongside the other College sets below.

42 cards · basic cards · AI-written, checked twice. Edit anything.

Study this set free Look inside first Get FlashKeepers for iPhone

Opens in your browser, no account. Get the iPhone and iPad app · Android app

What is a struct in Swift?
Show answerA value type that groups related data and behavior together.
What is a class in Swift?
Show answerA reference type that defines a blueprint for creating objects with properties and methods.
Are structs value types or reference types?
Show answerValue types. Each copy has its own independent data.
Are classes value types or reference types?
Show answerReference types. Multiple references point to the same object in memory.
What happens when you assign a struct to another variable?
Show answerA copy is made. Changes to one do not affect the other.
What happens when you assign a class instance to another variable?
Show answerThe new variable references the same object. Both point to the same data.
Where are struct instances stored in memory?
Show answerOn the stack.
Where are class instances stored in memory?
Show answerOn the heap. The stack stores a reference to the object.
When should you use a struct instead of a class?
Show answerWhen you need a value type with no inheritance, simple data storage, or copy semantics.
When should you use a class instead of a struct?
Show answerWhen you need reference semantics, inheritance, or shared state across references.
What is a stored property?
Show answerA property that stores a value as part of the instance, like a variable.
What is a computed property?
Show answerA property that calculates its value each time it is accessed, defined with get or get/set.
What does the willSet property observer do?
Show answerIt is called just before a stored property's value is set.
What does the didSet property observer do?
Show answerIt is called immediately after a stored property's value is set.
What is a lazy stored property?
Show answerA property whose initial value is not computed until the first time it is accessed.

27 more cards in the app

Study this set free