4

I am creating a new framework in swift for iOS. My project structure/hierarchy is

*Client(Single View Application)
    **Framework as a project
    **ViewController in Client consuming Framework

I am coding completely in Swift. Earlier i used objective C, which had .h file for defining headers. But in Swift there is no interface file. How is this gap addressed in case of frameworks? And i couldn't find any tutorial describing end to end flow of creating a swift framework.

All that i want to do is to create a simple function inside a framework and expose it for accessing the same in my client's VC.

The tutorial i followed is in https://github.com/hpique/Talks/blob/master/Building%20Swift%20frameworks/Building%20Swift%20frameworks.md

But i am not able to access the function in my client's VC. The function is not exposed. Kindly share me your thoughts in case if you have experienced the same or any other detailed tutorial in Swift 2.0.

1 Answer 1

3

You seem like you are on the right track. Couple things to make sure of:

  • Did you set your Framework as a target dependency to your Client in build phases?
  • Did you import the framework in the file you are trying to access it from?
  • Does the function you want to access have the right access controls (i.e. is it marked public)?
3
  • For the first point, Yup i added the framework as a dependent project. I have a problem with the second point. When i try to import, i get a compilation error as "*.swift file not found". Third, yes i have marked it as public.
    – vivin
    Commented Oct 5, 2015 at 20:11
  • Make sure you are importing the module and not a swift file. If your framework module is called "Framework" and you define the function in "Functions.swift" you want import Framework not import Functions.swift. Can you successfully compile the framework target by itself? If you can make your code accessible on github, I can try and help troubleshoot it.
    – Scott H
    Commented Oct 5, 2015 at 20:17
  • Ok, I submitted a pull request with the fixes. You did't have the SampleFramework as a dependency to the SampleClient. When I added that, I was able to compile, import the SampleFramework in the SampleClient's ViewController and use the exposed FileOne class.
    – Scott H
    Commented Oct 5, 2015 at 20:47

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.