MobileDev
MobileDev

Reputation: 3795

Swift method not visible in objective C

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 ...

enter image description hereenter image description here

Upvotes: 4

Views: 4097

Answers (2)

h.and.h
h.and.h

Reputation: 776

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!
    }

}

Upvotes: 2

lex_shvets
lex_shvets

Reputation: 717

You should add @objc before your function like this.

@objc func doSomething() {
   //Some code goes here
}

Upvotes: 8

Related Questions