View index.html
<!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;
View ErrorRxSwift.swift
// 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)
View withLatestFromRxSwift.swift
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
View Runner.swift
// 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()
View CreatingPythonVirtualEnvirontment.sh
# Make folder <folder>.python
mkdir SomeFolder.python; cd SomeFolder.python
# Make VirtualEnv
virtualenv -p $(which python3) .venv
# Activate
source .venv/bin/activate
View PropertyStoring.swift
protocol PropertyStoring {
func getAssociatedObject<T>(_ key: UnsafeRawPointer, defaultValue: T) -> T
}
extension PropertyStoring {
func getAssociatedObject<T>(_ key: UnsafeRawPointer, defaultValue: T) -> T {
guard let value = objc_getAssociatedObject(self, key) as? T else {
return defaultValue
}
return value
}
View CaptainAmerica+IronMan(ViewController).swift
protocol PertarunganCivilWar {
func diSerang()
}
class CaptainAmericaViewController: UIViewController, PertarunganCivilWar {
diSerang()
}
class IronManViewController: UIViewController, PertarunganCivilWar {
diSerang()
View SearchController+FilteredResult.swift
// UIViewController class conforms UISearchResultUpdating
// MARK: Search Controller
func configureSearchController() {
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
definesPresentationContext = true
tableView.tableHeaderView = searchController.searchBar
}
View ExportErrorToFile.js
// SWIFT 4.0.1
// XCODE 9.0.1
#if DEBUG
var errorFile = "errorLog.txt"
// Error object must be conform to CustomStringConvertible protocol
func saveErrorLog<T: CustomStringConvertible>(error: T) {
// Fetch document directory URL
let documentDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
let path = documentDirectory.appendingPathComponent(errorFile).path
View ABCViewControllerMock.swift
// Di kode produksi ABCApp
class ABCViewController: UIViewController {
func foo() -> String {
return "Jalankan kode PRODUKSI untuk ABCViewController"
}
}
// Di ViewControllerTests