@objc 란,

objective-c에서 스위프트로 선언된 클래스, 메소드, 밸류 프로퍼티 등을 참조하고 싶을 때 @objc 프로퍼티를 지정해 주면 된다.

기존에 만들어진 어플에 스위프트로 작업하고 있기 때문에 @objc 프로퍼티를 쓸 일이 잦은데 swift4 부터 @objcMembers 라는 프로퍼티가 생겼다.

기존의 @objc와 다른 점이 무엇인가 찾아보니 다음과 같이 명시되어 있다.

When a Swift class introduces many new methods or properties that require behavior from the Objective-C runtime, use the @objcMembers attribute in the declaration of that class. Applying the @objcMembers attribute to a class implicitly adds the @objc attribute to all of its Objective-C compatible members. Because applying the @objc attribute can increase the compiled size of an app and adversely affect performance, only apply the @objcMembers attribute on declarations when each member needs to have the @objc attribute applied.


@objc는 파일 사이즈와 성능에 영향을 준다니 @objcMembers로 쓰지 않을 이유가 없다.

단, @objcMemebers는 클래스에만 사용할 수 있기 때문에 특정 method나 프로퍼티만 공유하고 싶을 땐 @objc 그대로 사용하면 된다.

이왕이면 전부 Swift로 바꾸고 싶지만 당분간만 유지하기로 해...

+ Recent posts