2016-12-24 4 views
0

우리가 알고 있듯이 Swift 언어는 함수 오버로딩을 허용하고 Objective-c에서는 오버로드가 유효하지 않습니다.스위프트 오버로드 문제

enter image description here

왜 제공 :

Method ‘helloFuc’ with Objective-C selector ‘helloFunc:’ conflicts with previous declaration with the same Objective-C selector

내가 사진을 촬영 : 오류가 오는 이유

import UIKit 

class FuncOverLoad: NSObject { 

func helloFuc (_ what:String) { 

} 
func helloFuc (_ what:Int) { 

} 


func helloFuc() -> String { 

    return "one" 

} 
func helloFuc() -> Int { 

    return 1 

} 
} 

그러나 :

그래서 난 내 데모 프로젝트에서 테스트 문제가 있다면 Swift 함수 오버로드가 합법적입니까?

+1

이 질문에 대해서는 중복 된 내용입니다. 훨씬 더 좋은 방법은 다음과 같습니다. http://stackoverflow.com/questions/29457720/compiler-error-method-with-objective-c-selector-conflicts-with-previous-declara?s=1|6.5289 – rmaddy

답변

0

귀하의 경우 : NSObject을 제거하면 오류가 해결됩니다.

+0

' NSObject'는'Objective-C'와 관련이 있습니까? – aircraft

+0

이 경우 Swift의 오버로드 특성은 iOS 개발시 실제 중요성이 거의 없기 때문에 'vc'또는 'controls'등이 있습니다. – aircraft

+0

'NSObject'를 서브 클래 싱하는 것은'@ objc'을 의미하므로 Objective C와 같은 규칙에 구속됩니다 – Alexander