36

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?

Vatsal Manot
  • 17,695
  • 9
  • 44
  • 80

2 Answers2

55

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.

Vatsal Manot
  • 17,695
  • 9
  • 44
  • 80
  • 5
    After I did add "public" to everything, quit Xcode, remove ~/Library/Developer/Xcode/DerivedData, relaunch Xcode and errors disappeared. – mash Oct 29 '14 at 15:57
  • 2
    I forget this part everytime...grrrrr – naz Dec 11 '14 at 05:00
  • 1
    Old thread but one note: Instead of deleting that folder, I found that switching my scheme to the framework and running a build, then switching the scheme back to my app and running a build, accomplishes the same refresh. – John Shammas Mar 22 '15 at 16:12
  • "trashing the ~/Library/Developer/Xcode/DerivedData" did the trick for me, thanks! – eilas Jul 18 '17 at 09:11
  • Do you mind posting your test project on github. I am trying to make framework. and I am getting the same sort of issue. classes and func are not accessible in the separate test project that I am creating. – Alok C Oct 15 '17 at 01:36
  • And also check SDK min. support version and your app main target support version. – Naresh Nov 16 '21 at 10:40
1

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.

rustyMagnet
  • 3,479
  • 1
  • 31
  • 41