본문 바로가기

iOS/Swift

(60)
[Swift] ARC(Automatic Reference Counting) Automatic Reference CountingSwift는 메모리 관리를 위해 Automatic Reference Counting(ARC)라는 시스템을 사용한다. 대부분의 경우, ARC는 Background에서 자동으로 작동하기 때문에 개발자는 직접 메모리 관리에 신경 쓸 필요가 없다. 하지만 ARC가 어떻게 작동하는지 이해하면, 앱의 메모리 사용을 최적화하거나, 참조 순환(reference cycle) 같은 문제를 피하는 데 도움이 된다. 메모리 관리란?컴퓨터의 메모리는 프로그램이 실행되는 동안 데이터를 저장하기 위해 사용된다. Swift에서는 대부분의 값이 struct, enum, class로 정의된다. 이 중에서 struct와 enum은 값 타입(value types) 이므로, 새로운 인스턴스를..
[Swift] 앱에서 앱 설정으로 이동 openSettingsURLString | Apple Developer DocumentationThe URL string you use to deep link to your app’s custom settings in the Settings app.developer.apple.comif let url = URL(string: UIApplication.openSettingsURLString){ UIApplication.shared.open(url)} 응용[앱 이름]>[알림]에서\n알림을 허용해" data-og-host="dev-geeyong.tistory.com" data-og-source-url="https://dev-geeyong.tistory.com/74" data-og-url="https://..
[iOS] WKUIDelegate WKUIDelegate(Protocol) : 웹페이지를 대신하여 기본 UI 요소를 표시하는 방법 새 창이 열리는 것을 제어 사용자가 요소를 클릭했을 때 표시되는 기본 메뉴 Item의 동작을 강화 기타 UI 관련 작업 수행 JavaScript 또는 기타 플러그인 콘텐츠를 처리하는 결과로 호출 WKUIDelegate | Apple Developer Documentation The methods for presenting native user interface elements on behalf of a webpage. developer.apple.com webView(_:createWebViewWith:for:windowFeatures:) 새로운 웹뷰를 생성 webView(_:createWebViewWith:..
[iOS] WKNavigationDelegate WKNavigationDelgate 웹뷰의 탐색(navigation) 변경사항을 수락 또는 거부하고 탐색 요청 진행 상황을 추적하는 방법 WKNavigationDelegate | Apple Developer Documentation Methods for accepting or rejecting navigation changes, and for tracking the progress of navigation requests. developer.apple.com webView(_:decidePolicyFor:preferences:decisionHandler:) 웹 페이지의 탐색 허용 여부를 결정할 때 webView(_:decidePolicyFor:preferences:decisionHandler:) | Ap..
[Swift] Calendar Calendar(struct) 달력 단위와 절대 시점간의 관계를 정의하고, 날짜 계산 및 비교 기능 제공 import Foundation // 달력 선택 let buddhistCalendar = Calendar(identifier: .buddhist) let now = Date() // 사용자의 현재 달력 let calendar = Calendar.current // 날짜 요소에 접근하기 let year = calendar.component(.year, from: now) // 년(Int) let month = calendar.component(.month, from: now) // 월(Int) let day = calendar.component(.day, from: now) // 일(Int) let w..
[Swift] Mirror Mirror (struct) : 모든 유형 인스턴스의 하위 구조 및 표시 스타일을 나타냄 - 인스턴스의 저장된 속성, 컬렉션이나 튜플의 요소, 활성 열거형 케이스 등 특정 인스턴스를 구성하는 부분을 설명 struct Point { let x: Int, y: Int } let p = Point(x: 21, y: 30) print(String(reflecting: p)) // Prints "▿ Point // - x: 21 // - y: 30"
[iOS] viewIsAppearing(_:) viewIsAppearing(_:) 시스템이 ViewController의 view를 view 계층구조에 추가하고 있다는 것을 ViewController에 알림 호출 이후에 ViewController의 view가 나타날 때마다 System은 이 함수를 한 번씩 호출합니다. viewWillAppear(_:)와 달리 System은 ViewController의 view를 view계층 구조에 추가하고 이 함수를 호출하고 Superview는 ViewController의 view를 배치합니다. viewWillAppear vs viewIsAppearing System은 모양을 전환하는 중에 viewIsAppearing(_:)을 한 번만 호출하고 view가 나타날 때 Layout이 필요하지 않은 경우에도 호출합니다.
[iOS] XCTest XCTest Xcode Project의 unit test, 성능 test, UI test 케이스를 만들어 실행하는 Framework XCTest | Apple Developer Documentation Create and run unit tests, performance tests, and UI tests for your Xcode project. developer.apple.com ViewController.swift class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } } XCTestCase fina..