ios - Changing an argument's value on NSString's initWithFormat:arguments: method -


i'm having hard time figuring out following:

i have initializer method creates unused formatted nsstring nsstring arguments aren't initialized this:

nsstring *initialstring = [nsstring stringwithformat:@"%@, %@", arg1, arg2];

later in program, initialize arguments values when print out nslog initialstring arguments remain null. if check arguments they're initialized , provide correct values gave them.

initialstring strong referenced property of object while arguments static nsstrings.

so conclusion:

  1. i want initialize nsstring format , uninitialized arguments (hard coded) @ beginning of program.
  2. later on, @ runtime, want use initial string , have read values initialized arguments.

how achieve that? using pass-by-reference or kvo?

i not certain understand you, in order re-initialize initialstring updated values need call stringwithformat: again new values. because stringwithformat: take whatever value arg1 , arg2 @ time called , changes values not affect formatted string.

it's best put functionality private method updates instance variable (i assume is) whenever arg1 or arg2 changed:

- (void)formatinitialstringwitharg1:(id)arg1 andarg2:(id)arg2 {     self.initialstring = [nsstring stringwithformat:@"%@, %@", arg1, arg2]; } 

Comments