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 downloadImage() { | |
guard let team = team, let logoURL = team.logoURL() else { | |
return | |
} | |
sd_setImage(with: logoURL) | |
} |
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
extension Tournament: Equatable { | |
static func ==(lhs: Tournament, rhs: Tournament) -> Bool { | |
return lhs.ID == rhs.ID | |
} | |
} |
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
- (BOOL)isEqual:(id)object | |
{ | |
if (self == object) { | |
return YES; | |
} | |
if (![object isKindOfClass:TRTournament.class]) { | |
return NO; | |
} |
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
let viewModel = VersionViewModel(provider: | |
MoyaProvider<Service>(stubClosure: MoyaProvider.immediatelyStub)) |
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 definition. You're right, only ONE LINE of code! | |
class VersionViewModel: BaseViewModel<Version> {} | |
// Using it | |
let viewModel = VersionViewModel(provider: MoyaProvider<Service>()) | |
viewModel.fetchData(service: .version(version: AppInfo.version())).startWithResult { result in | |
switch result { | |
case let .success(version): | |
// Handle version success response | |
case let .failure(error): |
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
import Moya | |
import ReactiveSwift | |
class BaseViewModel<Element: Codable> { | |
var value: Element? { | |
didSet { | |
valueDidSet() | |
} | |
} | |
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 TournamentTableViewCell: BaseTableViewCell<Tournament> { | |
override init(style: UITableViewCellStyle, reuseIdentifier: String?) { | |
super.init(style: style, reuseIdentifier: reuseIdentifier) | |
selectionStyle = .none | |
textLabel?.font = R.font.proximaNovaLight(size: FontSize.Medium) | |
textLabel?.textColor = UIColor.flatBlack | |
} | |
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
// On your UITableView setUp | |
tableView.register(TournamentTableViewCell.self, | |
forCellReuseIdentifier: TournamentTableViewCell.cellReuseIdentifier()) | |
// On your UITableViewDataSource implementation | |
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
let cell = tableView.dequeueReusableCell(withIdentifier: TournamentTableViewCell.cellReuseIdentifier(), | |
for: indexPath) as! TournamentTableViewCell | |
guard let tournament = tournamentAtIndexPath(indexPath: indexPath) else { |
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 BaseTableViewCell<Element: Codable>: UITableViewCell { | |
public var model: Element? { | |
didSet { | |
setupCell() | |
} | |
} | |
public func setupCell() {} | |
public class func nib() -> UINib { |
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
let moyaProvider = MoyaProvider<Service>() | |
moyaProvider.request(.version(version: "2.2.0")) { result in | |
switch result { | |
case let .success(response): | |
var version: Version | |
do { | |
version = try response.map(Version.self) | |
print(version) | |
} catch { | |
print(error) |
NewerOlder