import UIKit
protocol Test {
var one: Int { get set }
var two: Int { get set }
}
struct Test1 : Test {
var one: Int
var two: Int
}
struct Test2 : Test {
var one: Int
var two: Int
}
let testArr1 = [Test1(one: 1, two: 2), Test1(one: 3, two: 4)]
let testArr2 = [Test2(one: 1, two: 2), Test2(one: 3, two: 4)]
func testGeneric<T>(_ dataArray: [T]) {
if let list = dataArray as? [Test] {
print("\(list[0].one)")
}
}
testGeneric(testArr1)
testGeneric(testArr2)
Last active
September 3, 2021 07:18
-
-
Save TuenTuenna/86af9eba50ee0a05922091b5725c5f3c to your computer and use it in GitHub Desktop.
protocol
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment