Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old May 29, 2011, 04:02 AM   #1
yaniv92648
macrumors member
 
Join Date: Oct 2009
General Getter/Setter

Hi,
In Objective-c the default getter of the property is it's name.
if the property name is "string" then the default setter is setString.
can i define a general getter/setter for all of the properties of a class?
for example:
class: Person.
properties: NSString *ID, *name, *address.
i want all the getter methods (ID, name, address) to return the NSString with a prefix of "A".
the method ID will return @"AID".
the method name will return @"Aname".
the method address will return @"Aaddress".
i do not want to override each getter separately because i have a lot of properties.
Thanks.
yaniv92648 is offline   0 Reply With Quote
Old May 29, 2011, 04:27 AM   #2
Matthew Yohe
macrumors Demi-God
 
Join Date: Oct 2006
Send a message via AIM to Matthew Yohe
That doesn't really make much sense. But yes, you would have to either write a getter for each one of these, or I guess just a single getter that takes an argument defining which property you want. So something like:

Code:
[myPerson prependLetterA:@"name"];
Then your method for this is:
Code:
-(NSString *)prependLetterA:(NSString *)property{

NSString *string = [self valueForKey:property];

string = [NSString stringWithFormat:@"A%@",string];

return string;
}
But really, why are you doing this? Maybe you're doing something for some reason that you don't actually need to.
Matthew Yohe is offline   0 Reply With Quote
Old May 29, 2011, 04:41 AM   #3
yaniv92648
Thread Starter
macrumors member
 
Join Date: Oct 2009
But both of this solutions are not what i want..

Thanks 4 the reply but i don't wanna define a new method, it should be the default getter method overridden because i want everyone who calls the default properties of that class from outside will get the @"A" prefix. and i don't wanna define a specific getter 4 each property because i have many properties. i'm doing this to fix something which has been done wrong in the project, it's complicated..

p.s. please mark the checkbox "disable smilies in text" down below in your comments, thank u.
yaniv92648 is offline   0 Reply With Quote
Old May 29, 2011, 04:49 AM   #4
Matthew Yohe
macrumors Demi-God
 
Join Date: Oct 2006
Send a message via AIM to Matthew Yohe
Quote:
Originally Posted by yaniv92648 View Post
Thanks 4 the reply but i don't wanna define a new method, it should be the default getter method overridden because i want everyone who calls the default properties of that class from outside will get the @"A" prefix. and i don't wanna define a specific getter 4 each property because i have many properties. i'm doing this to fix something which has been done wrong in the project, it's complicated..

p.s. please mark the checkbox "disable smilies in text" down below in your comments, thank u.
What you're asking cannot be done. There is no concept of "default getter" like you're thinking. You likely want to just change the rest of the project. I understand it might be "complicated" but the only way you can fix this is to either write out methods for every property, or change the rest of the program. And I imagine that it makes way more sense to change the program than to actually change getters to append letters. It also likely just makes sense to only change the string where it's visible to the user. So, if there's some field that displays to the user, and it should have some prepended text, then just do what I did above in that method:
stringWithFormat:@"MyPrependedText%@",myStringToDisplay
Matthew Yohe is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
General System Error nayan504 MacBook Pro 2 Sep 10, 2011 04:02 PM
Is Mac Pro STRICT to Mac Xeon Processors or Just Xeons in General? QuakeProd Mac Pro 7 Apr 19, 2011 08:06 PM
MI Asst. Attorney General Fired yg17 Politics, Religion, Social Issues 43 Nov 9, 2010 10:34 AM
Xcode c++getter/setter/properties puuukeey Mac Programming 13 Dec 30, 2008 09:01 AM
Auto Generate Getter/Setter Methods? Vortec4800 Mac Programming 2 Apr 15, 2008 11:38 PM


All times are GMT -5. The time now is 01:21 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC