This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func testJSONToUser() { | |
let userDictionary = mockUserAPI.getUserDictionary() | |
guard let user = UserMapper().map(userDictionary) else { | |
XCTFail("Failed to map User") | |
return | |
} | |
XCTAssert(user.id == 11235) | |
XCTAssert(user.name == "BobEsponja") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct User { | |
let id: Int | |
let name: String | |
} | |
class UserMapper { | |
func map(_ dictionary: [String: Any]) -> User? { | |
guard let id = dictionary["id"] as? Int else { return nil } | |
guard let name = dictionary["user_name"] as? String else { return nil } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct User: Codable { | |
let id: Int | |
let name: String | |
enum CodingKeys: String, CodingKey { | |
case id | |
case name = "user_name" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct User { | |
let id: Int | |
let name: String | |
init?(dictionary: [String: Any]) { | |
guard let id = dictionary["id"] as? Int else { return nil } | |
guard let name = dictionary["user_name"] as? String else { return nil } | |
self.id = id | |
self.name = name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol Helper { } | |
class BestHelper: Helper { /* I do the best helping in accordance to Helper */ } | |
class MockHelper: Helper { /* Fake it till you make it */ } | |
class MainClass { | |
let helper: Helper | |
init(helper: Helper) { | |
self.helper = helper |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Helper { /* I do helpful things */ } | |
class MainClass { | |
let helper: Helper | |
init(helper: Helper) { | |
self.helper = helper | |
} | |
} |
NewerOlder