iOS
[Swift] Conditional & Loop
swift.org를 참고하여 정리한 글입니다. Swift.org Swift is a general-purpose programming language built using a modern approach to safety, performance, and software design patterns. www.swift.org 조건과 반복문에 대해서 알아보자. if & else let int3 = 3 if 5 > int3 { print("OK") } // if와 else if 5 > int3 { print("OK") } else { print("NO") } // else-if로 조건을 쓸 수 있다. if 2 > int3 { print("if 2") } else if 5 > int3{ print("else i..
[Swift] Collection Type
swift.org를 참고하여 정리한 글입니다. Swift.org Swift is a general-purpose programming language built using a modern approach to safety, performance, and software design patterns. www.swift.org Swift의 Collection Type에는 대표적으로 Array, Dictionary, Set이 있다. Array var intStringArray: Array = ["1", "3", "4"] var engStringArray: [String] = ["a", "b", "c"] var korStringArray = ["ㄱ", "ㄴ", "ㄷ"] // 타입 추론! //var errorAr..
![[Swift] 기본 데이터 타입](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FqqYPP%2FbtrDZIGqM0V%2FZNXX3C1oHR96LTbPYbqpq1%2Fimg.png)
[Swift] 기본 데이터 타입
swift.org를 참고하여 정리한 글입니다. Swift.org Swift is a general-purpose programming language built using a modern approach to safety, performance, and software design patterns. www.swift.org Int Int: 정수 데이터(음수, 0, 양수) Int32: 32비트 크기의 Int Int64: 64비트 크기의 Int 크기에 따라 저장할 수 있는 수의 범위가 달라진다. 우리가 평소에 사용하는 Int는 64비트 크기라는 것을 알 수 있다. 특별한 경우가 아니라면, 보통은 신경쓰지 않고, 그냥 Int 타입을 사용한다. Bool True와 False 1 byte(= 8 bit)의 크기를..
[Swift] Protocol
swift.org 의 내용을 기반으로 작성된 글입니다. 프로토콜에는 요구사항 준수(Conform)와 채택(Adopt) 개념이 있다. 프로퍼티 요구사항 (Property Requirements), 메서드 요구사항 (Method Requirements) 프로토콜 내에는 프로퍼티와 메서드에 대한 요구사항을 정의한다. protocol SomeProtocol { var printLine: String { get set } var getRequirement: Int { get } func someTypeMethod() -> Double } 아래의 Person은 SomeProtocol을 채택했기 때문에, 두 변수와 하나의 메소드에 대한 요구사항을 준수해야한다. struct Person: SomeProtocol { v..
![[Swift] Method Swizzling](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FdRKply%2FbtrBRnL3rK2%2F8UcAw2ilC5heRWxdv6z0jk%2Fimg.gif)
[Swift] Method Swizzling
Swift에서 같은 이름의 Method를 호출하면서 상황에 따라 기능을 다르게 할 수 있다. 이를 Method Swizzling이라고 하는데, 간단히 알아보자. 예를들어, calFunction을 호출하는데 어쩔 때는 + 기능을 수행하고, 어쩔 때는 - 기능을 수행하는 셈이다. 같은 함수를 호출하지만 다른 기능을 하는데, 전환을 런타임 중에 할 수 있다는 것이 특징이다. 이걸 왜 써야하는지 본다면, 이미 정의된 Swift 또는 iOS 함수를 다른 기능으로 호출하고 싶을 때 사용한다. 대중적이고 쉬운 예시로 UIKit의 ViewContoller Life Cycle이 있다. 내가 만든 모든 ViewController의 viewDidAppear, viewWillAppear 등의 기능을 한번에 변경할 수 있다. ..