Skip to content

Instantly share code, notes, and snippets.

View muizidn's full-sized avatar
👨‍🚀
Working between Tiangong and Mir

Former Not Wannabe Lord Paramount of the Wkwkland muizidn

👨‍🚀
Working between Tiangong and Mir
  • Indian Ocean
View GitHub Profile
@muizidn
muizidn / Runner.swift
Created January 11, 2018 07:57
Observing Observable Array Elements Property At Once!
// 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()
@muizidn
muizidn / withLatestFromRxSwift.swift
Created February 5, 2018 06:09
Usage of withLatestFrom in RxSwift to tackle cyclic Observable sequence
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
@muizidn
muizidn / ErrorRxSwift.swift
Created February 19, 2018 02:36
RxSwift: Error handling without disposing subscription or Resubscribe after disposed
// 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)
<!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;
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
}
/// MuslimApp
// AppLaucherViewController.swift
import SubApplication
class AppLaucherViewController: UITableViewController {
private var items: [SubApplication] = []
convenience init(items: [SubApplication]) {
self.init()
public protocol SubApplication {
var name: String { get }
var thumbnail: UIImage? { get }
var starter: UIViewController { get }
}
// 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"
// MuslimApp Application.swift
import MuslimNote
let subApplication: [SubApplication] = [
MuslimNote.Application()
]
// MuslimApp AppLaucherViewController.swift
// DidSelectCellForRowAt indexPath: IndexPath
let subApp = items[indexPath.row]
let vc = subApp.starter
navigationController.pushViewController(vc, animated: true)