Avatar
Kishikawa Katsumi 3/24/2020 7:06 AM
^ これは当然Bが呼ばれるのだけど、
7:07 AM
AとBのメソッドにデフォルト引数を足すと(デフォルト引数なのでCall siteの変更はナシ)
7:07 AM
@swiftbot import Foundation struct DocumentSymbol: Encodable {} class Service { func perform() { sendDocumentSymbolRequest(context: [:], resource: "", slug: "", path: "") { (_, _) in } } private func sendDocumentSymbolRequest(context: [String : String], resource: String, slug: String, path: String, reply: @escaping (Bool, [String : Any]) -> Void) { let documentSymbols = [DocumentSymbol()] reply(true, ["result": "success", "value": encodeResponse(documentSymbols)]) } private func encodeResponse(_ documentSymbol: DocumentSymbol, _ indent: Int = 0) -> [String: Any] { print("A") return [:] } private func encodeResponse(_ documentSymbols: [DocumentSymbol], _ indent: Int = 0) -> [String: Any] { print("B") return [:] } private func encodeResponse<T: Encodable>(_ response: T) -> Any { print("C") let data = try! JSONEncoder().encode(response) return try! JSONSerialization.jsonObject(with: data, options: []) } } let service = Service() service.perform()