Swift

[Swift] Generic 을 사용해서 로그를 편하게 찍기

insub4067 2023. 5. 13. 14:20
import Foundation

struct SomeAPI {
    
    static func post() {
        Network.request(caller: self)
    }
}

struct OtherAPI {
    
    static func post() {
        Network.request(caller: self)
    }
}

struct Network {
    
    static func request<T>(caller: T.Type) {
        print(String(describing: caller))
    }
}

SomeAPI.post()
OtherAPI.post()

// 출력
SomeAPI
OtherAPI