-
Couldn't load subscription status.
- Fork 0
Macros
Macros are used in NSRails to define how your Objective-C class will interact with Rails.
NSRMap (...) – the only essential macro in NSRails. Declares which properties a class should share with Rails. See its page for more details.
@implementation Person
@synthesize name, age, phoneNumber;
NSRMap(name, age, phoneNumber);
@endNSRailsUseModelName ( exact_rails_model_name ) – should be declared if the corresponding model in Rails is not the name of your class. By default, the corresponding model name will be derived from the class name (lowercase and under_scored), and the controller name will be the class name pluralized (lowercase and under_scored).
For example, if my Objective-C class is named DHSubscriber, but in Rails it’s only subscriber, I should use the NSRailsUseModelName macro in its implementation:
@implementation DHSubscriber NSRailsUseModelName(@"subscriber")This macro can go anywhere inside the implementation, but placing it next to or directly below the @implementation declaration is recommended.
- If your class name has an irregular plural, you can also set its plural string (really just how to refer to the controller) manually through a second parameter. Without it, NSRails will automatically pluralize, and usually pretty well, but here’s an example of a necessary case:
@implementation DHCactus NSRailsUseModelName(@"cactus", @"cacti")
- Note: When using this macro, NSRails will no longer automatically under_score (neither the model name nor the controller), so it must be exactly as it is server-side.
-
Note: Be careful with this when inheriting two levels from
NSRRemoteObject. See Inheritance.
NSRailsUseConfig ( app_url_for_this_model ) – should be declared if you want a certain model to retrieve/send information from/to a server at a different URL than defined in +[NSRConfig defaultConfig]. You may also place this macro anywhere inside your class’s implementation:
@implementation DHSubscriber
NSRailsUseConfig(@"http://differentrailsapp.com/")
@end- If this URL requires basic HTTP authentication, a username and password can be defined in the next two parameters:
@implementation DHSubscriber NSRailsUseConfig(@"http://differentrailsapp.com/", @"username", @"password") @end
- If this macro isn’t defined, the model will go to whatever’s defined in
+[NSRConfig defaultConfig](or rather, if there is one, to a current config context if defined). -
Note: Be careful with this when inheriting two levels from
NSRRemoteObject. See Inheritance.