Memory Management & Access Control Flashcards
TF: All memory management only applies to reference types
True, cannot use for value types like structs.
Deinit is used for what?
to break the class down or deallocate the class
IB outlets are what kind of reference by default?
Weak
We have the protocol below and we want the customer class to inherit it. Why do we have to put the class in the protocol? protocol Loan: class { var payee: Customer { get set } }
class Customer { weak var loan: Loan? }
we have to put class in Loan protocol because we have to use reference types when working with weak references
TF: Swift makes use of Manual Retain Release.
False
Assume you created a custom class with a stored property. By default, references to that property will be:
Strong
TF: Strong retain cycles used to be very common before ARC, nowadays, it is nearly impossible to accidentally create one in Swift.
False
When we talk about allocating memory on a mobile device, we are talking about:
RAM
In Swift, if you find that you have created a strong reference cycle, how should you fix it?
Change one of the strong references to weak, using the weak keyword.
What are the five levels we can restrict our code to?
Open Public Internal Fileprivate Private
The member of the class are what by default? private class SomeClass {}
All members of this class are private
What access level is enabled by default?
Internal
TF: Internal access enables entities to be used within any source file from their defining module and in any source file outside of the module.
False
TF: A Swift source file exists within a module
True
How do we know what level a member of a class can be depending on the class itself?
A member can be anything lower than the type of the class itself.
So if a class is private, all members have to be private.
If a class is internal, all members can be fileprivate or private.