Could not insert new action connection Error - iphone

I get this error, when try to create new action for UIButton by dragging blue arrow from UIButton to my header file (you know, this new feature of XCode 4...)
When I create action in code by myself and connect it in old way, simply by dragging from button to File's Owner, it's works well
Here's screenshot:

Make sure your .m file exists in the project and on disk. Make sure it is correct with an #implementaiton-#end block. Open it in Xcode, close it, if the error persist, restart Xcode.
Xcode is trying to write to EditPUViewController.m (in the dealloc method etc.) but could not find it.
Also, it always helps to hard-clean the project with ⌘+⌥+⇧+K.

Try this:
Open Organizer then Project Tab.
Clear the "Derived Data". Xcode should re-index your project then and code sense should work. At least worked for me.

I had a comparable problem when trying to connect an action. To solve it I manually added the IBAction and then XCode allowed me to connect from the button to the code.

Go to Xcode -> preferences -> location tab -> derived data -> clear derived dat.

I ran into this issue myself but none of the methods presented here worked for me. The error described in the question above occurred when I tried to create an IBAction in my view's header file (.h), whereas to my implementation file (.m) I couldn't even drag a line. (Xcode wouldn't even show this little popup where you can name your action.)
After trying for hours I figured that the reason why I couldn't create the IBAction was because I had removed the very last line from my .m file. Xcode automatically adds an extra empty line after the #end delimiter when you create a new Objective-C file.
Don't ask me why - but if you remove that line Xcode doesn't let you create any actions or outlets. (This is obviously an Xcode bug.)

I noticed that .m file was moved inside en.lproj folder.
Just delete (reference only) the .m file from the Xcode and moved .m out of the en.lproj. Add it again.Don't worry, you will get all your connections back.
It will fix the issue.

I recently came across this problem. I soon realized that the cause had been my own doing.
I had previously disabled XCode indexing (which used to take forever & eat up my RAM), using the below code in a terminal window:
defaults write com.apple.dt.XCode IDEIndexDisable 1
To revert XCode to its default state, i used the following line in a terminal window:
defaults write com.apple.dt.XCode IDEIndexDisable 0
Voila! All's well again..

I got the same error. Restarting Xcode did not fix it for me (I didn't want to reboot). The file was also not in the en.lproj folder (nor in the usual project folder after I deleted it from within Xcode). The fix for me was to re-create the file with a different name (Using different case in the filename alone was not enough to fix it... must be a different name entirely).

I ran into this problem when I created a class, deleted it and then created a new one with the same name. The workaround was not to reuse the name of the deleted class, but use a new one. Thus, I'd say it's a bug on the XCode side.

Remove the newly created class (don’t delete it, just remove link and then re-add it);
Save Xib file;
Restart Xcode;
You may want to delete Derived Data as well if it does still not work.
This seems because of XCode is missing reference or need to refresh manually.

In my case, removing the reference of the nib(.xib) and adding it again solved the problem.

In my case I had by accident selected the arm64 build. When compiling I got an error but I did not notice that since I was working with the UI trying to connect an action.
The error however was exactly the same. After changing to another architecture so the project compiled I could connect the action by holding the ctrl button as usual.

user2175983 and AstroCB answer's worked well for me:
Just delete all Derived data by running this command line in a terminal:
rm -frd ~/Library/Developer/Xcode/DerivedData/*
Restart Xcode

I just deleted the reference to the file in the Xcode project and then re-added the file back to project from the finder...

In Xcode 9 I had the same error after moving .m files in project from one directory to another. Deleting references to .m files and add them again did solve the issue.

I found the ANSWER. When you create a new file (Objective C files) for each view controller, you must check by clicking the box, next to your project name. So that your project includes this file. Otherwise, this error will persist, because your project hasn't connected to the file even though it created it.

Related

Delete by mistake the storyboard

I delete the storyboard by mistake from my app.
Where I can find it and restore it,
or I lost it?
The default storyboard filename is Main.storyboard, so that's what you should look for unless you gave it a different name. (Older versions named it MainStoryboard.storyboard, so if you are working on an older project, you might need to look for that instead.)
First, check your project folder (using the Finder). If it's there, you can drag it back into your project in Xcode, or you can use the “Add Files to …” menu option.
If it's not there, check the trash can. If it's there, you can right-click it and choose “Put Back”, then follow the steps in the previous paragraph.
Try running again your app and Xcode will create the file automatically, this worked for me.

Unknown class FirstViewController in Interface Builder file

When I run my application i got this
I see in my console this message "Unknown class FirstViewController in Interface Builder file."
I am running TabBar application.
How can I fix this?
It looks like you deleted FirstViewController.h & .m from project, but forgot to change view controller's class in nib file.
Go to project , targets , build phases , compile Sources and add the unknown class ..done.
Right click on Storyboard --> Open As --> Source Code
Find your unknown class name in the storyboard source file. It may be because you have accidentally assigned a custom class name for one of your UIView subclass'.
It is kinda hard to understand your comments, but I think you may have deleted the FirstViewController but forgot to change all the references to it. you may need to go to MainWindow.xib and look for all FirstViewController UI components and delete them
Sometimes it happens when you change target name for some reason, you have then to open storyboard as source file, then search for old target name, replace it with the new name, should work if it is the case, hope it helps.
This can also happen if you use the same package name for multiple projects (if you're being lazy with your provisioning). Go into your user directory, then go to Library/Application Support/iPhone Simulator/[your sdk version]/Applications and delete what's in there. You may also have to delete the app from the device. That will remove any accidental references to files from other projects, which can cause this error.
When you add multi project to Workspace. If you use the same Product Name in your's projects. It can conflict.
Rename Product Name in the projects have a same name.
... Hope this help ....
This happened to me just after Git merge and resolving few conflicts.
It had screwed up my XCode project.
I tried all over the StackOverflow. At first I thought my Custom class .m file hasn't been added to the Compile Sources class list. But it's one case, however even after adding it, it gave me same issue back.
How I resolved:
I kept a backup of my .xib file and its backing custom class .m and .h files.
Then clean the project and try to run the app via XCode (which might not work)
Then re-add the files back to the XCode project and it will work.
Cheers!
This can sometimes happen if you made changes to a VC i.e. deleted prototype cell(s) within a tableview.
If all else fails I find cleaning project and restarting Xcode gets things back on track.

XCode uses an .xib not inside the project folder

I went back to an old project and recompiled it for OS 4.1 succesfully and ran it. I was asked to add a fourth tab to the Tab Bar, but I could not set its class to the newly added ModelsVC.h/.m. [edit: because it did not appear in the class dropdown, but the other viewcontrollers were there.]
I moved the project folder to a backup folder and unzipped a months old backup of the same project. It compiles and runs until the end of viewWillAppear for the first (default) view connected to the first tab, and then does nothing more. It is still running, but nothing is shown and nothing happens.
In the console, it says "Unknown class ModelsVC in Interface Builder file."
The problem is, that class didn't exist two months ago, so why should this way old project complain about it or even know about it?
I'd like to know where to look / tell XCode to use the .xib that is inside the project folder it is currently compiling.
And if it's path-related, how do I check what paths XCode looks in when a project is loaded/compiled?
For Xcode to run a .xib file inside the project folder, You can just open your xcode, add existing file and it is there.
I think the problem why the old project still runs is that it builds incrementally. That means when it builds the first time, the .xib file was there, and when it build the second time, it doesn't need to add and build the .xib file any more. So, in the second build, even if you delete and move out the .xib file, I think it still can build
Seems a 'sloppy copy' for whatever reason (such as a quick backup to try something experimental) of a project folder causes confusion. See this.

Xcode's Refactor menu is always disabled

For some reason Xcode's Refactor is always disabled. I used to be able to activate it via selecting a class name and right clicking in the editor to select it. But now no matter what I do, it remains disabled. Any idea what's going on?
Working with Xcode 5, I kept getting "Can't refactor during indexing" when trying to refactor. Rebuilding the index seemed to hang at "Indexing - Waiting for make" forever.
I then noticed that make was already used by another process on my machine (not by Xcode). Shutting this process down enabled Xcode to finally finish indexing
Your project's index might be out of date/corrupt. In the General tab of the Project Settings window, click Rebuild Code Index and wait until it's done.
You can check the progress of the rebuild in the Activity window (Window > Activity).
I just ran into a similar problem in Xcode. I could not refactor anything in the class's .m (implementation file). The only explanation I could come up with is that it was not indexing the file for some reason, and I could not force it to reindex. The only hack that I found that worked was to copy the file to temporary location, remove it from my Xcode project, copy the file from the temp location back to my project's location, and then re-add the file via Xcode.
None of these suggestions work for Xcode 3.2 - the ONLY way is to select the file you want to rename in the left Groups & Files column. THEN highlight the name of the .m or .h in the right code view, then you can right click and select Refactor!
For instance if you're changing the DetailViewController name, highlight the actual DetailViewController.h word in code.
Note, you should also always make sure you've selected the .h file, not the .m
I faced the same thing in Xcode 11. and this worked for me:
I changed iPhone 8 simulator to generic iOS Device and it worked when it is on Generic
I'm new in iOS development,I have met this similar problem.
Xcode:Version 7.1 (7B91b),it looks like Refactor not working:
But when I put my mouse on the red circle point in the following picture,and then the Refactor working.
I think this is a low level mistake,but may be a reference for someone.

Rename a class in Xcode: Refactor... is grayed out (disabled). Why?

Why is Refactor... grayed out (disabled) in Xcode?
I'd like to rename a class.
Select the class's symbol in its header file - i.e. the bit just after #interface. Then the refactoring stuff should be enabled.
If you are using Objective-C++ (i.e. mix Objective-C with C++ code) then refactoring is disabled in xcode since it does not support refactoring of C++ code.
Refactor might also be disabled if affected files (most likely the file with your class in it) are not saved.
I've been using Xcode for 5 years now, and refactoring has never worked correctly (even xcode 4.6 has major bugs where it WILL corrupt your source code!).
The workaround has always been (still works 100%, even in cases where Apple's code fails)
use shift-command-f to find all uses of the file
select "replace" in the search settings
"replace-all"
do the following for the .h file, and REPEAT IT FOR THE .m FILE (if you have one):
right click the original file, and select "show in finder"
delete the file from xcode (select "delete references only" when asked)
rename the .h (and .m if you have one) in Finder
in Xcode, select "Product -> (hold down Alt) -> Clean Build Folder"
quit xcode (you can usually get away with not doing this - but NOTE: there are some other MAJOR bugs in Xcode where it crashes itself if you don't do this)
re-open xcode
drag/drop the .h and .m back into Xcode
wait a few seconds (some of Xcode's core methods are asynchronous - allowing it to corrupt your project)
finally, when it seems to be doing nothing (and your hard disk isn't making any noise any more): cmd-b to re-build
I have a 100% success rate with this method. I just tried refactoring with Apple's "Refactor -> Rename" in latest xcode and it failed - again!
(this time with the incorrect error: "Unable to determine the language of", one of those error messages where Apple put the wrong text in place)
I'm going to my project at finder, then change files name by get info.
After that, at xcode -> Project Navigator I delete the files.
At end, I click right on the class and Add files to ..., and add these files again.
It worked for me.
For me I realized Refactor was disabled because the Xcode project I had opened was referencing a Base SDK that was missing. Edit Project Settings and in the Build tab set the Base SDK to one that you have (like for me this was iOS 4.2). This enabled Refactor for me.
Also, it could happen that you renamed the filename for the class, either outside xcode or by ctrl-clicking the filename and then renaming it.
xcode refuses to refactor if filename does not match with the class name.
Go to your class' header file and find the line that looks similar to this:
#interface YourClassName
Right click on the class symbol (e.g. YourClassName) and you should be able to select Refactor -> Rename...
I just tried this and it works in Xcode 5.
This may be a bit late, but I stumbled across this post because I was unable to refactor my "ViewController.swift" file to "WhateverViewController.swift". I tried selecting the file in the Project Navigator and then selecting "Editor -> Refactor" from the top menu, but 'rename' is always greyed out.
Instead, what worked was selecting the ViewController name from the editor. So if you have:
class ViewController: UIViewController {
// Code here...
}
Highlight the "ViewController" word and then select Refactor from the menu or right-click and select Refactor -> rename.
Hopefully that helps...
Had this problem as well. I ran through trying to find missing SDKs, saving files, and looking for Objective-C++ code as mentioned above, and all it took to fix my machine was rebooting XCode.
Seems a little buggy still.
BTW, this was for XCode 4.0.1
Refactoring works If you first change the file name in the project navigator.