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 fillWithData() { | |
PizzaManager().all() | |
.subscribe(onNext: { [weak self] pizza in | |
self?.pizzaViewModel.value = pizza | |
}, onError: { [weak self] _ in | |
if self?.pizzaViewModel.value.count == 0 { | |
self?.pizzaCollectionView.backgroundView = NetworkErrorView(withAction: { | |
self?.fillWithData() | |
}) | |
} |
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 animateParallax(position: CGFloat) { | |
self.photo.transform = CGAffineTransform(rotationAngle: position / self.frame.width * 0.5) | |
self.addToCart.transform = CGAffineTransform(translationX: position * 0.2, y: 0) | |
self.name.transform = CGAffineTransform(translationX: position * 0.5, y: 0) | |
self.summary.transform = CGAffineTransform(translationX: position * 0.7, y: 0) | |
} |
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
image.snp.makeConstraints { make in | |
make.width.height(100) | |
make.center.equalToSuperView() | |
} |
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
let image = UIImageView() | |
view.addSubView(image) | |
image.snp.makeConstraints { make in | |
make.edges.equalToSuperView() | |
} |
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
class SomeComponentView: UIView { | |
let title: UILabel = { | |
// label setup | |
}() | |
let addToCart = AddToCartView() | |
// setup | |
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
let addToCart = AddToCartView() | |
addToCart.price.text = "50" |
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
class AddToCartView: UIView { | |
let price: UILabel = { | |
let label = UILabel() | |
label.backgroundColor = .white | |
label.textColor = .black | |
label.textAlignment = .center | |
return label | |
}() | |
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
let realm = try! Realm() | |
let json = JSON(self.data)["pizza"].array | |
let viewModels = json.map { item -> PizzaViewModel in | |
let model = Pizza() | |
model.id = item["id"].intValue | |
model.name = item["name"].stringValue | |
model.price = item["price"].intValue | |
try! realm.write { | |
realm.add(model, update: true) |
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
class PizzaViewModel { | |
private let model: Pizza | |
private let disposeBag = DisposeBag() | |
var id: Int | |
var name: Variable<String> | |
var price: Variable<Int> | |
init(model: Pizza) { | |
self.model = model |
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
class PizzaViewModel { | |
private let model: Pizza | |
let id: Int | |
let name: String | |
let price: Int | |
init(model: Pizza) { | |
self.model = model | |
self.id = model.id |
NewerOlder