When i run my program with the simulator it builds and runs with no errors. However when i change the destination to my connected iPhone, a whole bunch of swift compile errors are displayed:
Attempting to use the forward class 'UIViewController' as superclass of 'UIActivityViewController'
Attempting to use the forward class 'UIViewController' as superclass of 'UIAlertController'
a bunch of those, and then
Cannot define category for undefined class 'UIViewController' UINavigationController.h
and a bunch of these as well ...
I'm very new to Xcode and can't figure these errors out ...
Possibly your compiling towards different iOS versions on the device and the simulator. This may cause the compiler compiling towards different Swift versions.
I had the same problem. Solved it by cleaning the derived data.
Delete your DerivedData folder in ~/Library/Developer/Xcode/DerivedData.
But would also Clean the project and Reset Content and Settings.
Related
Shortly after updating to Xcode 13.2.1 I started seeing some weird behaviour of breakpoints. When I run an app (in a simulator) some of my breakpoints change their look and turn to dotted blue outlined. Xcode does not stop execution at these breakpoints although code has been compiled, loaded and executed. I checked it in Console by adding some prints.
When I hover over breakpoint Xcode shows a message:
Xcode won't pause at this breakpoint because it has not been resolved
Resolving it requires that:
The line at the breakpoint is compiled.
The compiler generates debug information that is not stripped out (check the Build Settings).
The library for the breakpoint is loaded.
All trivial solutions like reloading, reapplying breakpoints have not helped.
Did anybody else see something like this? Is there a way to solve it?
Screenshot for reference:
Ok, so in my particular case rebooting laptop has helped. All breakpoints are now good. But it would still be nice to know the cause of the problem.
Make sure that the file in which you are adding breakpoint is having correct target set in target membership.
Click on .m file in which you want to add breakpoint.
Select the file inspector.
Check if you have selected correct target for that file or not (check below image).
What worked for me, was to select the files, delete them with - Delete>Move To Trash - and then drag the files back from the trash to the project.
In my case the issue was happening, because class was not added to the target, which I was trying to build.
For my case somehow the code path was never invoked and very likely considered as dead code. The same thing applies when not adding the file to the target that you want to debug.
This can be the case or somehow debugger might not be able to resolve your breakpoint. The first thing in this case should be cleaning derived data and any caches.
But instead of recloning your repo you can just delete breakpoint config from the location described in this answer
In Xcode 14 the problem is much more prevalent and "consistent". I figured out one pattern where it always fails and how to mitigate it.
If you have a final class then breakpoints set on or inside a private method will have that issue. If you remove private from the method or final from the class the breakpoints will get resolved properly.
If tried everything and nothing worked I suggest the following:
Reclone your repo
This is what worked for me.
I just passed through this problem and the solution for me was recreating the files.
Note: The ones I was trying to originally breakpoint on were copied from another project. When I created the new files, even though their Identity and Type looked just the same (target membership, encoding, paths), for some reason breakpoints started to work again.
Note 2: When copying and pasting code to your new files (if done manually), migrated breakpoints - created in the older file - will continue to fail. Only the ones created in this new file will work properly.
Hope it helps.
My case
Working on framework development. Framework is injected into the sample app for development/run purpose. Breakpoints inside the framework won't work.
Fix
Just removing xcframework in sample app and replacing with framework.
Reason
xcframework are precompiled outside of the app, so lib isn't compiled when project is built and that's why breakpoints doesn't work.
For me reboot the Xcode, and it works~
we've been having problems with very slow compile time on our rather big projects. Based on this great article: https://thatthinginswift.com/debug-long-compile-times-swift/ I set my swift compiler flags to:
-Xfrontend -debug-time-function-bodies
and started debugging. What I found out was that for every file that is compiled (>200) it also compiles bunch of seemingly unrelated files with it.
After more debugging it seems that if you add to a class or struct any extension like this:
extension MasterViewController {
func someFunc(){
}
}
the class MasterViewController will be compiled with any unrelated file in your target.
In my small example project there is also DetailViewController which is pushed from the MasterViewController. Because MasterViewController has referenced it, it also have to be recompiled with it. Every time for every file.
On this small project, the compile time is still fast but you can see how this can get really slow on big project where the extensions are used in more than few classes. On our project more than half of the source files is recompiled every time.
To test out the issue download the CompilerTest project from here https://1drv.ms/u/s!Av6oIon-UawdxmUtmDCNWF_zOcjn
Then build the project and go to latest build in Report navigator. After expanding the TestFile.swift you will see that MasterViewController was also compiled even though its not referenced at all in the file.
Then comment out the extension in MasterViewController.swift, clean the project and build folder. Then build again. You will see that the TestFile is now compiled as it should.
My question is whether there is a reason for this behaviour or if it is a bug that should be reported.
i am using xcode 4.4.1 for iOS target 5.1
i've started my project using ARC, and in the middle of the project I've added some non-arc thirdparty source to my project.
at this point, i've decided to try refactoring in xcode and an error occurs.
it comes from one of my original source code.
i have a property of (nonatomic, weak) and i've synthesized it ==> synthesize of 'weak' property is only allowed in ARC or GC mode.
I am puzzeled - i am using arc and it complains that it is only allowed in arc??
At the moment, i've refactored the thirdparty app from other project and copied it for my project to work, but the above is a question I'd still like to understand why .
Thanks!
(by the way, when i do convert to arc, it says that the target currently uses ARC)
It sounds like the issue is you've already set it up as an ARC project and your are for some reason trying to convert it again. I can only assume that the process doesn't expect therefore weak references at this stage. If you set them to Assign then convert to ARC you will see that it then suggests you change them to weak.
I had the same symptom using Xcode 4.6.3 targeting iOS 6.1. I brought in a non-ARC class from another project and converted it via the Refactor menu only to have subsequent builds fail on a pre-existing class with the error you saw (“synthesize of 'weak' property is only allowed in arc or gc mode”).
The project properties clearly said it was still an ARC project but the compiler seemed to have forgotten this was the case for the class in question.
I got around the issue by setting the property to 'strong' and converting that class to ARC via the Refactor menu. Unsurprisingly it told me no changes were necessary but did offer a Save button which I clicked. I was then able to change the property back to 'weak' and compile the project. (I'm presuming some metadata got out of synch somewhere along the way.)
EDIT: I eventually had to 'Refactor' other ARC-compliant classes to ARC as although they compiled they generated warnings and caused crashes in my app. I think the moral of the story is that including your whole project in the refactoring might be safer...
instead use:
#property(nonatomic,assign)
*note - This is not the same as weak, but very similar. Weak also sets the object to nil, assign does not.
I've upgraded my IOS4.3 app to IOS5 and am getting compile errors. From what I can tell, the syntax looks fine, but the compiler is complaining of "Unexpected #" when I synthesize properties, but only in some classes.
I also have an "Undeclared identifier" in one ViewController's viewDidLoad method.
I've performed a clean build and I'm guessing that there's a default setting which has been changed somewhere, but from scouring around this doesn't seem to be a common issue. Is there a list of common breaking changes anywhere?
EDIT:
This screenshot is one of my ViewControllers, which is derived from UITableViewController
There is a missing # in the line self.title = NSLocalizedString(...). The second parameter doesn't have the leading #.
Coming from a .NET/PHP background, I have very little experience with compilers. The problem was that Apple seem to have changes the default compiler for IOS5 from GCC to LLVM, hence the difference in syntax. It would be nice to be able to use the newer compiler, but GCC's the only one which gets anywhere near close.
I've suddenly got a very weird error in Xcode 4.1 that seems to have occurred after Xcode crashed.
I have some Model classes that inherit from a simple base class. Nothing unusual there.
What's happening now is that when I attempt to build for the "device" for one of these model classes that inherit (and only one) it throws a bunch of compile errors saying blah blah undeclared etc. Now if I switch it back to the simulator it builds and runs fine.
This was working perfectly well before the crash. I've done all of the usual clean build, delete derived data, restart XCode etc but still I can't make it work.
If I explicitly add the various bits from the base class into this problematic class it all works fine again.
I'm really perplexed. Any suggestions?
Thanks in advance,
Matt
You should try a "Product->Clean" and then recompile.
Sometimes Xcode doesn't seem to recognize changes made to files and gives weird errors and warnings.
Hope this helps.
If MrHus' clean doesn't work, Control-Click on your .xcodeproj and select Show Package Contents (Xcode projects are bundles). Remove everything but the project.pbxproj files; they may be corrupt.
If that doesn't work, try creating a whole new project from scratch. If that works, then your project.pbxproj was corrupt.