I recently organized the project folder for my Mac app, which contains over 40 custom classes. I organized these classes by putting them in folders.
After making Xcode aware of the new file locations, I ran my app. The following was logged...
Unknown Window class TSDirectoryWindow in Interface Builder file,
creating generic Window instead
I went into the compile sources, removed every file, then added them back (thinking maybe the compiler was still looking at the old locations). No luck.
I'm semi-new to Mac/Objective-C development, and I'm starting to think organizing my files was a bad idea. For all I know, this could be a big no-no. It appears to be a issue with every nib, as I get the same message when MainMenu is the main interface,
Unknown class 'TSAppDelegate', using 'NSObject' instead. Encountered in Interface Builder file at path
/Users/tsilva/Library/Developer/Xcode/DerivedData/Podsnatcher-dlctvrrkdaksfdbblvopdarwlslr/Build/Products/Debug/Podsnatcher.app/Contents/Resources/en.lproj/MainMenu.nib.
Any ideas on how I can get this fixed? Thank you for your time!
I was adding the files to the linker for the "MyAppTests" target, not the application itself. Whoops.
Related
I want to make my project more organized, so I created new groups and dragged files into those groups. I am doing all of this in Xcode, not finder or terminal. However, now, Xcode shows "Cannot find 'FileName' in Scope" errors next to references to classes in those files.
How do I solve this problem?
I tried building the project and cleaning the build folder.
I ran into the same issue today with Xcode 12.2 and an iOS 14.2 project. I created a file for a new struct, wrote some code in ViewController that created instances of the struct, and then for housecleaning I moved the struct's .swift file. At that point I saw the error "Cannot find [type] in scope."
Product | Clean Build Folder didn't do the trick.
Closing and reopening Xcode worked for me.
I'm not sure if the initial clean helped or not.
There are more detailed answers here, and your particular case may be covered:
SwiftUI 2.0 CoreData issues with new project - 'Cannot find type 'Item' in scope'
I fixed a similar issue today using Xcode 12.3 (12C33):
Solution
Removed the impacted files from Xcode (without trashing them)
Tried adding the files back with the create folder references option selected
Found that this action generated Cannot find 'type' in scope error
Resolved the error by removing the files references and select the create groups option when copying the files back into the project.
BTW - I found these methods work while using either the Add Files option or dragging the files/folders into the project.
I found some "hack" to fix it.
Lets say you wanna move folder Models to your project. Open AppCode and create Model group using IDE tools. Then open XCode, select Model folder and perform Add files to "Model" action. It worked out in my case.
From my understanding, the problem is with forlders, not with files.
When I create a new OS X "Game" project with Sprite Kit, and set a breakpoint anywhere I can see the variable values just fine:
Then I change the code to import my own framework (TilemapKit) which is a pure Objective-C framework:
import SpriteKit
import TilemapKit
class GameScene: SKScene {
override func didMoveToView(view: SKView) {
print("dang!")
}
}
No other changes made. I'm not even using any of the TilemapKit code (yet). When the breakpoint triggers, I see this:
The entire project stops being debuggable as far as observing variable values goes. This behavior is perfectly consistent. Without the framework import I can debug again.
Since I'm on Xcode 7 beta (7A121l) and OS X 10.11 developer preview I know this could simply be a (temporary) bug.
Command line Tiles are set to use the Xcode 7.0 version btw. I tried enabling modules in the framework target, made sure the deployment target is the same (10.11), disabled symbol stripping. I added a Bridging Header and #imported the TilemapKit framework in it (removing the Swift import in that case would still give me the non-debuggable app, so it doesn't seem to matter how or where I import the framework).
Does anyone have a suggestion on what could cause this behavior and how I might go about fixing it - or at least how I could try to narrow down the issue?
Is the culprit more likely to be connected to the project's vs the framework's build settings? Do I need to enable something in the app project to make it compatible with ObjC frameworks? (I already got -ObjC in the Other Linker flags)
UPDATE:
I ran po self in the debug console and found this notice:
<built-in>:3:6: error: module 'TilemapKit' was built in directory '/TilemapKit.framework' but now resides in directory './TilemapKit.framework'
#define __clang_major__ 7
^
missing required module 'TilemapKit'
Debug info from this module will be unavailable in the debugger.
How come the framework build directory changed? And why would that matter and how to fix this?
PS: the same framework in a new ObjC app can be debugged just fine.
I got a message from an Apple developer stating that they've observed this problem, and that it could be fixed by moving the .framework to a subfolder of the project.
Apparently the module .. was built in directory error appears only if the .framework is in the same folder as the .xcodeproj aka $(PROJECT_DIR).
However moving the framework to a subfolder didn't fix the issue in my case, but it's still worth a try until this gets fixed in a newer Xcode 7 beta (still occurs in beta 3).
In my case this was happening because of redundant import statements in my project.
My project mixes swift and objc files, so I have import statements in the bridging_header.h file.
In my bridging_header.h I had #import blah.h
In one of the swift files, I was importing a redundant header from a framework
#import blah // From blah.framework
I removed the redundant import from the swift file, that seems to have fixed it.
I can confirm this is happening in Xcode Version 7.0 beta 4 (7A165t). I had to remove my ObjC framework to get Debugging values to return. If removing your framework isn't an option, the print method is old-school debugging, but still works.
I had this issue a while ago. In my case the Prefix.pch was beeing included inside the Bridging-Header.h. This is not a issue per so, but inside my Prefix.pch there was many C includes that make the lldb fail to import the Bridging-Header.
So I removed the "#import Prefix.pch" from the Bridging-Header and copied just the "#includes" to the obj-c files that I need to use in swift.
The Optimization level is not set to None for the Debug configuration.
Be sure to set it to None for Objective-C apps as shown in Figure 1 and for Swift apps as shown in Figure 2.
The Build Configuration pop-up menu is set to Release in the scheme editor's Run action settings pane.
In Xcode, open the scheme editor by choosing Product > Scheme > Edit Schemeā¦, select the Run action for your app in the scheme actions pane, then set Build Configuration to Debug as seen in Figure 3.
Go to Edit Scheme on left top corner.
And change the configurations to Debug, if it is release
To be on the safe side, and as my project is relatively small, when I wanted to change the name of a class in Swift, I changed it manually and went through the files individually - storyboard, class file, and in project navigator.
In Xcode, is there another way to do this to be sure of replacing all instances, or is manually the only way to go? Can you safely use a find and replace for this purpose?
Select the class name in the declaration, right-click/control click on it, choose "refactor" and select "rename". That will do a complete rename, including references to the class from your storyboards. It's much safer than doing it manually (assuming the Swift editor is as smart as the Objective-C editor - I'm still pretty new to Swift development, so I haven't tested this feature with Swift.)
(As of version 6.2, Xcode is only capable of doing this with Objective-C and C code.)
In an app, suddenly it's giving me the error XCode Unknown class ***** in Interface Builder file. I reviewed everything, storyboard, classes, etc.
I try to rename the class but it is the same problem, even I created a new class and copy the code in. I think XCode is taken that from a kind of cache because even properties that I deleted like the icon in the tab bar item are still present in the app when I run it.
What can be the problem?
Also if using a static library, don't forget to add the -ObjC flag to Other Linker Flags in your projects Build Settings tab.
If you have failed to do so, "Unknown class ... in Interface Builder file" will occur when trying to load a view controller from the static library in IB.
Just another case I experienced the error will show.
I faced a problem when I created a project with the same name that already existed in my projects directory (though it was deleted some time ago). Xcode didn't understood that it's a new project and use build directory of old project as a build directory for a new one. I didn't knew how to completely rebuild project from scratch and I just removed a build directory.
In my case I removed /Users/username/Library/Developer/Xcode/DerivedData/ProjectName-suffix. You can find it in Xcode in Project navigator on the left by selecting ProjectName->Products->ProjectName.app and File inspector on the right will show you a full path to file.
Sorry, after trying several post I found one solution, delete the folder of the simulator in /...Library/Application\ Support/iPhone\ Simulator/ and removing the class and re-adding it.
You will need to add to your targets Other Linker Flags as well, just adding to the Project Build Settings does not seem to work.
I just upgrade my MonoDevelop to the latest version (2.8). I also installed XCode4, since it's fully supported now. When opening my solution (which consists of several projects) I was asked to migrate my solution. I did this and saved everything.
However, I think something is missing. When I open the .xib file, the project on the right doesn't show .h files, like shown in the tutorial.
It also shows warnings that the outlets were not found in XCode.
When I add a new screen, it creates the .h file as it should and shows this in XCode. However all existing screens don't have these files, which makes it impossible to add/change outlets.
How can I fix this.
Check that your classes you expect to see in Xcode have explicit [Register("SomeName")] attributes, which register them with a name usable from Xcode/Obj-C/IB.
I would expect an imported project to have those attributes already, since they're required for xibs to be able to load the classes by name, but you could maybe have got away without those attributes by using outlets on "File's Owner".