5

I created an Xcode 4.5.2 project starting with the Single View Application for iPhone template. After adding a UIButton to MainStoryboard.storyboard, I'm able to control-drag from the button to ViewController.h's code to create a new IBOutlet or IBAction. with extra line

However, if I remove the last line following @end, which is empty, control-dragging does not offer to create an IBOutlet or IBAction. without extra line

If I add a property to ViewController, then control-dragging offers to create IBOutlets and IBActions again. existing property

Edit 1: As jhilgert00 pointed out, adding curly braces, as if to create a place to declare instance variables, causes Xcode to once again offer to create IBOutlets and IBActions.

Is this an Xcode bug? Or should I not trim the empty line after @end?

Edit 2: This issue has been fixed in Xcode 5.

Community
  • 1
  • 1
John Sauer
  • 4,411
  • 1
  • 25
  • 33
  • I had no idea one could do this at all; I have always created my `IBOutlet`s in the interface file first. – Extra Savoir-Faire Jan 07 '13 at 22:20
  • thats a cool feature did not know that either. looks definitely like a bug to me. its perfectly valid to have no empty line at the end of the file. – mgr Jan 07 '13 at 22:26
  • Got the same problem. Most be a bug because I am able to reproduce it at will just by deleting and inserting that empty last line. – Entalpi May 23 '14 at 15:20

3 Answers3

6

My answer would be that this is a bug that should be filed at https://bugreport.apple.com, I doubt anyone here can give a useful answer. That said it's always a good idea to leave whitespace at the end of a file!

rpowell
  • 1,464
  • 2
  • 16
  • 29
  • Thanks. I'm glad to get confirmation that the problem isn't localized to me, and I hope others find this question if they Google the problem before Apple can fix it. I'll submit a bug report to Apple shortly. – John Sauer Jan 08 '13 at 01:35
  • Why would you recommend leaving whitespace at the end of a file? – John Sauer Jan 08 '13 at 01:35
  • There's a good discussion about it [here](http://stackoverflow.com/questions/729692/why-should-files-end-with-a-newline). Long story short: some programs have problems parsing files without a newline as the last character, not to mention the C standard dictates that should be the case. – rpowell Jan 08 '13 at 01:53
4

It seems stupid, but opening and closing your curly braces for your @interface seems to fix this issue.

#import <UIKit/UIKit.h>

@interface ViewController : View Controller {

// Drag your IBOutlets here...

}

@end

Screenshot on this answer.

Community
  • 1
  • 1
jhilgert00
  • 5,479
  • 2
  • 38
  • 54
  • True. Adding curly brackets, as if to create a place to declare instance variables, causes Xcode to once again offer to create IBOutlets and IBActions. However, my question is not "how can I fix this?", but "should Xcode be doing this in the first place?". Others seem to agree that it's an Xcode bug, so I'll likely submit it to Apple soon. – John Sauer Jan 08 '13 at 00:43
0

Just FYI, this happened to me because I had not changed my ViewController from generic one to the one I was trying to drag to, which makes sense.