미완성
-
FlatMap, CompactMapSwift/Tips & Tricks 2022. 4. 8. 16:02
Swift 를 쓰다보면 (다른 언어들도 마찬가지겠지만) Array 를 다룰 때 flatMap, compactMap 에 대해 다루게 된다. 먼저 정의부터 살펴보자. compactMap Summary Sequence 의 각 element 에 주어진 transform 을 시행했을 때 nil 이 아닌 결과들로 이루어진 array Discussion transformation 이 optional value 를 생성시킬 수 있을 때, optional 이 아닌 값들의 array 를 원할 때 사용하면 된다. 복잡도: O(m+n), n: sequence 의 크기, m: 결과의 크기 Example 예시에서 .map 은 optional 을 생성하고 nil 값을 생성할 수도 있지만, compactMap 을 사용할 경우 이때에..
-
Swift With REST API (using Alamofire, in progress )미완성 2022. 3. 18. 01:07
TODO Server: https://github.com/hanmok/TodoServer.git TODO SwiftCode : https://github.com/hanmok/TodoHabitREST let baseUrl = "http://localhost:5001" let targetUrl = "http://localhost:5001/todos" 먼저, Alamofire 의 도움을 받지 않고 REST API 호출하는 법 1. GET func getOneTodo(id: String, completion: @escaping (Result) -> Void ) { let url = "\(baseUrl)/\(id)" guard let URL = URL(string: url) else { return } var u..