I'm stuck about generics, and generic methods in swift.
Why this code that uses Swift generics method, gives EXC_BAD_ACCESS when invoking method1?
You can test it using Playground.
import UIKit
import Foundation
protocol SomeProtocol {
func printMe()
}
class SomeClass : SomeProtocol {
let value : String
init(value: String) {
self.value = value
}
func printMe() {
print("\(value)")
}
}
class BaseClass {
func method1<T>(_ param: T) {
print("passing into method 1 with param: \(param)")
method2(param)
}
func method2<T>(_ param: T) {
}
}
class ConcreteClass : BaseClass {
override func method2<T>(_ param: T) where T : SomeProtocol {
print("passing into method 2 with param: \(param.printMe())")
}
}
let someClass = SomeClass(value: "Hi")
let obj = ConcreteClass()
obj.method1(someClass)