일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
- 이니셜라이저
- Foundation
- struct
- init
- IOS
- Xcode
- Protocol
- instance
- tuist
- enum
- optional
- Git
- Unicode
- interpace
- initalizer
- Terminal
- property
- Class
- 스위프트
- UIKit
- String
- url
- Swift
- extension
- delegate
- 디자인패턴
- Method
- initializer
- 코딩테스트
- type
- Today
- Total
목록Swift (58)
아리의 iOS 탐구생활
Strings and Characters — The Swift Programming Language (Swift 5.5) Strings and Characters A string is a series of characters, such as "hello, world" or "albatross". Swift strings are represented by the String type. The contents of a String can be accessed in various ways, including as a collection of Character values. Swi docs.swift.org Strings and Characters — The Swift Programming Language (S..
커스텀 타입을 설계하는 과정에서 'Cannot use mutating member on immutable value: function call returns immutable value' 라는 에러가 나와서 당황했다. 클래스와 구조체를 공부하면서 값타입 참조타입이 무엇인지 이해했다고 생각했으나 이 에러를 만나자마자 엥... 이게 뭐지...??? 갑자기 멘붕이 찾아와서 황급히 구글링을 시작했다. 내가 코드를 짜다가 발생했던 에러는 다음 예제와 같다. class ClassType { let name: String var age: Int init(name: String, age: Int = 0) { self.name = name self.age = age } } struct StructType { var cl..
Apple Developer Documentation developer.apple.com NSString에서 write라는 메소드를 살펴보다가 용어가 궁금하여 찾아보았다. true면 임시 저장소에 백업파일을 먼저 기록하고, 기록이 모두 성공하면 최종 데이터를 지정한 파일에 저장하게 된다. 원본 파일의 손상을 막을 수 있고 시스템이 크래시를 내는 일을 방지한다. false를 준 뒤 fail이 나면 저장하고자 하는 파일이 충돌이 날 것이다. 빈 파일이라면 상관 없겠지만… 쉽게 얘기하면 true는 파일을 원자적으로 처리하고, false는 원자적으로 처리하지 않는다. 속도면에서는 false가 빠를 수 있겠지만 충돌이 일어날 가능성이 있다. 반면 true는 원자적으로 처리하기 때문에 일어날 충돌을 방지해준다. (..
Closures — The Swift Programming Language (Swift 5.5) Closures Closures are self-contained blocks of functionality that can be passed around and used in your code. Closures in Swift are similar to blocks in C and Objective-C and to lambdas in other programming languages. Closures can capture and store referen docs.swift.org 클로저(Closure)는 코드의 블록이다. 함수는 ‘이름이 있는 클로저’라고 표현한다. 보통 클로저는 ‘이름이 없는 코드블록’을 ..
먼저 나에 대한 소개를 하자면, 원래 평범하게 8년이라는 시간 동안 영업직을 잘 다니다가 왠지 '이 길은... 내 길이 아닌 것 같아'라고 느낀 그 순간부터 내 적성에 맞는 다른 업종은 없을까... 고민하다가 주변 사람의 추천으로 '개발자'라는 진로에 대해서 고민하게 되었다. 고민을 하다 보니 평소 어릴 적부터 내가 관심 있었던 건 컴퓨터 분야였고, 뭐 전문적으로 교육을 받거나 하진 않았지만 알게 모르게 자잘한 컴퓨터 관련 지식들을 알고 있었고, 또 그 분야에 대해서 탐구하는 것도 좋아했던 지라 업종을 바꾸자고 결심하게 되었고, 이후 6개월간 회사를 다니면서 남는 시간에 프로그래밍에 대해서 알아가는 기간을 가졌다. 6개월간 Java라는 언어도 접해보기도 하고 Flutter라는 프레임워크도 접해보면서 '앱..
🔍 try do-catch Error Handling — The Swift Programming Language (Swift 5.5) Error Handling Error handling is the process of responding to and recovering from error conditions in your program. Swift provides first-class support for throwing, catching, propagating, and manipulating recoverable errors at runtime. Some operations aren docs.swift.org 오류처리(Error Handling)는 프로그램이 오류를 일으켰을 때 감지하고 복구하는 프로..
Date 관련 타입들은 앱 개발을 할때 굉장히 많이 사용하게 되는 타입중 하나이다. 시간과 날짜를 다루는 타입들은 swift 기본 프레임워크인 Foundation에 포함되어 있다. 🔍 Date Apple Developer Documentation developer.apple.com Foundation의 Date 타입은 전 세계적으로 정확히 같은 시간을 표현하기 위한 타입이다. init() 현재 시간을 나타내준다. init(timeIntervalSinceNow: TimeInterval) 현재 시각으로 부터 입력한 초 이후의 시점을 나타낸다. init(timeInterval: TimeInterval, since: Date) 다른 Date()객체로부터 입력한 초 이후의 시점을 나타낸다. init(timeInt..
✔️ Apple 공식문서 참고 Apple Developer Documentation developer.apple.com Strings and Characters — The Swift Programming Language (Swift 5.5) Strings and Characters A string is a series of characters, such as "hello, world" or "albatross". Swift strings are represented by the String type. The contents of a String can be accessed in various ways, including as a collection of Character values. Swi docs.s..
🔍 Codable이 뭘까? Codable은 Decodable와 Encodable를 준수하는 타입(프로토콜)이다. JSON 데이터를 간편하고 쉽게 인코딩 & 디코딩 할 수 있게 해준다. typealias Codable = Decodable & Encodable 구조체, 클래스, 열거형 모두 Codable을 채택할 수 있다. 먼저 JSON을 인코딩 및 디코딩을 하는데 이용할 타입을 만들어주고 Codable를 채택하자. struct Person: Codable { // Codable 프로토콜 채택 var name: String var age: Int } 👉🏻 JSON 만들기 (Encoding) JSONEncoder를 선언한다. JSONEncoder의 encode메소드를 사용하여 인스턴스를 Data타입으로 만든..
Protocol Extension extension은 타입을 확장한다. 프로토콜 역시 타입이기 때문에 extension을 활용하여 확장할 수 있다. 프로토콜에는 정의만 한다고 하였는데 extension을 통해 구현을 추가한다는 것이 조금 어색할 수도 있다. 정리하자면 문법적으로는 프로토콜의 구현을 추가하지만 실제로는 프로토콜을 채용한 타입의 구현이 추가된다고 보면 된다. 코드의 중복을 줄이면서 프로토콜을 확장시킬 수 있다는 장점이 있다. 예제를 통해 이해해보자. protocol SayText { var text: String { get set } func say() } extension SayText { func say() { print(text) } } struct A: SayText { var tex..