Reputation: 9255
I have an objective-c class which tries to init a Swift class object using:
- (id) init : (ObjCTestClass*) testclass
{
NSLog( @"Creating" );
self = [super init];
if ( !self )
{
return nil;
}
self.testclass = testclass;
self.swiftClass = [[SwiftClass alloc] init: self.testclass];
return self;
}
Here is the corresponding Swift class:
final class SwiftClass: NSObject {
private var objcTestClass: ObjCTestClass
init(testclass:ObjCTestClass) {
provider = CXProvider(configuration: type(of: self).providerConfiguration)
objcTestClass = testclass
super.init()
}
}
I am getting the following error:
No visible @interface for 'xxx' declares the selector 'init:'
Note: ObjCTestClass is an objective-c class. I have bridging headers to expose objective-c to Swift and vice-versa.
How to fix this?
Upvotes: 2
Views: 2574
Reputation: 7746
It should be [[SwiftClass alloc] initWithTestClass: self.testclass]. This should autocomplete when you're typing if it's setup correctly
Upvotes: 2
Reputation: 9255
I fixed the above problem by setting the property explicitly after init:
final class SwiftClass: NSObject {
**public var objcTestClass: ObjCTestClass!**
init() {
provider = CXProvider(configuration: type(of: self).providerConfiguration)
super.init()
}
}
- (id) init : (ObjCTestClass*) testclass
{
NSLog( @"Creating" );
self = [super init];
if ( !self )
{
return nil;
}
self.testclass = testclass;
**self.swiftClass = [[SwiftClass alloc] init];
self.swiftClass.objcTestClass = self.testclass;**
return self;
}
Upvotes: 1