Reputation: 3545
I have an Objective-C application where I like to integrate Swift, but I have an odd issue.
I imported <#ProjectName#>-Swift.h
to my implementation file, where I needed the Swift Class. My Swift Class looks like this:
import Foundation
@objc class FileIconColor: NSObject {
@objc func fileIconColorForSuffix(suffix: NSString) -> UIColor {
var color:UIColor!
//Some huge calculations
return color
}
//Just for testing
@objc func test () {
println("Test")
}
}
I am able to call the Class, but I am not able to access the functions in the class; As you can see, the @objc
prefixes are there, on both the Class and its functions.
Do you know why this happens? I also build the project before I want to use the function, because the Swift bridging header first needs to be built, am I correct?
Oh and btw, I managed to access Objective-C code in my Swift Class. So there can't be much wrong (I manually created the Objective-C bridging header) :)
Thanks, David
Upvotes: 1
Views: 1354
Reputation: 4970
I just tested to see that it works for me in an old Objective C project. I'm on Xcode 6.0.1.
I did this:
At the top:
#import "PhotoUnzipper-Swift.h"
(PhotoUnzipper's the name of my project)
and in viewDidLoad:
FileIconColor *color = [[FileIconColor alloc] init];
[color test];
It compiled, and I got "Test" printing out in the console.
Important: I did not import the <#ProjectName#>-Swift.h
file. Xcode takes care of that.
The first time I tried, I had problems because I had a deployment target of 4.1. (silly me.) I did not seem to be able to resolve that, but started again, and followed those steps above exactly and it worked.
Upvotes: 2