Xcode“使用未声明的类型'SomeClass'”错误,但构建成功

Qui*_*inn 9 xcode ios swift

我已经看到过像在这里这里一样几次问过这个问题,但是我所查找的所有问题似乎已经过时或答案与我所遇到的问题不符。

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
    }
    ...
Run Code Online (Sandbox Code Playgroud)

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")
    }

    ...
Run Code Online (Sandbox Code Playgroud)

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!

小智 3

我相信这是因为你们的班级不属于同一目标。这过去对我有用,我希望对你也有用。

选择文件 > 打开文件检查器 > 确保选中所有目标框: 在此输入图像描述

  • 感谢您的回答,但不幸的是这不是问题 - 我所有的课程都已经属于同一个目标 (2认同)