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
extension SKAction { | |
static func write<Root: AnyObject, Value>( | |
value: Value, | |
to keyPath: ReferenceWritableKeyPath<Root, Value>, | |
on object: Root | |
) -> SKAction { | |
SKAction.customAction(withDuration: 0) { [weak object] _, _ in | |
object?[keyPath: keyPath] = value | |
} |
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
/* | |
The answers to each of these questions should be written as a function. | |
Call the function to execute your code. | |
Open this file in a text editor like "Sublime Text" or "Notepad++" | |
Write your answers in this file, saving often. |
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
/* | |
The answers to each of these questions should be written as a function. | |
Call the function to execute your code. | |
Open this file in a text editor like "Sublime Text" or "Notepad++" | |
Write your answers in this file, saving often. |
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 output = ""; | |
let character = "#"; | |
for (let count = 0; count < 7; count += 1) { | |
output += character; | |
console.log(output); | |
} |
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
import Foundation | |
enum MovieGenre: Int, Codable { | |
case action, horror, art, comedy, drama | |
} | |
let genre: MovieGenre = .action | |
let encoder = JSONEncoder() | |
// On the follow line, the code raises Swift.EncodingError.invalidValue | |
let jsonValue = try! encoder.encode(genre) |
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 TrainDepartureService { | |
func departureTimes(forLine: TrainLine, departingFrom: TrainStation) -> Observable<Date> { | |
return Observable<TimeInterval>.timer(0, period: 60, scheduler: scheduler) | |
.flatMapLatest { _ -> Observable<Date> in | |
network.departureTime(forLine: forLine, departingFrom: departingFrom) | |
} | |
} | |
private let scheduler: SchedulerType |
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
enum TrainLine { … } | |
enum TrainStation { … } | |
protocol TrainNetworkHandler { | |
func departureTime(forLine: TrainLine, departingFrom: TrainStation) -> Observable<Date> | |
} |
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
func simpleCombineStreams( | |
resource: Observable<Bool>, | |
buttonTap: Observable<Void> | |
) -> Observable<Bool> { | |
return buttonTap | |
.withLatestFrom(resource) | |
} |
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
struct FollowerNetworkingMock: FollowNetworkHandler { | |
let mockFollowers: [User] | |
let followResponse: Response | |
func follow(user: User) -> Observable<Response> { | |
return .just(followResponse) | |
} | |
func followers() -> Observable<[User]> { | |
return .just(mockFollowers) | |
} | |
} |
NewerOlder