Monday, January 17, 2011

What Does Your Obj-C Code Look Like?

With a little help from Ruby, mine looks like this



example_model = ExhibitContributionSponsorship.new
field_names = example_model.attribute_names
field_names.collect! do |field_name|
  splitOut = field_name.split("_");
  splitOut.collect! { |piece| piece==splitOut.first ? piece : piece.capitalize }
  splitOut.join
end

field_names.each { |field| puts "@property (nonatomic retain) NSString *#{field};" }
synthesize = "@synthesize "
synthesize << field_names.join(", ")
puts synthesize

field_names.each { |field| puts "@property (nonatomic retain) IBOutlet UITextField *#{field}Control;" }
synthesize = "@synthesize "
synthesize << field_names.collect.join(", ")
puts synthesize



I used to use Excel, but Ruby is cooler.

No comments: