11

I've seen this question asked a few times like here and here but all the questions I've looked up seemed outdated or had answers that did not line up with the issue I'm having.

I have 2 frameworks - one with some classes to do processing (lets call it ProcessingLibrary) and a second that makes use of my processing framework.

In the ProcessingLibrary framework I have a public class declared in a swift file like so:

public class SomeClass {

    public init(_ stuff: String) {
        // do stuff
    }
    ...

and it builds and everything is beautiful and life is wonderful.

Then in the other framework that tries to make use of SomeClass I import the .framework file to Linked Frameworks and Libraries and add it to the framework search path, and then have another class that tries to create an instance of SomeClass like this:

Import Foundation
Import ProcessingLibrary

class SomeOtherClass {
    var someClassInstance: SomeClass

    init() {
        someClassInstance = SomeClass("stuff")
    }

    ...

When I do this xcode tells me that someClassInstance is an ErrorType and gives me the Use of undeclared type SomeClass error, however if I build the library it succeeds with no warnings and no errors. In fact I can even archive it and use it in other projects.

So technically I could just write the library knowing what calls I need to make and just ignore these xcode errors, but it would be nice to be able to have the autocomplete and not see errors on every line. (In fact in the last 2 days since i originally asked this question I have done this)

I've tried doing clean build, deleting derived data, deleting and re-adding the framework, restarting xcode... nothing seems to fix it.

It may be important to note that xcode DOES autocomplete the import line for ProcessingLibrary and the only other thing it can find with autocomplete / is able to jump to definition of is ProcessingLibraryVersionNumber which is defined in the ProcessingLibrary.h header file.

I need to distribute this outer framework however it seems that anywhere I include the outer framework also has the same problem it does, where xcode can't find its class / method definitions but it will build successfully.

Update

Okay, so based on the answers there must be something else missing that I'm not including causing the issue.

So the only info I hadn't mentioned in the original post (since I thought it was unrealated) is that the ProcessingLibrary also includes a static library of C code and is essentially just a swift wrapper for that C code.

It has a CWrapper.m and CWrapper.h file that import the C code I need and provide easier calls for it and the ProcessingLibrary.h imports the CWrapper.h like:

#import <ProcessingLibrary/CWrapper.h>

and CWrapper.h is a public header.

Then the majority of the code for the project is in SomeClass.swift that makes the C calls through my CWrapper files.

The static c library .a files are in another directory outside of the project and I just point to them and have a build setting for library search paths that points to it.

The only other build setting I have changed from the default is Enable Bitcode -> NO because my C library doesn't support the bitcode.

Not sure if any of that info will relate to this error but hopefully it helps.

Thanks everyone who has given an answer!

Quinn
  • 3,896
  • 2
  • 22
  • 45
  • Make the library depend on the main project so it always builds first? – matt Apr 02 '19 at 19:26
  • @matt I'm not sure I understand what you mean by that... there is no "main project" just a library that includes another library. The one library does depend on the other library – Quinn Apr 02 '19 at 19:29
  • Oh I see what you are saying. Just turn off Live Issues in the Xcode preferences if that’s what generates the error markers. – matt Apr 03 '19 at 15:09
  • Thanks for that tip! That does improve my QOL a good amount, but it still doesn't feel like a solution - I would like to have autocomplete and be able to jump to my class definitions but xcode still can't find the classes. Theres got to be something wrong with how I build my framework that xcode cant parse it right but I'm not sure what. – Quinn Apr 03 '19 at 15:18
  • I was going to suggest filing a bug report. If things compile and run, the parser must be at fault. That sort of thing does happen, and it’s a clear bug. For example, I sometimes find that it can lose its ability to supply a right curly brace. – matt Apr 03 '19 at 15:22
  • 1
    Why don't you post a tiny demo project with a couple of libraries consisting of single classes reproducing the issue? – matt Apr 08 '19 at 17:12
  • @matt Unfortunately the libraries I'm using are confidential so I can't post the majority of it – Quinn Apr 08 '19 at 17:14
  • Yes, but if this phenomenon is reproducible _you_ should be able to figure out how to reproduce it, just using some tiny libraries you create yourself. It needn't have anything to do with the "the libraries I'm using". And if the phenomenon is _not_ reproducible then no answer is possible and you've thrown away 100 points of rep to no purpose. So you ought to _want_ to demonstrate this issue somehow. – matt Apr 08 '19 at 17:17
  • @matt I've currently resorted to rewriting the whole `ProcessingLibrary` in Obj-C, (luckily it isn't too big of a library) but if I have time later I will try reproducing it like that – Quinn Apr 08 '19 at 17:19
  • @Quinn, do the both targets have same default configuration? – Anand Apr 09 '19 at 15:04

4 Answers4

3

I believe this is because your classes do not belong to the same target. This has worked for me in the past, I hope it does for you as well.

Select the file > open the file inspector > ensure all target boxes are checked: enter image description here

NFDev
  • 68
  • 8
  • 2
    Thanks for the answer, but unfortunately that's not the problem - all my classes do belong to the same target already – Quinn Apr 08 '19 at 14:40
2

Just restarting XCode worked for me.

Apologies for the trivial answer but this issue kept me busy for a while so hopefully will help someone else

Reece Kenney
  • 2,159
  • 2
  • 16
  • 53
0

There might be something wrong with your project settings. I created a framework called TestSOFramework where the SomeClass resides and TestSOFramework2 where SomeOtherClass is in and everything seems working. Can you try with a fresh projects and see if it works?

enter image description here

cekisakurek
  • 2,442
  • 2
  • 15
  • 28
  • I added some more info to the question - it was a project made with deafult xcode settings aside from a couple which I put in my update. Perhaps its something to do with that causing it. – Quinn Apr 08 '19 at 17:12
  • @Quinn Tbh. I do not want to make a static lib and test it :) – cekisakurek Apr 09 '19 at 15:39
0

In my case these errors went away after I built and ran the unit tests.

Things I also tried first:

  • Shelved all my changes
  • Cleaned the build folder
  • Restarted Xcode
alex bird
  • 104
  • 4