I'm working on an iOS application written in Objective C that has an attached class written in Swift. When I try to call a in my Obj C AppDelegate.m, I don't get any errors, but the reply callback never fires.
My ObjC has the following methods:
- (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void(^)(NSDictionary *replyInfo))reply {
NSString *success =[ApiController handleCall];
//NSString *success =[self hello]; // This works if you swap it with the above method
//NSString *success = @"hello"; // when uncommented this also works.
NSDictionary *dict = @{@"status" : success};
reply(dict);
}
-(NSString *)hello{
return @"hello";
}
NSString *success = [SwiftClass swiftMethod];
My swift class looks like this:
@objc class SwiftClass {
@objc func swiftMethod()->NSString{
return "it works!"
}
}
In addition to the above code, I've made sure to include #import "ProjectName-Swift.h", as well as create a bridging header for the swift code.
Am I missing anything?
swiftMethodactually inside a method? Are you calling it on an instance ofSwiftClassor are you literally calling[SwiftClass swiftMethod]? The latter won't work becauseswiftMethodisn't a type method.