This file contains 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
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
This file contains 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 name: String | |
let nickname: String | |
} | |
struct Pet { | |
let name: String | |
let owner: String | |
let breed: String | |
let weight: Int |
This file contains 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 set(with user: User) { | |
leftTitleLabel.text = user.name | |
leftSubtitleLabel.text = "Nick: " + user.nickname | |
hideImage() | |
} | |
func set(with pet: Pet) { | |
leftTitleLabel.text = pet.name | |
leftSubtitleLabel.text = "Owner: " + pet.owner | |
This file contains 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 ReusableTableViewCellDataProvider { | |
var leftTitle: String? { get } | |
var leftSubtitle: String? { get } | |
var rightTitle: String? { get } | |
var rightSubtitle: String? { get } | |
var image: UIImage? { get } | |
} |
This file contains 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 UserReusableCellDataProvider: ReusableTableViewCellDataProvider { | |
let user: User | |
var leftTitle: String? { | |
return user.name | |
} | |
var leftSubtitle: String? { | |
return "Nick: " + user.nickname | |
} |
This file contains 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 set(with dataProvider: ReusableTableViewCellDataProvider) { | |
leftTitleLabel.text = dataProvider.leftTitle | |
leftSubtitleLabel.text = dataProvider.leftSubtitle | |
rightTitleLabel.text = dataProvider.rightTitle | |
rightSubtitleLabel.text = dataProvider.rightSubtitle | |
set(image: dataProvider.image) | |
} |
This file contains 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
private func set(image: UIImage?) { | |
guard let image = image else { | |
hideImage() | |
return | |
} | |
showImage() | |
iconImageView.image = image | |
} |
This file contains 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 tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
guard let cell = tableView.dequeueReusableCell(withIdentifier: "ReusableTableViewCell") as? ReusableTableViewCell, indexPath.row < users.count else { | |
return UITableViewCell() | |
} | |
let user = users[indexPath.row] | |
let dataProvider = UserReusableCellDataProvider(user: user) | |
cell.set(with: dataProvider) | |
return cell | |
} |
This file contains 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 PetReusableCellDataProvider: ReusableTableViewCellDataProvider { | |
let pet: Pet | |
var leftTitle: String? { | |
return pet.name | |
} | |
var leftSubtitle: String? { | |
return "Owner: " + pet.owner | |
} |
This file contains 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 HttpRequestProtocol { | |
init(method: HttpMethod, url: String, headers: [String: String], parameters: [String: Any], encoding: Encoding) | |
func run(completion: @escaping ((HttpResponse) -> Void)) | |
} |
OlderNewer