Swift: add, adds, append, appends 속도 비교
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]을 배열에 더하는 연산을 다중 add, adds, 다중 append, appends로 각각 수행할 때의 속도 비교다중 add를 제외하면 평이하며, 다중 add의 경우 n이 100000000 일 때, 다른 API에 비해 3배의 속도 차이가 발생 import SwiftUIfunc measure(label: String, repeatCount: Int, function: () -> ()) { let time = ContinuousClock().measure { for _ in 1...repeatCount { function() } } print(label, ":", time)}struct ContentView: View { @State ..
2025. 3. 30.
Swift: async let 수행 순서
async let의 수행 순서는 await 순서에 따름func function(_ name: String, _ i: Int) async -> Int { print("sleep: ", name, i) sleep(UInt32(i)) print("wake up: ", name, i) return i}async let a = function("a", 10)async let b = function("b", 3)async let c = function("c", 2)async let d = function("d", 5)async let e = function("e", 3)async let f = function("f", 5)async let g = function("g", 3)async let ..
2025. 3. 30.
알쓸스잡 - 6
stridestride(from: , to: , by:)열린 범위 -> 0...5stride(from: , through: , by:)닫힌 범위 -> 0.. switch 연속 케이스fallthrough를 사용하면 C 처럼 케이스 이후 다음 케이스로 넘어감let integerToDescribe = 5var description = "The number \(integerToDescribe) is"switch integerToDescribe {case 2, 3, 5, 7, 11, 13, 17, 19: description += " a prime number, and also" fallthroughdefault: description += " an integer."}print(descriptio..
2025. 1. 21.
알쓸스잡 - 2
Swift에서 제공하는 데이터 타입기본 데이터 타입: Int, Double, Bool, ...컬렉션 타입: Array, Set, Dictionary 플랫폼에 따른 Int플랫폼에 따라 Int의 크기가 달라짐32 bit: Int -> Int3264 bit: Int -> Int64UInt 또한 동일 Double, Float 크기Double: 64 bit 부동 소수점, 15자리의 소수점 정확도Float: 32 bit 부동 소수점, 6자리의 소수점 정확도 타입 세이프티, 타입 추론 시점타입 세이프티, 타입 추론은 컴파일 단계에서 검사 숫자 리터럴0b 접두사: 2진수0o 접두사: 8진수0x 접두사: 16진수 아래는 모두 10진수 17let decimalInteger = 17let binaryInteger = 0b1..
2024. 12. 26.
SwiftUI + Combine MVVM 아키텍쳐 분석 - 7
TestCore Data데이터를 저장하고, 불러오는 로직에 대한 테스트init 후 empty 한지, 접근 불가능 디렉터리에 접근 가능한지, ...System시스템 기능들이 제대로 동작하는지에 대한 테스트딥 링크, life cycle, ...UtilityLoadableTests지연 가능 값과 에러 핸들링에 관한 테스트원소가 동일한지, 취소했을 때 결과, throwing, ...LazyListTestscollection에 관한 테스트empty, nil, concurrent access, ...HelpersTestslocalization에 관한 테스트RepositoryWebRepositoryTests네트워킹과 에러 핸들링에 관한 테스트ImageWebRepositoryTests이미지 불러오기에 관한 테스트suc..
2024. 11. 11.
Data Type
Class, Struct데이터를 캡슐화하기 위한 모델클래스와 구조체 공통점속성 정의(property), 기능 정의(method), 첨자 구문 정의(subscript), 초기화 구문 정의(init), 확장 가능(extension), 프로토콜관련 문서: Properties, Methods, Subscripts, Initialization, Extensions, Protocols클래스만 가진 기능상속 가능타입 캐스팅 사용으로 런타임에 클래스 인스턴스 타입 확인 및 해석deinit참조 카운팅으로 두 개 이상의 참조 허용관련 문서: Inheritance, Type Casting, Deinitialization, Automatic Reference Counting클래스와 구조체일반적으로 클래스가 지원하는 기능을 다..
2024. 11. 7.