반응형
반응형

SwiftUI에서 UIkit 사용하기


SwiftUI에서 UIkit를 사용하기 위해서는 UIViewRepresentable을 채택하는 struct를 구현하면 됩니다.

UIViewRepresentable을 채택하게 되면 필수로 구현해야 하는 makeUIView와 updateUIView가 있고 UIViewType을 원하는 UIkit의 View로 변경하면 됩니다.

UIViewRepresentable

// 구현
struct SwiftUIView: UIViewRepresentable {
	func makeUIView(context: Context) -> UIViewType {
    	let view = UIViewType()
        return view
    }
    
    func updateUIView(_ view: UIViewType, context: Context) {
    
    }
}


// 사용
struct MyView: View {
	var body: some View {
    	VStack { 
        	SwiftUIView()
        }
    }
}

UIViewControllerRepresentable

만약 Custom View가 아닌 하나의 Controller일때는 UIViewControllerRepresentable이라는 것을 따로 제공합니다. 

makeUIViewController에 해당하는 ViewController를 리턴하도록 해주면 됩니다.

struct MyViewControllerRepresentation: UIViewControllerRepresentable { 
	func makeUIViewController(context: Context) -> ViewController {
		
    }

	func updateUIViewController(_ uiViewController: ViewController, context: Context) { 
    
    } 
}

 

 

SwiftUI에서 Storyboard 사용하기


코드로 구현된 UIViewController가 아닌 Storyboard(.xib)로 구현되어있다면 어떻게 해야할까요?

UIStoryboard

struct MyViewControllerRepresentation: UIViewControllerRepresentable { 
	func makeUIViewController(context: Context) -> ViewController {
		UIStoryboard(name: "MyStoryBoardView", bundle: nil)
        	.instantiateViewController(withIdentifier: "ViewController") as! ViewController
    }

	func updateUIViewController(_ uiViewController: ViewController, context: Context) { 
    
    } 
}



반응형

알고리즘 문제를 풀어보려고 하는데 문제를 풀어도 어떤식으로 제출을 해야 하는지에 대한 글입니다.

 

1. 문제 풀기 위한 Xcode 세팅

1. 먼저 xcode를 열어 new project를 만듭니다.

2. macOS에서 Commend Line Tool을 선택합니다.

3. main.swift 파일에서 문제를 푸시면 됩니다!

 

Playground로 하지 않고 Command Line Tool로 하는 이유는 아래를 보면 알 수 있습니다.

 

2. 입력값을 받는 문제

문제중에 입력값을 받는 문제들이 있습니다. 이 입력값을 받기 위해 일반 Playground를 사용하지 않고 Command Line Tool을 사용합니다.

 

입력값을 받기 위해서는 readLine()을 호출하면 됩니다.

실행을 하게되면 먼저

1. Hello, World!가 찍힘

2. 해당 콘솔창에 insert!!!를 입력

3. 옵셔널로 insert!!!가 print

 

가 되는 것을 볼 수 있습니다.

 

반응형

'Algorithm > BackJoon' 카테고리의 다른 글

[Swift] 백준 11047 - 동전 0  (0) 2022.01.24
[Swift] 백준 11399 - ATM  (0) 2022.01.23
[Swift] 백준 2839 - 설탕 배달  (0) 2022.01.23

Xcode 13.2 버전 업데이트 후 발생하는 오류

 

애플 공식 답변

- We're currently investigating this issue — thank you to those who have filed bug reports so far.

To workaround this issue, please re-download Xcode 13.2 directly from Releases section of the Apple Developer website. This information is also captured in the Xcode 13.2 Release Notes.

If you still encounter this issue after downloading that specific version of Xcode, please open a bug report using Feedback Assistant, and post the FB number here.

 

해결방법은 Xcode 삭제 후 Apple Developer 웹 사이트에서 직접 재설치 한다.

 

https://developer.apple.com/download/all/?q=Xcode%2013.2

 

로그인 - Apple

 

idmsa.apple.com

 

반응형

'ios > Xcode' 카테고리의 다른 글

Terminal에서 바로 Xcode 프로젝트 파일 실행하기  (0) 2022.05.11

+ Recent posts