Swift
-
현재 시각 구하기 (Date, String)Swift/Tips & Tricks 2022. 9. 7. 11:52
현재 시각 구하기. 1. Date Type func localDate() -> Date { let nowUTC = Date() let timeZoneOffset = Double(TimeZone.current.secondsFromGMT(for: nowUTC)) guard let localDate = Calendar.current.date(byAdding: .second, value: Int(timeZoneOffset), to: nowUTC) else {return Date()} return localDate } 2. String Type func getCurrentDateStr(dateFormat: String = "yyyy-MM-dd HH:mm:ss") -> String { let date = Date(..
-
iOS - Local Identifier, TimeZone Identifier ListSwift/Tips & Tricks 2022. 8. 1. 15:08
가끔.. 앱에서 설정한 Timezone 과 유저의 Timezone 설정이 달라 스케쥴 관련 기능에서 작동이 안될 때가 있다. 그럴 때는 날짜 / 시간 과 언어 / 지역, 그리고 코드 내 Local identifier, Timezone identifier 를 바꿔가면서 원인을 찾아보자~ Local Identifier List mrMarathi bsBosnian ee_TGEwe (Togo) msMalay kam_KEKamba (Kenya) mtMaltese haHausa es_HNSpanish (Honduras) ml_INMalayalam (India) ro_MDRomanian (Moldova) kab_DZKabyle (Algeria) heHebrew es_COSpanish (Colombia) myBurme..
-
RxSwift - API CallSwift/RxSwift 2022. 7. 26. 15:31
func fetchEvents(repo: String) { let response = Observable.from([repo]) .map { urlString -> URL in return URL(string: "https://api.github.com/repos/\(urlString)/events")! } .map { url -> URLRequest in return URLRequest(url: url) } .flatMap { request -> Observable in return URLSession.shared.rx.response(request: request) // this method returns 'Observable' // completes whevever your app receive t..
-
RxSwift Merge 이용해서 Event 묶기Swift/RxSwift 2022. 7. 20. 11:21
Observable.merge(self.node.passwordText.rx.controlEvent(.editingDidEndOnExit).asObservable(), self.node.loginButton.rx.tap.asObservable()) .map { Reactor.Action.login } .bind(to: reactor.action) .disposed(by: self.disposeBag) Observable.merge() 는 parameter 로 Observable 을 받음. .rx.controlEvent() 는 ControlEvent 를 return 하므로, ControlEvent -> Observable 로 바꾸어줘야함. ( .asObservable )
-
UIView, Border on specific Sides (Extensions)Swift/Tips & Tricks 2022. 6. 3. 12:06
import UIKit extension UIView { enum ViewSide { case top case left case bottom case right } func addBorders(to sides: [ViewSide], in color: UIColor, width: CGFloat) { sides.forEach { addBorder(to: $0, in: color, width: width) } } func addBorder(to side: ViewSide, in color: UIColor, width: CGFloat) { switch side { case .top: addTopBorder(in: color, width: width) case .left: addLeftBorder(in: colo..
-
LottieSwift/Tips & Tricks 2022. 5. 27. 11:24
iOS Lottie 다루는 법 1. Cocoapods 에 추가한다. 2. lottiefiles.com 에 가서 원하는 Animation 을 다운 받는다. 3. XCode Project 로 가져온다. 4. import Lottie 5. 코드 import UIKit import Lottie class ViewController: UIViewController { let animationView = AnimationView() override func viewDidLoad() { super.viewDidLoad() setupAnimation() } private func setupAnimation() { animationView.animation = Animation.named("paperplane") ani..
-
Sorting Using Multiple Criteria ( Swift )Swift/Tips & Tricks 2022. 5. 17. 12:16
self.trialCores = screen.trialCores.sorted { if $0.tag != $1.tag { return $0.tag < $1.tag } else { return $0.direction.count < $1.direction.count } } let sortedContacts = contacts.sort { if $0.lastName != $1.lastName { // first, compare by last names return $0.lastName < $1.lastName } /* last names are the same, break ties by foo else if $0.foo != $1.foo { return $0.foo < $1.foo } ... repeat for..
-
Code Snippet (Xcode)Swift/Tips & Tricks 2022. 5. 13. 10:37
Snippet 을 이용하면 반복되는 코드를 빠르게 작성할 수 있다. 단축키는 Shift + Command + L 여기에 Completion 을 보면 'closure' 라고 쓰여있는데, 이는 XCode 에서 'closure' 을 입력 시 바로 코드를 완성 할 수 있다는 의미인 듯 하다. 선택하면 아래와 같이 바로 코드를 빠르고 쉽게 완성 시키는 데 많은 도움이 된다. Code Snippet 생성 1. Code Snippet 을 생성하기 원하는 영역을 드래그 후 우클릭 -> Create Code Snippet 선택 2. 해당 화면이 노출되고, 여기에서 편집이 가능하다. 3. Xcode 에서 일반적으로 제공하는 Code Snippet 은 Place Holder 가 제공되고, place holder 는 을 사용..