1

I have created global string in app delegate class and append strings in that string in multiple classes as my application control moves but i m getting only last appended string.

@property (nonatomic , strong) NSString *strConacatResponse;

in appdelegate.m

self.strConacatResponse = [self.strConacatResponse stringByAppendingString:[NSString stringWithFormat:@"Name : %@ ",name]];

then in another classes

NSString *strDates = [NSString stringWithFormat:@"\n Common utilities not expire *** EndDate: %@ *** StartDate: %@ ",paramEndDate,paramStartDate];


    [AppDelegate sharedAppDelegate].strConacatResponse =  [[AppDelegate sharedAppDelegate].strConacatResponse stringByAppendingString:strDates];

in my 3rd class

 NSString *strTemp = @" \n Database getSuscriptionStatus error in api calling of apple   ";
    [AppDelegate sharedAppDelegate].strConacatResponse = [[AppDelegate sharedAppDelegate].strConacatResponse stringByAppendingString:strTemp];

but getting only last string

2
  • 1
    Can you show sharedAppDelegate method? Commented May 1, 2018 at 11:54
  • What do you mean by last string? Could please tell what exact string you're getting? Commented May 1, 2018 at 12:26

4 Answers 4

1

You need to initialize the self.strConacatResponse First in you appDelegate and Use an NSMutableString while declaring the variable.

First step would be (IN appDelegate) :-

self.strConacatResponse=[NSString stringWithFormat:@"Name : %@ ",name];

Then append the strings as usual

Sign up to request clarification or add additional context in comments.

Comments

1

Declare the property variable as NSMutableString

@property (nonatomic , strong) NSMutableString *strConacatResponse;

in appdelegate.m

self.strConacatResponse=[[NSMutableString alloc]init];
self.strConacatResponse = [NSString stringWithFormat:@"Name : %@ ",name];

then in second classes

NSString *strDates = [NSString stringWithFormat:@"\n Common utilities not expire *** EndDate: %@ *** StartDate: %@ ",paramEndDate,paramStartDate];

 [AppDelegate sharedAppDelegate].strConacatResponse = [NSString stringWithFormat:@"%@ %@ ",[AppDelegate sharedAppDelegate].strConacatResponse,strDates ];

in Third class

NSString *strTemp = @" \n Database getSuscriptionStatus error in api calling of apple   ";


[AppDelegate sharedAppDelegate].strConacatResponse = [NSString stringWithFormat:@"%@ %@ ",[AppDelegate sharedAppDelegate].strConacatResponse,strTemp];

Comments

0

Your string needs to be mutable to be able to append new strings:

@property (nonatomic , strong) NSMutableString *strConacatResponse;

Then (for instance) in AppDelegate:

strConacatResponse = [NSMutableString new];

And now you can add more strings to it.

Comments

0

Just want to point existing logging APIs, because it seems that you're trying to achieve some sort of logging: os_log, NSLog, CocoaLumberjack. Those are battle-proven APIs, so depending on your needs it might be a better option to not reinvent the wheel.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.