I have project using Swift 3.2 and Objective-C compiling with Xcode Version 9.0 (9A235). It compiles fine in Swift 3.2. However, when I switch to Swift 4.0, the methods declared in Swift is no longer visible in Objective-C. The error is No visible @interface "UserAPI" declares the selector ...
Asked
Active
Viewed 3,823 times
4

MobileDev
- 3,750
- 4
- 32
- 35
-
6Most probably a duplicate of https://stackoverflow.com/questions/46829032/xcode-9-0-1-swift-4-no-method-declared-with-objective-c-selector-onclickfor and https://stackoverflow.com/questions/44390378/how-can-i-deal-with-objc-inference-deprecation-with-selector-in-swift-4 – add `@objc` to the members that you want to expose to Objective-C. – Martin R Oct 21 '17 at 07:36
2 Answers
8
You should add @objc before your function like this.
@objc func doSomething() {
//Some code goes here
}

Jared_M
- 547
- 1
- 5
- 13
2
Or! Use @objcMembers if you'd like to expose the entire class to Objective-C
@objcMembers class MyClass {
func methodOne() {
// no @objc required!
}
func methodTwo() {
// no @objc required here either!
}
}

h.and.h
- 690
- 1
- 8
- 26