Extensions Flashcards

1
Q

TF: You can add computed properties to extensions?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

TF: You can add stored properties or property observers?

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

TF: You can add new type and instance methods.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

TF: You can define nested types

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

TF: Can add convenience initializers

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

TF: We can add protocol conformance to both custom types, native types and types from external frameworks in an extension

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

TF:You cannot provide a default implementation for any requirements specified in a protocol

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

TF: We can only provide default implementations for protocols via an extension.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What’s the purpose of using an Extension?

A

Extensions add new functionality to an existing class, structure, enumeration, or protocol type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

TF: Extensions can add new functionality to a type, but they cannot override existing functionality.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
protocol SomeProtocol {
    func someMethod() -> Int
}
extension SomeProtocol {
    func someMethod() -> Int {
        return 1
    }
}
struct SomeStruct: SomeProtocol {
    func someMethod() -> Int {
        return 2
    }
}

let b: SomeProtocol = SomeStruct()
b.someMethod()

What is the value returned from the someMethod() call?

A

1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Why can we not add designated initializers in a class extension?

A
A designated initializer initializes all properties of a class and we don't have access to private properties in an extension
A designated initializer needs to call a specific superclass' initializer which is not possible from the extension.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
protocol SomeProtocol {
    func someMethod() -> Int
}
extension SomeProtocol {
    func someMethod() -> Int {
        return 1
    }
}
struct SomeStruct: SomeProtocol {
    func someMethod() -> Int {
        return 2
    }
}

let a: SomeStruct = SomeStruct()
a.someMethod()

What is the value returned from the someMethod() call

A

2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Which of following is not allowed in an extension? (Instance Methods, Stored Properties, Type Methods, Computed Properties)

A

Stored Properties

How well did you know this?
1
Not at all
2
3
4
5
Perfectly