GithubHelp home page GithubHelp logo

holtwick / xobjc Goto Github PK

View Code? Open in Web Editor NEW
74.0 5.0 3.0 1.17 MB

XCode automated property and method code generator for smart Objective-C developers who want to save time and reduce typing errors

Home Page: http://github.com/holtwick/xobjc

License: MIT License

C 0.71% Objective-C 5.34% Python 93.94%

xobjc's Introduction

Error in user YAML: (<unknown>): did not find expected alphabetic or numeric character while scanning an alias at line 1 column 1
---

**Deprecated, this code should not be used any more! Better use Xcode 4 with ARC!**

---

xobjc

Flattr this git repo

FULL XCODE4 COMPATIBILITY*

Xcode4 Demo on YouTube youtube.com/watch?v=Mzfv-ANydW4.

XCode3 Demo on mov.io mov.io/fE.

<iframe src='http://mov.io/go/showvideo/player/fE?autoplay=false' width='430' height='391' scrolling='no' frameborder='0'></iframe>

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!

Preparations

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 

Your code

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)

Usage

$ 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 ;)

Example

Some pictures say more than thousand words. Here is a before/after diff showing the magic:

Header

Module

XCode4 Integration

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.

Header

If Growl is installed it will also issue a notification.

XCode3 Integration

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.

Related

Macro extensions for XCode

Similar approaches and discussions

Known Bugs and Problems

  • 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

License (MIT License)

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.

xobjc's People

Contributors

holtwick avatar

Stargazers

 avatar Xie Wu avatar Angus H. avatar Rui Ribeiro avatar  avatar Cemal YILMAZ avatar y109 avatar Chris Slott avatar 好大 avatar  avatar Sumeru Chatterjee avatar Jeffrey Macko avatar Andreas Schubert avatar Boris Charpentier avatar  avatar Mingming Wang avatar Cody Logan avatar Tomek Kuźma avatar Jake Rocheleau avatar Lucien Doellinger avatar Stan Serebryakov avatar Thibaut LE LEVIER avatar Hans Magnus Inderberg avatar Keith Moon avatar  avatar Greg Combs avatar Måns Severin avatar Heiko Dreyer avatar  avatar  avatar Luke Rhodes avatar John Yanarella avatar Arseniy Ivanov avatar Vincent Esche avatar Alexander Repty avatar Vijay Santhanam avatar Florian Bürger avatar Wil Cho avatar Dave DeLong avatar Chris Miles avatar Dan Messing avatar Edward Rudd avatar Alec Perkins avatar  avatar Imran Raheem avatar Fabio Balancin avatar Sergey Zenchenko avatar  avatar yohei sugigami avatar Peter Steinberger avatar Jean Regisser avatar  avatar jk avatar Andrew avatar Gustaf Lindqvist avatar  avatar Mathieu Ravaux avatar Christian Greppmeier avatar Bernd Folberth avatar Steven Fusco avatar João Prado Maia avatar Aron Cedercrantz avatar Dave Spector avatar Bob Larrick avatar Mike Cohen avatar Anh Do avatar Willi Wu avatar Johannes Fahrenkrug avatar Torsten Curdt avatar  avatar Mark Glossop avatar Joachim Fornallaz avatar Ding Yi avatar d11n avatar

Watchers

 avatar James Nguyen avatar Corintho Assunção avatar  avatar  avatar

xobjc's Issues

xobjc interferes with ivars that have IBOutlet set, but no XIBOutlet or other markers

... and thus breaks perfectly valid code that just doesn't use xobjc.

@interface ListenerViewController : UIViewController {
IBOutlet UILabel *currentPitchLabel;
IBOutlet UIButton *listenButton;

BOOL isListening;

}

-> xobjc created:

@Property (xobjc nonatomic, retain) UIButton *listenButton;
@Property (xobjc nonatomic, retain) UILabel *currentPitchLabel;

and happily deleted all other properties that were there.

Change Readme to use relative path in Xcode4 integration

... so that it's compatible with multiple people working on the same project.

It's important to select the target in "Provide build settings from", and then a call like

${SRCROOT}/../xobjc/xobjc4.py

will do the trick. (exact path depends on project path structure)

nonatomic per default?

In the Xcode4 version, all my properties miss the "nonatomic" declaration, and if i add it manually via the XPROPERTY flag, the XASSIGN/XRETAIN is no longer honored. (nonatomic should be default, and

XRETAIN XPROPERTY(atomic) UIView *var

should emit

@Property(xobjc nonatomic, retain) UIView *var;

instead of

@Property(xobjc nonatomic) UIView *var;

Honor comments

Currently, if a ivar is commented out, xobjc handles it as if it were visible, and compile fails (obviously)
at least the // comment should be recognized

Add keyword like XPRIVATE for properties that you wanna hide

Some properties are better declared within a private Interface inside the .m - I'd love some additional keyword that helps declaring if the property should be inside the .h or .m

(i know - I could just send a pull request, but my python is a bit rusty)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.