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
// This code shows you how to observing Observable<[E]> | |
// to Observable<[E.A]> | |
// Get your hand dirty! | |
class Player { | |
let stamina = Variable(0) | |
} | |
// ViewController | |
let disposeBag = DisposeBag() |
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 user: PublishSubject<User>() | |
let cart = user.startWith( ... ) // I provide a starter value for sequence | |
.flatMapLatest { user -> Observable<Cart> in | |
return Observable.just(user.cart) | |
} | |
.map { | |
... // Do some logic here | |
} | |
// Updating user for other observer |
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
// Setelah print "Fetch Error ..." maka subscription -> onCompleted -> isDisposed (dan tidak bisa fetchProduct lagi) | |
Network.fetchProduct() // Return Observable<[Product]> | |
.subscribe(onNext: { value in | |
print("Product is \(value)") | |
}, onError: { error in | |
print("Fetch Error \(error)") | |
}) | |
.diposed(by: bag) |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<style> | |
.main-button { | |
background-color: white; | |
color: black; | |
border: 2px solid #4CAF50; |
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 WhateverUseCase { | |
... | |
let store: Store // I don't need specify any type | |
func performOperation() { | |
/// Car | |
store.fetch(Car.self, with: [.color(.red), .year(Date())]) | |
.success { cars in | |
// Do logic | |
} |
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
/// MuslimApp | |
// AppLaucherViewController.swift | |
import SubApplication | |
class AppLaucherViewController: UITableViewController { | |
private var items: [SubApplication] = [] | |
convenience init(items: [SubApplication]) { | |
self.init() |
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
public protocol SubApplication { | |
var name: String { get } | |
var thumbnail: UIImage? { get } | |
var starter: UIViewController { get } | |
} |
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
// MuslimNote | |
// Application.swift | |
import SubApplication | |
public class Application: SubApplication { | |
let name = "Muslim Note" | |
let thumbnail = UIImage(named: "muslim_note_thumnail") | |
let starter: UIViewController | |
init() { | |
let vc = HomeController( | |
nibName: "HomeController" |
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
// MuslimApp Application.swift | |
import MuslimNote | |
let subApplication: [SubApplication] = [ | |
MuslimNote.Application() | |
] |
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
// MuslimApp AppLaucherViewController.swift | |
// DidSelectCellForRowAt indexPath: IndexPath | |
let subApp = items[indexPath.row] | |
let vc = subApp.starter | |
navigationController.pushViewController(vc, animated: true) |