nsmutablearray

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

南笙酒味 提交于 2019-12-06 02:09:08
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 As posted, the code you have will not give you the error you describe. Probably, somewhere between allocating resultString and the for loop, you are overwriting it with a normal NSSring. Just do have like this: It works for me... NSMutableString

How to persist a NSMutableArray

冷暖自知 提交于 2019-12-06 02:05:11
I'm absolutely new to iOS Dev. I started out with the really helpful tutorial on Apple dev website So i made the simple To-Do List application, as per instructions. The App: It's a simple to-do list. It has a view, with a single text-field, which takes in an input, which then appends that input to the table-list view. the table list view is my "TO-Do List" which is generated from a NSMutableArray. The Problem: Whenever i quit and relaunch the application, my List disappears. The Question: I need a way to persist the NSMutableArray *ToDoList which stores my list. So is it possible to persist

how to remove NULL values from NSMutableArray? ios

假装没事ソ 提交于 2019-12-06 01:55:28
问题 i have array of birthdates as array is getting filled from facebook so there are some friends whos birthdates are private so it contain NULL how to convert that array like empty string wherever there is null value the array is like below "<null>", "10/29/1988", "11/13", "03/24/1987", "04/25/1990", "03/13", "01/01", "<null>", "12/15/1905", "07/10", "11/02/1990", "12/30/1990", "<null>", "07/22/1990", "01/01", "07/17/1989", "08/28/1990", "01/10/1990", "06/12/1990", 回答1: The null values appear to

iOS - Make a copy of a array object into another

随声附和 提交于 2019-12-05 22:59:29
I have a little problem, and I need help. I want to loop through a multidimensional array, and every time I find a value for a key ex."name" that is equal to ex. "Hello". I want to copy that array object into another array. How do I do that? I assume you have a 2-dimensional array and since I don't know how your objects within the array look like I take the id type and the method valueForKey : NSMutableArray *tmp = [[NSMutableArray alloc] init]; for(NSArray *dim1Array in yourMultidimensionalArray) { for(id obj in dim1Array) { if([[obj valueForKey:@"name"] isEqualToString:@"Hello"]) { [tmp

NSArray和NSMutableArray

倾然丶 夕夏残阳落幕 提交于 2019-12-05 22:34:32
一、NSArray的基本介绍: NSArray是OC语言中的数组类,可以存放多种类型的数据。 二、NSArray的初始化: //只有一个数据的数组 NSArray *arr1 = [NSArray arrayWithObject:@"1"]; NSArray *arr2 = [NSArray arrayWithObjects:@"2",@"3",@"4",nil]; //用数组生成另一个数组 NSArray *arr3 = [NSArray arrayWithArray:arr2]; //多个数据的数组初始化(最常用) NSArray *arr4 = @[ arr1, arr2, arr3 ]; for (int i = 0; i < 3; i++) { NSLog(@"arr%d - %@",i,arr4[i]); } 三、NSArray的常见用法: //初始化字符串arr NSArray *arr = @[@"1",@"2",@"3",@"a",@"b",@"c",@"你好",@"我好",@"他好"]; //arr.count - 获取数组中元素的个数 NSLog(@"arrr - count - %lu",(unsigned long)arr.count); //objectAtIndex - 获得某个位置的元素 NSLog(@"arr - 2 - %@",[arr

UserDefaults/KeyedArchiver Frustrations

拜拜、爱过 提交于 2019-12-05 20:57:52
I'm working on a homework app that uses custom Assignment objects for each assignment. I am trying to store an NSMutableArray (casted to an NSArray via initWithArray:) in standardUserDefaults but I'm having trouble with saving and reloading the array. I have a table view from which you can choose to add a new assignment (which loads NewAssignmentViewController). When you save the assignment, it is pushed back to an array in AssigmentsViewController. And then you call it every time you load the UITableView which shows the assignments. Here is the relating code: -(void)saveToUserDefaults:

NSMutable array to UITableview when button clicked

那年仲夏 提交于 2019-12-05 20:30:47
i want to show my email headers in a UITableView when inbox button clicked, my email headers is stored in an NSMutable Array, -(IBAction)buttonInbox:(id)sender{ NSLog(@"Inbox Button Clicked %@",buttonInbox); [self select:@"INBOX"]; NSArray *lines = [self sendCommand:@"fetch 1:* (body[header.fields (from subject date)])"]; //NSMutableArray *emaiArray= [[NSMutableArray alloc] init]; NSMutableString *totalEmail= [NSMutableString stringWithString:@""]; int counter = 0; int i =0; NSRange tmp; for(i=0;i<[lines count];i++) { NSString *line = [lines objectAtIndex:i]; //NSLog(@" Burda %@" ,line); tmp =

writeToFile not working with NSDictionary [duplicate]

瘦欲@ 提交于 2019-12-05 17:44:14
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 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths

How to initialize a NSMutableArray in Objective C?

巧了我就是萌 提交于 2019-12-05 15:15:12
问题 I come from a Java background and I am learning Objective C. I am trying to create a class that has a string array and a member function to modify the Array. My code looked like this: @implementation TAWChapter @synthesize mSubject; @synthesize mItems; - (id) init{ self.mItems = [[NSMutableArray alloc] init]; return self; } - (void) setSubject:(NSString *)subject{ self.mSubject = subject; } - (void) addItem:(NSString *)item{ [self.mItems addObject:@"asdf"]; } @end Which didn't work. I got a "

CFPropertyListCreateDeepCopy fails to process array / dictionary containing NSNull

旧街凉风 提交于 2019-12-05 12:28:38
For some reason this sample code works: NSArray *immutable = @[ @"a", @"b", @"c" ]; NSMutableArray *mutable = (__bridge id)CFPropertyListCreateDeepCopy(kCFAllocatorDefault, (__bridge CFArrayRef)immutable, kCFPropertyListMutableContainers); and this code produces nil as a result of the conversion: NSArray *immutable = @[ @"a", [NSNull null], @"c" ]; NSMutableArray *mutable = (__bridge id)CFPropertyListCreateDeepCopy(kCFAllocatorDefault, (__bridge CFArrayRef)immutable, kCFPropertyListMutableContainers); I tried to find any mention of NSNull not being allowed when using this function. I have a