---
**Deprecated, this code should not be used any more! Better use Xcode 4 with ARC!**
---
FULL XCODE4 COMPATIBILITY*
Xcode4 Demo on YouTube youtube.com/watch?v=Mzfv-ANydW4.
XCode3 Demo on mov.io mov.io/fE.
A tool for making annoying every day tasks for Objective-C developers, especially
iPhone developers, easier. Therefore this tool will help you writing semi-automatically
the @property
and @synthesize
stuff. It also updates the dealloc
method to release
your objects. And you can define the attributes according to the
Google Objective-C Styleguide
using a trailing underscore, i.e. your public attribute is then defined
without this underscore. But also a leading underscore is ok. Public method can easily be defined by
prepending XPUBLIC in the implementation part.
No more redundancies and nonsense typing orgies! You'll save a lot of time!
You have to define some helpers in your code that will indicate your properties
(you can alternatively use xobjc.h
from this package):
#define XRETAIN
#define XIBOUTLET
#define XASSIGN
#define XCOPY
#define XPROPERTY(...)
#define XNIL nil
#define XPUBLIC
In your header file mark you properties like this:
#import <UIKit/UIKit.h>
#import "xobjc.h"
@interface DemoViewController : UIViewController {
XIBOUTLET UILabel *header_;
XIBOUTLET UITextView *message_;
XASSIGN id delegate_;
XASSIGN int counter;
XRETAIN NSArray *listOfUsers_;
XCOPY NSString *secretKey_;
XPROPERTY(readonly) BOOL isPublic_;
int age;
}
@end
In your module file you can mark public methods like this:
XPUBLIC
- (void)somePubMethod { /* ... */ }
(IBAction, class initializers and class methods are always considered public)
$ python xobjc.py sample.h
After that your .h
and .m
files are updated. XCode should reload your code in the editor
automatically. The command also creates a new subfolder which contains a backup of your
original code, hope you never will need it ;)
Some pictures say more than thousand words. Here is a before/after diff showing the magic:
Edit your projects 'Scheme' and add a new 'Run Script Action' to your 'Build / Pre-actions'. Fill in the full path of your xobjc4.py. Now each time you build your project this script will be run. This is super handy.
If Growl is installed it will also issue a notification.
In Xcode in the menu choose the script symbol and there Edit User Scripts
. Create a new
entry and copy and paste the contents of the file xobjc.py
into the text field. That's all,
you are done. Just call the script form the menu or via the key shortcut you defined while you
are in the header or implementation file you like to become updated.
Macro extensions for XCode
Similar approaches and discussions
- http://cocoawithlove.com/2008/12/instance-variable-to-synthesized.html
- http://allancraig.net/blog/?p=315
- http://github.com/wookay/da/blob/b1190cd83df5700b0b6035eef2959c7968bde488/ruby/xcode/property_automation.rb
- With Snow Leopard MacOS X 10.6 the 'osascript' helper, which is used for XCode integration, threw some errors. I used a workaround I found here to circumvent the problem: http://kb2.adobe.com/cps/516/cpsid_51615.html If you are using non Intel architecture or other OS you might need to modify this portion of code in xobjc.py
Copyright (c) 2011 Dirk Holtwick
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.