Objective c 如何在目标c中字符串的全局变量中追加字符串

Objective c 如何在目标c中字符串的全局变量中追加字符串,objective-c,nsstring,Objective C,Nsstring,我已经在app delegate类中创建了全局字符串,并在应用程序控件移动时将字符串附加到多个类中,但我只得到最后一个附加的字符串 @property (nonatomic , strong) NSString *strConacatResponse; 在appdelegate.m中 self.strConacatResponse = [self.strConacatResponse stringByAppendingString:[NSString stringWithFormat:@"Na

我已经在app delegate类中创建了全局字符串,并在应用程序控件移动时将字符串附加到多个类中,但我只得到最后一个附加的字符串

@property (nonatomic , strong) NSString *strConacatResponse;
在appdelegate.m中

self.strConacatResponse = [self.strConacatResponse stringByAppendingString:[NSString stringWithFormat:@"Name : %@ ",name]];
然后在另一节课上

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


    [AppDelegate sharedAppDelegate].strConacatResponse =  [[AppDelegate sharedAppDelegate].strConacatResponse stringByAppendingString:strDates];
在我的第三节课上

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

但是,仅获取最后一个字符串时,需要首先在appDelegate中初始化self.strConacatResponse,并在声明变量时使用NSMutableString

第一步是(在appDelegate中):-


然后像往常一样追加字符串

您的字符串需要可变才能追加新字符串:

@property (nonatomic , strong) NSMutableString *strConacatResponse;
然后(例如)在
AppDelegate
中:

strConacatResponse = [NSMutableString new];

现在您可以添加更多字符串。

只想指出现有的日志API,因为您似乎在尝试实现某种日志记录:,NSLog。
这些都是经过战斗验证的API,因此根据您的需要,最好不要重新发明轮子。

将属性变量声明为NSMutableString

@property (nonatomic , strong) NSMutableString *strConacatResponse;
在appdelegate.m中

self.strConacatResponse=[[NSMutableString alloc]init];
self.strConacatResponse = [NSString stringWithFormat:@"Name : %@ ",name];
然后在第二节课上

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

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

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


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

您能展示sharedAppDelegate方法吗?最后一个字符串是什么意思?请告诉我你得到的是什么细绳?
NSString *strTemp = @" \n Database getSuscriptionStatus error in api calling of apple   ";


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