I want to access Swift code in Objective-c.
I have written one class in swift which contains static method. I want to access that Static Method in objective C Class.
Here is Class declaration:
@objc class LocalizedResource: NSObject {
/*!
* @discussion This function will get localize string for key
* @param key Localize key
* @return String for locaized key
* @code LocalizedResource.getStringForKey(key);
*/
static func getStringForKey(key:String) -> String {
let frameworkBundle = NSBundle.mainBundle()
let value = frameworkBundle.localizedStringForKey(key, value: nil, table: nil)
return value;
}
}
I have made following settings for it:
Also I have added @Obj before my class declaration in Swift class.
I have import MyProject-Swift.h in the .m file where I want to access that method.
But when I am trying to access it, it is not allowing me to access that static method.
Is any one having solution for it? Is there something missing?
Thnaks.
From your comment:
I am calling this method as follows:
errorMessage.text = LocalizedResource.getStringForKey(@"TIMED_OUT_ERROR");
In Objective-C, the "dot syntax" is used for properties, not for methods. The correct call should be
errorMessage.text = [LocalizedResource getStringForKey:@"TIMED_OUT_ERROR"];
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments