我在app委托类中创建了全局字符串,并在我的应用程序控件移动时在多个类中追加该字符串中的字符串,但我只得到最后一个附加字符串。
@property (nonatomic , strong) NSString *strConacatResponse;
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];
在我的第3课
NSString *strTemp = @" \n Database getSuscriptionStatus error in api calling of apple ";
[AppDelegate sharedAppDelegate].strConacatResponse = [[AppDelegate sharedAppDelegate].strConacatResponse stringByAppendingString:strTemp];
但只获得最后一个字符串
答案 0 :(得分:1)
您需要在appDelegate中初始化self.strConacatResponse,并在声明变量时使用NSMutableString。
第一步是(IN appDelegate): -
self.strConacatResponse=[NSString stringWithFormat:@"Name : %@ ",name];
然后像往常一样追加字符串
答案 1 :(得分:1)
将属性变量声明为NSMutableString
@property (nonatomic , strong) NSMutableString *strConacatResponse;
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];
答案 2 :(得分:0)
您的字符串需要是可变的才能添加新字符串:
@property (nonatomic , strong) NSMutableString *strConacatResponse;
然后(例如)AppDelegate
:
strConacatResponse = [NSMutableString new];
现在你可以添加更多字符串了。
答案 3 :(得分:0)
只想指出现有的日志记录API,因为您似乎正在尝试实现某种日志记录:os_log,NSLog,CocoaLumberjack。 这些都是久经考验的API,因此根据您的需求,不再重新发明轮子可能是更好的选择。