제네릭
-
[Swift] 제네릭 (Generics)iOS/Swift 2022. 12. 2. 11:47
import UIKit struct MyArray{ //보통 SomeElement 자리에 T를 넣음 "Type" // 제네릭을 담은 빈 배열 var elements : [SomeElement] = [SomeElement]() //생성자 init(_ elements: [SomeElement]){ self.elements = elements } } struct Friend { var name: String } struct Coder { var name: String } var mySomeArray = MyArray([1,2,3]) print("mySomeArray : \(mySomeArray)") var myStringArray = MyArray(["가","나","다"]) print("myStringArra..