Swift 4.0 오류 보고: Argument of'#selector'refers to instance method xxx

1204 단어 학습 노트
swfit 4의 새로운 기능
오늘 코드를 컴파일하여 이 문제를 발견했습니다. 찾아보니 수정은 매우 간단합니다. 관련 클래스 앞에서 다음과 같이 추가합니다.
@objcMembers
class JKWLoginVC: UIViewController 
{
}

아니면 방법명 앞에서 수정을 해요.
@objc func clickLoginBtn() {

    }

As of Swift 4 you’ll start seeing the error “Argument of ‘#selector’ refers to instance method ‘firstPage()’ that is not exposed to Objective-C”, along with the proposed fix of “Add ‘@objc’ to expose this instance method to Objective-C”. What this means is that the Swift method in question isn’t visible to Objective-C, which matters because UIBarButtonItem is Objective-C code.
While adding @objc to individual methods is a working solution, I expect most people will just shrug their shoulders and put @objcMembers before their class – that automatically exposes everything in the class to Objective-C, just like Swift 3 used to. So, modify the class definition to this:

좋은 웹페이지 즐겨찾기