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 AsynchronousTesting: XCTestCase { | |
var clientManager: APIManager! | |
func setUp() { | |
clientManager = APIManager() | |
} | |
func testLongOperationWrongly() { | |
var users: [Users] = [] | |
clientManager.getListOfUsers { incomingUsers, error in |
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 AsynchronousTesting: XCTestCase { | |
var clientManager: APIManager! | |
func setUp() { | |
clientManager = APIManager() | |
} | |
func testLongOperationCorrectly() { | |
var users: [Users] = [] | |
let fetchExpectation = expectationWithDescription("Fetching list of users") |
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
var array = [1, 2, 3, 4]; | |
//Imperative method | |
var newArray = []; | |
for (var i = 0; i < array.length; i++) { | |
var temp = array[i]; | |
temp = temp + 1; | |
newArray.push(temp); | |
} | |
console.log(newArray); //[2, 3, 4, 5] |
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
function buttonClicked() { | |
var buttonClickedStream = Rx.Observable.just(null); | |
buttonClickedStream | |
.takeUntil(viewDismountedObservable) | |
.flatMap(getDataFromStorage) | |
.filter(checkIfdataMoreThanADayOld) | |
.flatMap(getNewData) | |
.map(performComplexOperations) | |
.subscribe((combinedData) => { |
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
function buttonClicked() { | |
var buttonClickedStream = Rx.Observable.just(null); | |
buttonClickedStream | |
.flatMap(getDataFromStorage) | |
.filter(checkIfdataMoreThanADayOld) | |
.flatMap(getNewData) | |
.map(performComplexOperations) | |
.subscribe((combinedData) => { | |
console.log(combinedData); |
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
var vet = { | |
dog: "Max", | |
returnMax: function() { | |
return this.dog; | |
} | |
} | |
vet.returnMax(); // "Max" | |
var newReturnMax = vet.returnMax; | |
newReturnMax(); // returns the dog property of the global object, otherwise returns undefined. |
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
var footballer = { | |
name: "Leo Messi" | |
}; | |
var basketballer = { | |
name: "Steph Curry" | |
}; | |
var fighter = { | |
name: "Conor McGregor" |
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
_ = Observable.just("hello") | |
.map { | |
return $0.characters.count //On main thread | |
} | |
.map { | |
return $0 + 5 // On main thread | |
} | |
.map { | |
return $0 + 10 // On main thread | |
} |
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
//Main thread at point of observable creation | |
_ = Observable.just("hello") | |
.map { | |
return $0.characters.count //On main thread | |
} | |
.map { | |
return $0 + 5 //On main thread | |
} | |
.observeOn(ConcurrentDispatchQueueScheduler(globalConcurrentQueueQOS: .UserInteractive)) // User Interactive dispatch queue passed to observe on operator | |
.map { |
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 timer = Observable<Int>.interval(1, scheduler: MainScheduler.instance) | |
timer.subscribeNext { | |
print("First Subscription: \($0)") | |
} | |
delay(2) { | |
timer.subscribeNext { | |
print("Second Subscription: \($0)") | |
} |
OlderNewer