1

From what I can tell there are some challenges people are having in XCode6 in terms of wiring up outlet collections. I just wanted to see if i'm doing this right or what I need to do correctly! I reviewed here Can't hook up an outlet collection in Xcode 6 using storyboard as well as other areas, but I wanted to be more basic about this first.

I have 7 images on a screen. I'd like to iterate through all of them in a loop or something. I read an outlet collection would be a sensible way to do this. To create an outlet collection, I am doing this:

  1. While splitting the screen (storyboard on left, assistant editor on right) I control+click on one of my 7 images, and drag it into the view controller code on the right. This will prompt me to create an outlet, or outlet collection (I select outlet collection).
  2. Now that this is done, a circle appears in the left margin next to this variable indicating that the image is associated with that variable. If I hover over the circle, the first image lights up.
  3. What you're supposed to do (can someone confirm this please??) is you just hover your mouse over the circle, and a + symbol appears, and all you do is hold down the left mouse button, and drag over to another image (for example image#2), and it should automatically add that to the collection. The idea is to simply drag to each image so they are all added.

Is that right in step #3 above? Is this the normal way you would add items to a collection? Drag from the + to the image within your controller? For me, when I do this, the line appears, but it doesn't seem to respond to connecting the line to anything. I just hover it over the images, and it doesn't highlight the image or select it or anything, and when I let go, nothing happens.

I'm still somewhat new to this - what am I doing wrong?

Thanks so much for your patience/help!

Community
  • 1
  • 1
NullHypothesis
  • 4,286
  • 6
  • 37
  • 79

3 Answers3

0

There is an error with Xcode and Interface Builder that causes problems with outlet collections. You are doing it right, Xcode is problematic.

A workaround is to:

  • Go to your DerivedData folder (Xcode preferences -> locations)
  • Clean build folder from the Product menu while holding option (alt) button
  • Quit Xcode
  • Delete the folder starting with your app's name in the derived data folder
  • Go to your xcodeproj file, right click it, show package contents.
  • Delete the xcuserdata folder (warning: don't touch the others!)
  • Open Xcode again.

When you delete user data, window positions etc. will be reset to defaults and breakpoints will be deleted. Your project should work smoother (after a few seconds of re-indexing) and outlet collections should work properly.

Can Poyrazoğlu
  • 33,241
  • 48
  • 191
  • 389
  • uffa. ok thanks for confirming. Is there another approach? I was just thinking for now (since there are only 7 images) just add each one manually in viewdidload and iterate that way. – NullHypothesis Aug 02 '14 at 16:33
  • Well, there are different approaches, but creating an IBOutletCollection is exactly the way to go for this. – Can Poyrazoğlu Aug 02 '14 at 17:12
0

I have had some success by just changing my workflow as follows (no need to restart Xcode).

  • First, create the outlets in code in the controller class file.
  • Second, drag from the objects (in the outline view of IB) to the controller, or back (for actions).

This has always worked without fail. It is slightly more effort, but actually negligible. Definitely an Xcode bug.

Mundi
  • 79,884
  • 17
  • 117
  • 140
0

OK I had the same issue and I think I have just found a workaround


1) Do steps one and 2 with the first image

2) Now repeat exactly what you did using the second image - drag and drop just below the first outlet collection (this would simply create a second outlet collection use exactly the same name )

3) Now Xcode won't like it as you have two outletCollections with the same name. Now comment out the first one

4) Now you only have one outlet collection. And it would be wired up to both your images. confirm it by hovering your mouse pointer over the little 'circle' next to the IBOutlet to see your images being highlighted.

This seems to work for me. So hope this helps :-)

coffeecoder
  • 514
  • 7
  • 7