본문 바로가기
iOS/iOS

Objectice-C to Swift Migration

by 패쓰킴 2022. 8. 3.
728x90

AppDelegate.swift 생성

1. project - target - Build Setting - Define Module - YES

2. AppDelegate.swift 파일 생성

3. .swift 파일 생성시 프로젝트명-Bridging-Header 생성 옵션창이 같이 뜨니 생성해줄것

4. AppDelegate.h와 .m 파일에 있는 내용을 생성한 swift 파일에 swift문법으로 고쳐 작성

5. AppDelegate class 앞에 @objc 붙여주기 (Objective - C 에서 swift 객체를 인식하기 위함)

6. class 위에 @UIApplicationMain 을 붙여서 AppDelegate.swift 가 main임을 명시

7. 기존의 AppDelegate.h/.m 파일과 main.m 파일 삭제

AppDelegate.swift 사용

1. 사용하려는 Objective - C .h 파일 상단에 @class AppDelegate; 추가

2. .m 파일 상단에 #import "프로젝트명-Swift.h" 추가

3. 이후에는 objective-c로 프로그래밍 하던데로 swift의 객체 이용하면됨!

 

참고:

https://beenii.tistory.com/198?category=787971

https://newbedev.com/how-to-convert-objective-c-app-delegate-to-swift

https://mixup.tistory.com/107

https://learn-hyeoni.tistory.com/66

https://pilgwon.github.io/blog/2018/08/09/Objc-Swift-Transition.html

Swift closure(completion, handler) 사용하기

Swift closure 함수 생성
@objc func 함수명(파라미터명: @escaping (A타입, B타입) -> 리턴타입) {

}
Objective - C에서 사용하기
[[함수속한클래스 함수명With파라미터명:^(A타입 A파라미터, B타입 B파라미터) {

}];

 

참고:

https://stackoverflow.com/questions/38993345/call-swift-completion-handler-in-objective-c/51987636#51987636

728x90

'iOS > iOS' 카테고리의 다른 글

stored property에 'available' 사용하기  (0) 2022.08.16
카카오 SDK 설정  (0) 2022.08.09
PCH 파일  (0) 2022.07.29
웹 페이지의 자바스크립트 통신(JS <-> Swift)  (0) 2022.07.13
ViewController present (VC1위에 VC2 present)  (0) 2022.07.05

댓글