iOS - Not able to access Static method of swift class

NiksT

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:

  1. Product Module Name : MyProject
  2. Defines Module : YES
  3. Embedded Content Contains Swift : YES
  4. Install Objective-C Compatibility Header : YES
  5. Objective-C Bridging Header : $(SRCROOT)/MySources/SwiftBridgingHeader.h

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.

Martin R

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.

edited at
0

Comments

0 comments
Login to comment

Related

TypeScript: access static method of a class

static vs class as class variable/method (Swift)

Not able to access static files

Object of type super class not able to access method of Sub class

How to access a static method via a class reference

Static method cannot access instance members of a class

Access The Type of the Containing Class of a Static Method in Java

Access static variables within class in Swift

Swift unit tests mock class static method

Swift: Get current class from a static method

Access static variable from non static method in Swift

Not able to access a class attribute

Not able to access static files in express

Access variable in another method from static method in same class

Access method of private class inside static inner class from main()

How to access a static member of the class in a decorator for a method of that class?

AndroidAnnotations access Singleton class object into other class static method

How to access protected variable of class inside static method of the same class?

Sub-class not able to access the protected method of super-class when the reference is of type super-class

custom class method returning nil Swift IOS

Why javascript static variable not able to access ( using class name ) without creating minimum one instance?

Not able to access a instance of a class from within a static procedure. C#

Why inner class can not access outer class method which is overload between normal method and static method?

How can static method access class variable in Python?

How can static method access class variable in Python?

PHP reference Class from variable with static method access

Access private static method from outside the class C++

Cannot access a method call from non-static to non-static class/method

es6 access static method of child class from static method of parent?