Skip to content

Instantly share code, notes, and snippets.

View fadion's full-sized avatar

Fadion Dashi fadion

  • Tirana, Albania
View GitHub Profile
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()
})
}
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)
}
image.snp.makeConstraints { make in
make.width.height(100)
make.center.equalToSuperView()
}
let image = UIImageView()
view.addSubView(image)
image.snp.makeConstraints { make in
make.edges.equalToSuperView()
}
class SomeComponentView: UIView {
let title: UILabel = {
// label setup
}()
let addToCart = AddToCartView()
// setup
let addToCart = AddToCartView()
addToCart.price.text = "50"
class AddToCartView: UIView {
let price: UILabel = {
let label = UILabel()
label.backgroundColor = .white
label.textColor = .black
label.textAlignment = .center
return label
}()
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)
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
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