You can use 1._____ to add functionality to an existing type, such as new 2.____ and 3.______ _______
You can use 1. ______ to add protocol conformance to a type that is declared 2. ______ or even a 3. _____ that you imported from a 4._____ or 5. ______
What do “extensions” do?
They add functionality to an existing class, structure, enumeration, or protocol type.
What is retroactive modeling?
The ability to extend types for which you do not have access to the original source code. Extensions include retroactive modeling.
Extensions are similar to _____ in Objective-C.
categories
Unlike Objective-C categories, Swift extensions do not have _____.
names
What are six things that extensions in Swift can do?
Extensions can add new functionality to a type, but they can not _____ ______ ______.
Override existing functionality
We can declare extensions with the ______ ______.
extension keyword
Syntax to declare extension with the extension keyword
extension SomeType {
// new functionality to add to SomeType goes here
}An extension can extend an existing type to make it adopt one or more _______.
protocols
How do you add protocol conformance when declaring an extension?
You write the protocol names the same way as you would write them for a class or structure.
Syntax for an extension that extends an existing type to make it adopt multiple protocols
extension SomeType: SomeProtocol, AnotherProtocol {
// implementation of protocol requirements goes here
}If you define an extension to add new functionality to an existing type, where will this new functionality be available?
It will be available on all existing instances of that type, even if they were created before the extension was defined.
An extension can be used to extend an existing generic type. You can also extend a generic type to _____ ______ ______.
Conditionally add functionality
Extensions can add computed 1. ______ properties and computed 2.______ properties to existing types.
Extensions can add new computed properties, but they can not add 1. _____ ______, or add 2. _____ _____ to existing properties.
2. property observers
Extensions can add new initializers to existing types. What does this enable you to do? (List 2 things)
Extensions can add new convenience initializers to a class, but they can’t add new 1. _____ ______ or 2. _____ to a class.
2. Deinitializers
Designated initializers and deinitializers must always be provided by the ____ _____ _____
original class implementation