0

When I go into xcode try to add a new class with File>New>New File and then adding an Objective C class, my header file winds up looking like this:

@interface Course : NSObject 

@end

instead of what it needs to look like

@interface Course : NSObject {
@private

}
@end

is there any reason for this, I'd really like to have it set up the way that the code snippet does (the second) by default.

chown
  • 51,908
  • 16
  • 134
  • 170
bringel
  • 482
  • 5
  • 17

2 Answers2

3

Looks like this is normal behavior for Xcode 4.2. The new runtime does not require the creation of instance variables when you use properties.

Old runtime:

@interface Foo : NSObject
{
  NSNumber *myNumber;
}
@property (nonatomic, retain) NSNumber *myNumber;
@end;

New runtime:

@interface Foo: NSObject
@property (nonatomic, retain) NSNumber *myNumber;
@end;
diederikh
  • 25,221
  • 5
  • 36
  • 49
  • This does not answer the question at all. I do not see where he is asking about instance variables or properties in his question. – chown Nov 20 '11 at 23:19
  • @chown The OP has asked if there’s a reason why the new templates do not have a `{@private}` block (for ivars). –  Nov 20 '11 at 23:36
  • @Bavarious Ohhhhhhh, I get it, you'r answering the *why* part. I read his statement: "I'd really like to have it set up the (2nd) way by default" as his main question. But, this does provide an answer for the *why* part; sorry about that =). – chown Nov 20 '11 at 23:59
  • So the Objective C runtime changed that quickly. In the books and videos i'm using everything looks different now – bringel Nov 21 '11 at 00:38
3

In the

/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/File Templates/Cocoa Touch/Objective-C class.xctemplate/NSObject

directory there are template files called ___FILEBASENAME___.m and ___FILEBASENAME___.h. What you need to do is change the ___FILEBASENAME___.h file (using something like vim, TextWrangler, etc) from this:

//
//  ___FILENAME___
//  ___PROJECTNAME___
//
//  Created by ___FULLUSERNAME___ on ___DATE___.
//  Copyright (c) ___YEAR___ ___ORGANIZATIONNAME___. All rights reserved.
//

___IMPORTHEADER_cocoaTouchSubclass___

@interface ___FILEBASENAMEASIDENTIFIER___ : ___VARIABLE_cocoaTouchSubclass___

@end

To this:

//
//  ___FILENAME___
//  ___PROJECTNAME___
//
//  Created by ___FULLUSERNAME___ on ___DATE___.
//  Copyright (c) ___YEAR___ ___ORGANIZATIONNAME___. All rights reserved.
//

___IMPORTHEADER_cocoaTouchSubclass___

@interface ___FILEBASENAMEASIDENTIFIER___ : ___VARIABLE_cocoaTouchSubclass___ {
@private

}
@end

Poke around in /Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/File Templates/ and /Developer/Library/Xcode/Templates/File Templates to see more templates you can customize.

Or use this python script I wrote to customize them all automatically (after tweaking the python script to fit your customization needs):
http://blog.hozbox.com/2011/11/20/easy-xcode-template-customization/

chown
  • 51,908
  • 16
  • 134
  • 170