nsmutablearray

Storing NSMutableArray in Sqlite

情到浓时终转凉″ 提交于 2019-12-19 10:21:28
问题 I have an NSMutableArray containing the coordinates and sizes of multiple CGRects. I want to store this into the sqlite. Is it possible to store the whole array? Or should I just store the CGRects manually in the database? UPDATE: This one is the data I retrieved from the database: 62706c69 73743030 d4010203 04050817 18542474 6f705824 6f626a65 63747358 24766572 73696f6e 59246172 63686976 6572d106 0754726f 6f748001 a3090a0f 55246e75 6c6cd20b 0c0d0e5a 4e532e6f 626a6563 74735624 636c6173

How to archive an NSArray of custom objects to file in Objective-C

ⅰ亾dé卋堺 提交于 2019-12-19 09:16:32
问题 Can you show me the syntax or any sample programs to archive an NSArray of custom objects in Objective-C? 回答1: Check out NSUserDefaults . For Archiving your array, you can use the following code: [[NSUserDefaults standardUserDefaults] setObject:[NSKeyedArchiver archivedDataWithRootObject:myArray] forKey:@"mySavedArray"]; And then for loading the custom objects in the array you can use this code: NSUserDefaults *currentDefaults = [NSUserDefaults standardUserDefaults]; NSData *savedArray =

数组排序

自闭症网瘾萝莉.ら 提交于 2019-12-19 05:23:28
1 #pragma mark 冒泡排序 2 - (void)userArrSort:(NSMutableArray *)userArr 3 { 4 int n = userArr.count; 5 int i,j; 6 NSDictionary *temp; 7 for(j=0;j<n-1;j++) 8 { 9 for(i=0;i<n-1-j;i++) 10 { 11 // NSDictionary*ssy = []; 12 if(((NSString *)[userArr[i] objectForKey:@"vlevel"]).intValue<((NSString *)[userArr[i+1] objectForKey:@"vlevel"]).intValue)//数组元素大小按升序排列 13 { 14 temp=userArr[i]; 15 userArr[i]=userArr[i+1]; 16 userArr[i+1]=temp; 17 } 18 } 19 } 20 for (int x = 0; x<userArr.count; x++) 21 { 22 if (1) { 23 // [userArr replaceObjectAtIndex:0 withObject:[userArr[i]]; 24 } 25 } 26 } 27 #pragma mark

How to add string objects to NSMutableArray

倖福魔咒の 提交于 2019-12-18 13:54:20
问题 I have an NSMutableArray named randomSelection: NSMutableArray *randomSelection; I am then trying to add strings to this array if certain criteria are met: [randomSelection addObject:@"string1"]; I am then trying to output the string, to determine if it has added it: NSString *test = [randomSelection objectAtIndex:0]; NSLog(test); However nothing is being output to the error log and I can't figure out why. Any help/hints appreciated. 回答1: I think you are missing to allocate the memory for

How can I check If I got null from json?

坚强是说给别人听的谎言 提交于 2019-12-18 13:11:51
问题 Here I got from JSON [{"photo":null}] and I use this code NSMutableArray *jPhoto = [NSMutableArray arrayWithArray:(NSArray *)[jsonDict valueForKey:@"photo"]]; How can I check it if I want to use if() ?? edit here is JSON Data [{"photo": [{"image":"http:\/\/www.yohyeh.com\/upload\/shisetsu\/13157\/photo\/1304928459.jpg","title":"test picture","content":"this is description for test picture.\r\n\u8aac\u660e\u6587\u306a\u306e\u306b\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb

How to check if an instance of NSMutableArray is null or not

最后都变了- 提交于 2019-12-18 12:10:48
问题 How to check an NSMutableArray is null or not ? 回答1: If you want to check if it is empty: if ([myMutableArray count] == 0) { ... } If you want to check if the variable is nil : if (!myMutableArray) { ... } or: if (myMutableArray == nil) { ... } 回答2: //if the array has a count of elements greater than 0, then the array contains elements if(myarray.count>0){ NSlog(@"myarray contains values/elements"); } else{ //else the array has no elements NSlog(@"myarray is nil"); } 回答3: There are multiple

How to convert the NSMutableArray to CSV file on iPhone?

為{幸葍}努か 提交于 2019-12-18 11:15:30
问题 I am writing an iPhone application, which contains a function. It can convert the NSMutableArray to a CSV file. However, I don't know how to do. Can anyone help me to do this? Thank you very much. // ------ Update ----- Thank you for everyone reply. Actually, the array contains the objects of the elements, but I can convent it all to the array like the following (I guess it is more easy to do this). The array is NSMutableArray *csvArray and the array contains data, like the following example.

Adding an object at a specific index of an NSMutableArray

橙三吉。 提交于 2019-12-18 11:14:06
问题 How can an object be added at a specific index of an NSMutableArray ? How is an object added to the front of the array? 回答1: [myMutableArray insertObject:myObject atIndex:42]; To add an object to the front of the array, use 0 as the index: [myMutableArray insertObject:myObject atIndex:0]; 回答2: Take a look at the insertObject:atIndex: method of the NSMutableArray class. Adding to the "front" of the array implies index 0. For example: NSMutableArray * array = [[NSMutableArray alloc]

iPhone SDK: How do I pass an array of values from a ViewController onto other ViewController?

橙三吉。 提交于 2019-12-18 07:21:51
问题 I tried creating a method like below in SecondViewController : -(void)setValue:(NSMutableArray*)array { //NSMutableArray *newArray = [[NSMutableArray alloc] init]; newArray = [array retain]; } and passing the value from FirstViewController using an object of SecondViewController named second: [second setValue:existingArray]; existingArray is an NSMutableArray. What could be wrong? 回答1: In the code you have set the array in the " second " object of a SecondViewController . So you need to use

iOS error: [__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]

落花浮王杯 提交于 2019-12-18 07:11:58
问题 In my application I try to load contents from a url, store them in a mutable array and show them in a table view. But I can't get it working, because every time I run the app this error appears: *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]' *** First throw call stack: (0x34dd088f 0x36d9e259 0x34d2823d 0x316e562f 0x315f09a9 0x313c0c5d 0x313c1b95 0x313c1ae7 0x313c16c3 0xa5cfb 0x33623ec7 0x35387a09