Tusker/MyPlayground.playground/Contents.swift

59 lines
1.2 KiB
Swift

import UIKit
class Client {
func test<A>(_ thing: A) {
if var thing = thing as? ClientModel {
thing.client = self
} else if var arr = thing as? [ClientModel] {
arr.client = self
}
// } else if let arr = thing as? Array<Any> {
// for el in arr {
// if var el = el as? ClientModel {
// el.client = self
// }
// }
// }
}
}
protocol ClientModel {
var client: Client! { get set }
}
class Something: ClientModel {
var client: Client!
}
extension Array: ClientModel where Element: ClientModel {
var client: Client! {
get {
return first?.client
}
set {
for var el in self {
el.client = newValue
}
}
}
}
//extension Array: ClientModel where Element == ClientModel {
// var client: Client! {
// get {
// return first?.client
// }
// set {
// for var el in self {
// el.client = newValue
// }
// }
// }
//}
var array = [Something(), Something()]
let client = Client()
client.test(array)
array[0].client
array[1].client