55. let task = KingfisherManager.shared.retrieveImage(
with: source,
options: options,
completionHandler: { result in
CallbackQueue.mainCurrentOrAsync.execute {
completionHandler?(result)
}
}
)
56. 4. Avoid Singletons for objects
that are not single properties
of the environment
57. 4. Avoid Singletons for objects
that are not single properties
of the environment unless it
improves the API and
integration of your framework
for third party apps
66. struct SwiftConf {
var text: String
}
var a = SwiftConf(text: "StructText")
var b = a
b.text = "ModifiedStructText"
print(a.text)
print(b.text)
67. class TextContainer {
var text: String
init(text: String) {
self.text = text
}
}
struct SwiftConf {
var textContainer: TextContainer
}
var a = SwiftConf(textContainer:
TextContainer(text: "ClassText"))
var b = a
b.textContainer.text = "ModifiedClassText"
print(a.textContainer.text)
print(b.textContainer.text)
74. class UserStorage {
var name: String?
init() {}
}
struct User {
public var storage: UserStorage
init() {
self.storage = UserStorage()
}
public var name: String? {
get {
return storage.name
}
set {
if isKnownUniquelyReferenced(&storage) {
storage.name = newValue
}
else {
storage = UserStorage()
storage.name = newValue
}
}
}
}
75. 5. Prefer structs over classes
when the thing it represents
and its properties have value
semantics
76. 5. Prefer structs over classes
when the thing it represents
and its properties have value
semantics unless it’s a complex
nested struct, which should be
backed by a class