Accessing classes from parent groups - not allowed??

As far as I understand it, "Groups" in Xcode are simply a way to organize your project's files.

However, I have found that classes in groups can't access the classes that aren't in the same group or children of that group. This makes no sense to me.

Example:

Group A

-ClassA

Group B

-ClassB

I want to declare: class ClassA: ClassB but I get the error "Cannot find type 'ClassB' in scope"

However, if I move ClassB into Group A, it works. Is this a bug?

Answered by Gilllissie in 701972022

I have figured this out. What's not obvious is that this project has a Watch Extension target. I am sharing many of the classes between the main iPhone target and the watch target, which requires checking the box for the watch target when the class is under the phone project structure. I had forgotten to check the box for the watch to have access to the new class BleMessenger.swift.

It would be extremely helpful if the error message was more specific, but I guess it's just something to remember.

I tried to reproduce and did not get the error.

Unless I misunderstand your case.

Could you show a screenshot of the folders structure in Project navigator ? And show the exact code.

Are you sure classB is not defined inside another class ?

Ok, my example wasn't exactly my use case. I'll revise...

Group A

-ClassA

-Group B (is inside of Group A)

--ClassB

ClassB cannot see ClassA.

(edit: This works in a new project, so I guess I'll have to get screenshots from my actual project.)

When I put the class file "BleMessenger.swift" into the "Data" group, the classes in the "Gadgets" group can't see it. If I move the "BleMessenger.swift" file into the Gadgets group, suddenly the classes in the "Gadgets" group see it. As shown, the BleMessenger class is currently empty. Here are screenshots of the issue:

I tried to simulate the same, could not replicate.

Did you do a clean Build Folder ? May be you need some cache cleaning for the compiler.

Accepted Answer

I have figured this out. What's not obvious is that this project has a Watch Extension target. I am sharing many of the classes between the main iPhone target and the watch target, which requires checking the box for the watch target when the class is under the phone project structure. I had forgotten to check the box for the watch to have access to the new class BleMessenger.swift.

It would be extremely helpful if the error message was more specific, but I guess it's just something to remember.

Could you check also both files Target membership when it does not work ?

Accessing classes from parent groups - not allowed??
 
 
Q