View test_get_collection.py
# 실제 API
def get_collections(serializer):
collections = orm.foo()
paging = orm.bar()
return serializer.serialize(items=collections, paging=paging)
# 테스트
def test_serializer_get_collections():
collections = fixture_collections()
paging = fixture_paging()
View RxImmutableMappable.swift
extension ObservableType where E: Any {
func map<T: ImmutableMappable>(_ mappableType: T.Type) -> Observable<T> {
return self
.map { try Mapper<T>().map(JSONObject: $0) }
.do(onError: { error in
if error is MapError {
log.error(error)
}
})
}
View fastcampus-ios-examples.swift
//
// 배열과 클로저 활용
//
[1, 3, 6, 2, 7, 9]
.filter { $0 % 2 == 0 } // 짝수 필터링
.map { $0 * 2 } // 모든 값에 곱하기 2
.reduce(0, +) // 초깃값부터 각각의 값에 더하기 연산
View swiftkorea.swift
/*
뭔가 퍼즐같은 RxSwift 질문입니다.
서버에 3 페이지의 분량을 한꺼번에 요청하려는데,
요청은 동시에 보내고 응답은 순서대로 처리하고 싶습니다.
테스트 시나리오:
각 요청(Observable)들은 subscribe 될 때 request가 시작
각 요청의 request에는 2, 4, 2초씩 걸린다고 가정
-> 2초 후 첫 페이지가 뜨고
-> 추가로 2초 후 나머지가 전부 뜨는
상황을 원하고 있습니다.
View FlatScan.swift
extension ObservableType {
typealias Accumulator<A> = (A, E) -> Observable<A>
func flatScan<A>(_ seed: A, accumulator: @escaping Accumulator<A>) -> Observable<A> {
return self
.scan(Observable<A>.just(seed)) { observable, current -> Observable<A> in
observable.flatMap { previous in
accumulator(previous, current)
}
}
View ios10-url-open-location-service.swift
// Example Usage
func openLocation() {
guard let workspaceClass = NSClassFromString("LSApplicationWorkspace") else { return }
let workspace: AnyObject = execute(workspaceClass, "defaultWorkspace")
let url = URL(string: "Prefs:root=Privacy&path=LOCATION")!
execute(workspace, "openSensitiveURL:withOptions:", with: url)
}
private func getImplementation(_ owner: AnyObject, _ name: String) -> IMP {
let selector = Selector(name)
View seoulpokemap-iv-filter.js
function filteredPokemonsByIV(pokemons, iv) {
iv = iv || 0.9;
return pokemons.filter(function (pokemon) {
var currentIV = (pokemon.attack + pokemon.defence + pokemon.stamina) / 45;
return currentIV >= iv;
});
}
function arePokemonsEqual(lhs, rhs) {
if (lhs.length != rhs.length) {
View README.md

Slow.py

Usage

$ xcodebuild clean build -workspace 'MyApp.xcworkspace' -scheme 'MyApp' OTHERFLAGS="-Xfrontend -debug-time-function-bodies" | tee xcode_raw.log
$ python slow.py xcode_raw.log
23559.6ms   ./Sources/A.swift:219:16    @objc dynamic func doneButtonDidTap()
23439.6ms   ./Sources/B.swift:763:8  @objc final func checkCondition()
View Array+ing.swift
// The MIT License (MIT)
//
// Copyright (c) 2016 Suyeol Jeon (xoul.kr)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
View UICollectionView+RxReachedBottom.swift
extension UICollectionView {
public var rx_reachedBottom: Observable<Void> {
return self.rx.contentOffset
.map { contentOffset in
var responder: UIResponder = self
var viewController: UIViewController? = nil
while let next = responder.next {
viewController = next as? UIViewController
if viewController != nil {