목록Swift (208)
HIT해

CaseIterable이란?CaseIterable은 Swift에서 열거형의 모든 케이스를 컬렉션처럼 다룰 수 있게 해주는 프로토콜이다.이 프로토콜을 채택한 열거형은 자동으로 allCases 라는 속성을 가지게 되며, 이를 통해 열거형의 모든 케이스를 배열 형태로 접근할 수 있다. 기본 사용법enum CompassPoint: CaseIterable { case north case south case east case west} 이렇게 하면 CompassPoint.allCases 를 통해 열거형의 모든 케이스에 접근할 수 있다.for direction in CompassPoint.allCases { print(direction)} 배열로 만들기allCases를 활용하여 열거형의 모..

Computed Property란?Computed Property는 클래스, 구조체, 열거형에서 값을 저장하지 않고, 간접적으로 값을 계산하여 반환하는 속성을 뜻한다.Stored Properties와 달리 Computed Properties는 값이 직접 저장되지 않고, 매번 접근할 때마다 특정 연산을 통해 값을 반환한다. 기본 구문Swift에서 Computed Properties는 get 블록과 set 블록(선택사항) 으로 구성된다. struct Rectangle { var width: Double var height: Double var area: Double { get { return width * height } se..

while 반복문이란?while 반복문은 특정 조건이 참일 때 코드 블록에서 반복해서 실행하는 구조다.반복이 계속될지 여부는 반복문이 시작되기 전에 평가되는 조건에 따라 결정되고, 조건이 거짓이 되거나 break 문이 실행되면 반복이 종료된다.기본적인 사용법var count = 0while count 무한루프while true { print("This will print forever")} 이 코드는 true가 항상 참이기 때문애 무한히 실행된다.무한 루프는 break 구문을 사용하여 특정 조건에서 탈출할 수 있다. var count = 0while true { print("Count is \(count)") count += 1 if count == 5 { break ..

Tuple이란?Swit에서 튜플은 다양한 값의 묶음이다.튜플의 구성 요소들은 서로 다른 타입이 가능하며 개수도 사용하고 싶은 만큼 사용할 수 있다.기본 예시import UIKit// (키: 값, 키: 값)var myPet : (name: String, kind: String, age: Int) = (name: "댕댕이", kind: "강아지", age: 1)// 키 명을 생략할 수 있다.var myCat : (String, String, age: Int) = ("개냥이", "고양이", age: 1)myCat.age// 인덱스로 접근myPet.0 키 이름이 생략할 수도 있으며 키 이름이 없다면 인덱스로 접근할 수도 있다.메소드 반환 Tuple// 반환 타입을 튜플로 선언func someFunction() ..

https://developer.apple.com/documentation/swiftui/view/sheet(ispresented:ondismiss:content:) sheet(isPresented:onDismiss:content:) | Apple Developer DocumentationPresents a sheet when a binding to a Boolean value that you provide is true.developer.apple.com TCA 구조로 만들어진 프로젝트에서 Sheet 를 구현해보자! nonisolatedfunc sheet( isPresented: Binding, onDismiss: (() -> Void)? = nil, @ViewBuilder conten..

TCA란?TCA(The Composable Architecture)는 Swift와 SwiftUI를 사용하여 애플리케이션의 상태 관리와 비즈니스 로직을 다루기 위한 아키텍처.TCA는 Point-Free라는 소프트웨어 개발 회사에서 만든 오픈 소스 라이브러리구성요소State (상태): 애플리케이션의 현재 상태Action (액션): 상태를 변경하는 이벤트Reducer (리듀서): 액션에 따라 상태를 변경하는 함수Store (스토어): 상태, 리듀서, 및 액션을 관리하는 중앙 저장소Environment (환경): 외부 시스템과의 상호작용을 추상화한 것 구성요소 구체예시State (상태):애플리케이션의 현재 상태를 나타내는 구조체상태는 애플리케이션에서 중요한 데이터와 UI 상태를 포함예시: 사용자 정보, UI의 ..

https://developer.apple.com/documentation/swift/caseiterable CaseIterable | Apple Developer DocumentationA type that provides a collection of all of its values.developer.apple.com enum으로 얼굴 상태들을 선언해주고 바꿀 수 있는 버튼을 만들어보자! 1. enum 선언enum Face : String,CaseIterable { case sparkle case sosim case saechim case nareun case meong case cupid case bboombboom case balral case chi..

dae 모델링 파일에서 한 모델안에 모든 커스터마이징 노드들을 담고 선택한 노드만 보이게 만들어보자! UIViewRepresentable 프로토콜 함수인 updateUIView 를 통해 특정 노드만 isHidden 키워드로 남겨두자. 예시코드struct ContentView: View { @State var showChic = true var body: some View { VStack{ Text("3D Test") DolView(showChic: $showChic) Button("Show Chic") { // 일단 showChic를 false로 설정하여 상태 변화를..