nsmutablearray

error : 'Attempt to mutate immutable object with appendString:' --

删除回忆录丶 提交于 2019-12-07 12:38:12
问题 I am getting an error 'Attempt to mutate immutable object with appendString:' and my code is NSMutableString *resultString= [[NSMutableString alloc]init]; for (NSMutableString *s in self.ArrayValue) { [resultString appendString:s]; NSLog(resultString); } ArrayValue is NSMutableArray. I am not able to understand where is the problem thank you in advance 回答1: As posted, the code you have will not give you the error you describe. Probably, somewhere between allocating resultString and the for

remove object from NSArray

烈酒焚心 提交于 2019-12-07 11:41:39
问题 How can I remove an object from a reversed NSArray . Currently I have a NSMutableArray , then I reverse it with NSArray* reversedCalEvents = [[calEvents reverseObjectEnumerator] allObjects]; now I need to remove at item from reversedCalEvents or calEvents and automatically refresh the table the array is displayed in based on conditions. i.e. if(someInt == someOtherInt){ remove object at index 0 } How can I do this? I cannot get it to work. 回答1: You will need a mutable array in order to remove

writeToFile not working with NSDictionary [duplicate]

↘锁芯ラ 提交于 2019-12-07 08:46:15
问题 This question already has answers here : Why NSMutableDictionary don't want write to file? (2 answers) Closed 5 years ago . I looked around other similar questions about this but nothing really worked. I managed to write only one pair (object / key) of the dictionary (e.g.: setObject:itemProperties[0] forKey[0]) on my Plist. But I would like all the objets and keys to be added. I didn't managed so far (return the error). Any help? // Path to Documents Folder NSArray *paths =

【OC】十一、数组对象(NSArray & NSMutableArray)

扶醉桌前 提交于 2019-12-07 08:44:13
不可变数组: NSArray 可变数组: NSMutableArray 创建一个不可变数组 简单的创建一个数组 [NSArray arrayWithObjects: @"111",@"222",nil]; 我们可以按顺序列出对象并用逗号隔开,并且最后一个值指定为nil 这时候我们可以使用 arrayWithObjects 方法 我们可以取出数组的值 用objectAtIndex方法 [arr objectAtIndex:0]; 创建一个可变数组 如果我们想要在数组中添加 删除 修改元素 我们可以使用NSMutableArray NSMutableArray *arr = [NSMutableArray array]; 给数组分配容量 NSMutableArray *array= [ NSMutableArray arrayWithCapacity : 20 ]; 在数组末尾添加对象 [array addObject:"Four"]; 删除数组中指定索引处对象 [array removeObjectAtIndex:1]; 快速枚举 for(NSString *string in array) { NSLog(@"string:%@",string); } 来源: oschina 链接: https://my.oschina.net/u/1048271/blog/209005

iPhone: Return NSMutableArray in method while still releasing

余生长醉 提交于 2019-12-07 07:34:27
I am trying to understand a little more about memory management. Knowing that I need to release anything that I have init or alloc'ed I am confused about the following: - (NSMutableArray *)getData { NSMutableArray *data = [[NSMutableArray alloc] init]; NSString *first = @"First object"; [data addObject:first]; NSString *second = @"Second object"; [data addObject:second]; return data; } Since I used alloc and init, I know I need to release my data object. But if I add autorelease to the init part or to the return, it crashes when I run the method. What is the correct way to do something like

Sort NSMutableArray with custom objects by another NSMutableArray [duplicate]

做~自己de王妃 提交于 2019-12-07 06:25:57
问题 This question already has answers here : How do I sort an NSMutableArray with custom objects in it? (25 answers) Sorting two NSArrays together side by side (4 answers) Closed 6 years ago . I have 2 NSMutableArrays . First array contains custom object intances with property NSString *itemID , second array contains only from NSString objects with same values of itemID , but in another order. I need to sort first array by itemID property of each object, and it should be sorted like second array.

Selectively remove and delete objects from a NSMutableArray in Swift

痞子三分冷 提交于 2019-12-07 05:42:13
问题 Basic question. What is the best way to selectively remove and delete items from a mutable Array in Swift? There are options that do NOT seem to be suited for this like calling removeObject inside a for in loop enumeration block and others that appear to work in general like for loop using an index + calling removeObjectAtIndex , even inside the loop for in loop for populating an arrayWithItemsToRemove and then use originalArray. removeObjectsInArray(arrayWithItemsToRemove) using .filter to

Fast Enumeration With an NSMutableArray that holds an NSDictionary

99封情书 提交于 2019-12-07 05:23:52
问题 Is it possible to use fast enumeration with an NSArray that contains an NSDictionary? I'm running through some Objective C tutorials, and the following code kicks the console into GDB mode NSMutableArray *myObjects = [NSMutableArray array]; NSArray *theObjects = [NSArray arrayWithObjects:@"easy as 1",@"easy as two", @"Easy as Three"]; NSArray *theKeys = [NSArray arrayWithObjects:@"A",@"B",@"C"]; NSDictionary *theDict = [NSDictionary dictionaryWithObjects:theObjects forKeys:theKeys];

How can I convert NSMutableArray into NSString?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-07 05:04:02
问题 I am trying to convert (or copy?) a NSMutableArray into a NSString . I guess my problem is that I don't really understand the structure of a NSString . After conversion I want to attached it in email body. Here is my code: - (IBAction)sendEmail { NSLog(@"sendEmail"); [textView resignFirstResponder]; [textView1 resignFirstResponder]; if ([MFMailComposeViewController canSendMail]) { // set the sendTo address NSMutableArray *recipients = [[NSMutableArray alloc] initWithCapacity:1]; [recipients

I'm trying to get a UILabel to scroll inside of a UIScrollView but it doesnt scroll

情到浓时终转凉″ 提交于 2019-12-07 04:49:55
问题 This is in my .m - (void)viewDidLoad { [super viewDidLoad]; [self.scrollView addSubview:self.contentView]; self.scrollView.contentSize = self.contentView.bounds.size; NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; NSMutableArray *arr = [[NSMutableArray alloc]init]; arr = [Singleton getArray]; NSString *str = [arr componentsJoinedByString:@"\n"]; summaryLabel.text = str; } This is in my .h @interface TotalViewController : UIViewController { UIScrollView *scrollView;