Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't access class from custom dynamic framework (Swift)

My test dynamic iOS framework XYZFramework consists of a single class XYZ.

However, even after declaring:

import XYZFramework

I am unable to access this class, with any attempts yielding the following error:

Use of unresolved identifier 'XYZ'

How do I resolve this issue?

like image 773
Vatsal Manot Avatar asked Sep 13 '14 13:09

Vatsal Manot


2 Answers

Found the answer. I had to prefix my class declaration with the public modifier. So this:

class XYZ {

}

became:

public class XYZ {

}

And, as always, trashing the ~/Library/Developer/Xcode/DerivedData folder fixed any minor complications.

like image 155
Vatsal Manot Avatar answered Nov 14 '22 20:11

Vatsal Manot


If your Framework's class also contained Static and Instance Member functions you also need some more public keywords adding.

// set the Framework class to Public
public class FrameworkHello{  

   // set the initializer to public, otherwise you cannot invoke class
   public init() {  

   }

   // set the function to public, as it defaults to internal
   public static func world() {  
       print("hello from a static method")
   }
}

Now you can access this via your Swift code or with lldb:

(lldb) po FrameworkHello.world()
hello from a static method

This ensures the Framework's Symbols are accessible in a Release build.

like image 1
rustyMagnet Avatar answered Nov 14 '22 20:11

rustyMagnet