strongself / Generamba

This codegenerator is too brilliant to be real!
MIT License
1.82k stars 183 forks source link

Can I create a template to generate swift-like structure objects for ObjC? #157

Closed appleios closed 8 years ago

appleios commented 8 years ago

In swift we can create structs:

struct Person {
  var name: String
  var familyName: String
}

and get an initilizer for free:

let adam = Person(name: "Adam", familyName: "Smith")

In objc we have to create a class of kind:

@interface Person : NSObject
@property (strong, nonatomic) NSString *name;
@property (strong, nonatomic) NSString *familyName;
- (instancetype)initWithName:(NSString*)name familyName:(NSString*)familyName;
@end
@implementation Person
- (instancetype)initWithName:(NSString*)name familyName:(NSString*)familyName;
{
  self = [super init];
  if(self) {
    _name =  name;
    _familyName = familyName;
  }
}
@end

Is it possible to create a template for generamba for generation of this kind of swift-struct like classes for ObjC, for example, like this:

generamba gen objcstruct Person name:String familyName:String
etolstoy commented 8 years ago

@appleios Yes, it's possible.