ObjectMapper에서 Decodable로 다시 쓰기
조심하다
변환
Before
import ObjectMapper
struct Item: Mappable {
    var id: Int = 0
    var name = ""
    init?(map: Map) { }
    mutating func mapping(map: Map) {
        id <- map["id"]
        name <- map["name"]
        ...
    }
}
After
import Decodable
struct Item {
    let id: Int
    let name: String
}
extension Item: Decodable {
    static func decode(_ json: Any) throws -> Item {
        return try Item(
            id: json => "id",
            name: json => "name"
        )
    }
}
 중첩 된 클래스 (struct)를 대체 할 때 이런 느낌이됩니다.
부모 클래스 (struct)
import ObjectMapper
struct User: Mappable {
    var id: Int = 0
    var name = ""
    var item: Item?
    ...
    init?(map: Map) { }
    mutating func mapping(map: Map) {
        id <- map["id"]
        name <- map["name"]
        ...
        do {
            item = try Item.decode(map["item"].JSON)
        } catch {
            // なんか例外処理
        }
    }
}
아이 class (struct)
import Decodable
struct Item {
    let id: Int
    let name: String
}
extension Item: Decodable {
    static func decode(_ json: Any) throws -> Item {
        return try Item(
            id: json => "item" => "id",
            name: json => "item" => "name"
        )
    }
}
이런 식으로 치마치마 대체해, 모든 아이 class (struct) 가 Decodable 가 되면 부모마다 단번에 Decodable 로 최적화해 갑니다.
 매일 조금씩 리팩토링해 갑니다.
🐣 
                
                    
        
    
    
    
    
    
                
                
                
                
                    
                        
                            
                            
                            Reference
                            
                            이 문제에 관하여(ObjectMapper에서 Decodable로 다시 쓰기), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
                                
                                https://qiita.com/keisei_1092/items/afcf34a5ec663913c1ec
                            
                            
                            
                                텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                            
                            
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                            
                            
                        
                    
                
                
                
            
import ObjectMapper
struct Item: Mappable {
    var id: Int = 0
    var name = ""
    init?(map: Map) { }
    mutating func mapping(map: Map) {
        id <- map["id"]
        name <- map["name"]
        ...
    }
}
import Decodable
struct Item {
    let id: Int
    let name: String
}
extension Item: Decodable {
    static func decode(_ json: Any) throws -> Item {
        return try Item(
            id: json => "id",
            name: json => "name"
        )
    }
}
부모 클래스 (struct)
import ObjectMapper
struct User: Mappable {
    var id: Int = 0
    var name = ""
    var item: Item?
    ...
    init?(map: Map) { }
    mutating func mapping(map: Map) {
        id <- map["id"]
        name <- map["name"]
        ...
        do {
            item = try Item.decode(map["item"].JSON)
        } catch {
            // なんか例外処理
        }
    }
}
아이 class (struct)
import Decodable
struct Item {
    let id: Int
    let name: String
}
extension Item: Decodable {
    static func decode(_ json: Any) throws -> Item {
        return try Item(
            id: json => "item" => "id",
            name: json => "item" => "name"
        )
    }
}
이런 식으로 치마치마 대체해, 모든 아이 class (struct) 가 Decodable 가 되면 부모마다 단번에 Decodable 로 최적화해 갑니다.
매일 조금씩 리팩토링해 갑니다.
🐣 
                
                    
        
    
    
    
    
    
                
                
                
                
                    
                        
                            
                            
                            Reference
                            
                            이 문제에 관하여(ObjectMapper에서 Decodable로 다시 쓰기), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
                                
                                https://qiita.com/keisei_1092/items/afcf34a5ec663913c1ec
                            
                            
                            
                                텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                            
                            
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                            
                            
                        
                    
                
                
                
            
Reference
이 문제에 관하여(ObjectMapper에서 Decodable로 다시 쓰기), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/keisei_1092/items/afcf34a5ec663913c1ec텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)