Objective-C 에서 Swift 사용하는 방법
#import "프로젝트 명-Swift.h"
를 사용하면 swift 객체를 Objective-C 문법 그대로 활용 가능
#import "ViewController.h"
#import "프로젝트 명-Sift.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
popCalendarViewController = [[PopCalendarViewController alloc] init];
}
- (IBAction)buttonClicked:(id)sender {
popCalendarViewController.modalPresentationStyle = UIModalPresentationOverFullScreen;
popCalendarViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:popCalendarViewController animated:false completion:^(void){}];
}
@end
Swift 객체에 적용해줘야 할 것
@objc
어노테이션을 Class에 적용해주면 됨
그리고 사용할 프로퍼티 혹은 메서드 앞에 @objc
키워드를 적용해줘야
Objective-C 프로젝트에서 사용 가능
@objc
final class PopCalendarViewController: UIViewController {
@objc var selectedDate: NSDate?
private let popCalendarView = PopCalendarView()
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(popCalendarView)
popCalendarView.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
print("selectedDate: \(String(describing: selectedDate))")
popCalendarView.calendarDelegate = self
popCalendarView.calendarDataSource = self
popCalendarView.delegate = self
}
}
// Objective-C 파일에서 사용 예시
NSLog(@"%@", popCalendarViewController.selectedDate);
프로젝트에 설정해줘야 할 것
Targets → Build Setting → Defines Module의 값을 No → Yes로 변경해주면
Swift파일의 헤더파일을 자동으로 생성해줌

Swift에서 Objective-C 사용하는 방법

swift파일을 추가하면 아래와 같이 브릿징 헤더를 만들라고 얼럿이 뜬다

Create를 누르면 자동으로 “프로젝트 이름-Bridging-Header.h” 파일이 생성된다.

“프로젝트 이름-Bridging-Header.h”
아래와 같이 사용할 Objective-C 클래스의 헤더를 추가해준다

Objective-C프로젝트에 라이브러리 적용시 에러핸들링
sdk does not contain 'libarclite' at the path '/applications/xcode.app/contents/developer/toolchains/xcodedefault.xctoolchain/usr/lib/arc/libarclite_iphonesimulator.a'; try increasing the minimum deployment target

sandbox: rsync.samba(63589) deny(1) file-write-create /users/zundaeng/library/developer/xcode/deriveddata/objectivec_bridge_header-enozseokazaoaqbhslfltxekunyi/build/products/debug-iphonesimulator/objectivec bridge header.app/frameworks/fscalendar.framework/_codesignature
Project → Build Setting → User Script Sandboxing

위 세팅처럼 User Script Sandboxing을 Yes → No로 설정해주면 됩니다.
Uploaded by N2T