5

the most common answer for this question on SO is 3 years old and the commonly agreed solution (delete DerivedData) doesn't work for me so I have to re ask this question.

this is the problem i have, optically looks the same

I am trying to drag to create an outlet for my tableview.

as mentioned, deleting DerivedData does nothing for me (but I can see it reindexing). The second most common answer is

Removing(removing reference, not deleting) and then adding the appropriate file(the file of class you want to add the outlet to) is actually enough.

Edit 1 I found that after unchecking (in XCode 6.3.1) I had to wait a few seconds for the Indexing to appear and complete in the project name box. Same for the way backwards. This increased chances to fix the issue in almost all (but not all) cases.

Edit 2 Removing reference means that You do not delete the file completely but just remove it from the project (it still exist in the folder of your project, you add it later).

I dont know if this still applies to Xcode 7.3 since I work on storyboard and don't have any .h or .m files to delete or remove references to. If this advice is still valid in xcode 7.3, could you please advise where to click?

Other things I have tried that did not work

  • cleaning project
  • restarting xcode
  • in Terminal: defaults delete com.apple.dt.Xcode
  • in Terminal: defaults write com.apple.dt.XCode IDEIndexDisable 0
  • rewriting the entire project from scratch

Help a brother out?

Community
  • 1
  • 1
swyx
  • 2,378
  • 5
  • 24
  • 39
  • hi @EICaptainv2.0, the classname is indeed ViewController. i fail to see whats wrong... – swyx Jun 08 '16 at 06:23
  • I find that sometimes creating a blank line where you want to create the IBOutlet helps, or you can just create the IBOutlet manually and then in IB drag from "new referencing outlet" to your view controller object in the left hand panel (you will need to expand this panel first, from your screenshot it is currently hidden) and make the connection. The assistant view is often a bit flakey – Paulw11 Jun 08 '16 at 06:38
  • 1
    Oh, and for the sake of style, create all of your properties at the top of the class, not in the middle of some functions – Paulw11 Jun 08 '16 at 06:39
  • I just wasted my last hour trying to solve this. I couldn't. I did a git reset HEAD --hard and did my modifications all over again, started with control dragging the required outlets. For the second try it worked. – Zoltan Varadi Jun 08 '16 at 09:25
  • hi guys, Paulw11's first comment did it for me (and the second comment probably helps someone's sanity in future!) THanks so much everyone!! hope future people benefit from this as it was hours of time wasted – swyx Jun 10 '16 at 02:34

8 Answers8

11

Hi future xcode n00bs (i hate when the loop isnt closed by the asker!), please refer to @Paulw11's comment. that fixed it for me

You can just create the IBOutlet manually and then in IB drag from "new referencing outlet" to your view controller object in the left hand panel (you will need to expand this panel first, from your screenshot it is currently hidden) and make the connection. The assistant view is often a bit flakey

swyx
  • 2,378
  • 5
  • 24
  • 39
3

I've found a way to reproduce systematically this error in a simply way

  • Drag the azure line on ViewController and leave drag inside the Hint ("Insert Outlet or OutletCollection): The create connection box appear normaly

enter image description here

  • Now after click "Connect" button....BUUM! "Could not insert new outlet connection"

enter image description here

  • Finally try to do the same thing but leaving the drag outside the hint box

enter image description here

  • After click "Connect" you will discover that now all work fine!

    Hope this help!

christian mini
  • 1,662
  • 20
  • 39
1

what worked for me - delete class file (which appeared to be in a "Base project" folder)
- create a new one in the default project folder.

btw I tried deleting derived data before and it there still was the same error.

1

The simple solution for me was to create a new ViewController class and reassign that class to the storyboard. Then I was able to use the IBOutlets via click and drag as usual.

My issue seemed to be caused by attempting to rename the class. I renamed the file, in code, and reattached it in storyboard. But the IBOutlets seem to have an issue with classes being renamed.

rleedev
  • 51
  • 5
1

I tried a lot of options without good results, at the end, i opened terminal and type:

defaults delete com.apple.dt.XCode IDEIndexDisable

Then i restarted the mac, and opened Xcode again, it was working now (This even solve autocompleting issues)

Nelson
  • 233
  • 1
  • 4
  • 6
1

None of the above solutions worked for me. (deleting derived data, removing target class file and re-adding it, creating a new target class file and copy and paste the text in there, restarting xcode, restarting mac, clean, clean build folder, or in any combination that I could think of, etc.)

In the end, what did work, was adding a line to the target class (like print("dummy")) and then build the project.

I can only guess why. My guess is that none of the other solutions enforced a new compilation of the target-class file. Somehow xcode 'knows' for which classes the code changed. Adding an empty line or comment line didn't work btw. Xcode is 'smart' appearantly and know a new compilation is not required if you add a comment or empty line. It needs to be compilable code. Again... just a guess. Also have no idea why deleting derived data, clean and clean build folder didn't work.

guido
  • 2,792
  • 1
  • 21
  • 40
0

If this doesn't work to drag the connection from the storyboard or nib, you can do it from the Connections Inspector. Click and drag the '+' sign on 'New Referencing Outlet'.

Worked for me on xCode 7.3.

enter image description here

lukas_o
  • 3,776
  • 4
  • 34
  • 50
0

In my case it was another file (say HeaderCell.Swift) that I had accidentally deleted but was part of compile sources. Xcode was not showing the actual problem but was wrongly displaying "Could not insert new outlet connection" for (FooterCell.swift & FooterCell.xib). After I restored the file HeaderCell.Swift, the IBOutlet connection worked fine.

Raunak
  • 3,314
  • 1
  • 22
  • 28