I have a class that represents some data.
I'm getting this data from a Web Service in the JSON format.
The web service does not conform to the Objective - C naming convention. More specifically, all the attributes of an object starts with capital letter, for example Name.
I want to be able to utilize the built-in KVC but still build my objects with the Objective-C naming convention.
So in my public class declaration I'm declaring one property:
@interface TVPage : NSObject
@property (nonatomic, copy) NSString *name;
@end
And In my *.m file I'm declaring a category extension to conform to the Web Service naming convention:
@interface TVPage ()
@property (nonatomic, copy , getter = name , setter = setName:) NSString *Name;
@end
In the private property I'm specifying the getter and setter that I want to actually access the data.
All I want to achieve is just another method, called Name that will actually call name behind the scene. (setName: actually fits for both Name and name)
My question is, when I'm synthesizing the properties like that:
@implementation TVPage
@synthesize name;
@synthesize Name;
@end
Will it generate two different Instance Variables called Name and name or is it smart enough to understand not to do that and create only one named name?
Can I tell the compiler explicitly - "Do not generate IVar for this property"?
Thanks!
EDIT:
Why would I want to do that?
A lot of you asked me what exactly am I trying to achieve here. Well, what I'm trying to do is to make my life easier when it comes to parsing the data returned from the web service.
The data is returned as a JSON String. That means that when I'll parse it, I'll probably get back NSDictionaries to represent the data.
I want to easily create objects that I designed to hold this data, because it's not convenient, safe or readable to work with dictionaries as a data model.
Now, the Key-Value Coding features allow me to set the attributes of an object, directly from a dictionary using setValuesForKeysWithDictionary:
But this will work only if my object actually have accessor methods with the same names as the dictionary's keys. If there is a key that don't have a matching attribute in my object, I'll get an exception from setValue:forUndefinedKey:.
To avoid that I want to create Facade Interface that will conform to the Key-Value Coding methods implied by the attribute names from the server. At the same time I want that the implementation of that interface will access the same data that the "regular" interface access.
object.name = @"a"; object.Name = @"b"; NSLog(@"a:%@, b:%@", object.name, object.Name);