Tag: nsarray

NSArray Tokenize基于密钥

我已经从服务器获取数据,并传递数据NSJSONSerialization后NSMutableArray也填充。 数组的输出如下: NSArray *jsonArray = (NSArray *)json; NSLog(@"Array – %@",jsonArray); 我想创build一个新的数组,其中将包含通讯的所有数据。 Array – ( { error = 0; newsletter = ( { date = "2015-11-23"; description = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\\'s standard dummy text ever since the 1500s, when an unknown […]

在目标c中对负数和正数进行sorting

我通过webservice列出了一个数量百分比像一个项目的东西。我得到的响应是一个类似于下面的代码的字典数组。我需要一个有序的格式 NSArray *numberArray = [NSArray arrayWithObjects: [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:-12.0], @"price", nil], [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:-86.0],@"price", nil], [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:-8.0],@"price", nil], [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:12.0],@"price", nil], [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:2.0],@"price", nil], [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:112.0],@"price", nil], nil]; 这是JSON响应的日志 [ { price = "-12"; }, { price = "-86"; }, { price = "-8"; }, { price = 12; }, { […]

Objective-C,sorting包含数字的string数组

让我们假设我有一个这样的数组 NSArray* arr = @[@"1",@"4",@"2",@"8",@"11",@"10",@"14",@"9"]; //note: strings containing numbers 我想这样sorting:[1,2,4,8,9,10,11,14] 但如果我使用 [arr sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]; 我得到[1,10,11,14,2,4,8,9] …如果我使用: NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"length" ascending:YES]; NSArray *sortDescriptors = @[sortDescriptor]; [arr sortedArrayUsingDescriptors:sortDescriptors]; 我得到这样的东西:[1,4,2,8,9,11,10,14] 我怎样才能结合这两个谓词? 或者是解决这个问题的其他更简单的方法? 注意:这个数组的输出只是为了debugging目的,我不在乎如果结果将数组转换为整数,只要我可以在控制台与NSLog谢谢

如何判断对象是否在NSArray?

有没有办法告诉某个对象是否在NSArray中? 我向数组中添加对象的方式使得可以多次添加同一个对象,而且我想查看是否有方法来查看它是否已经存在(在任何地方)。

方法firstObject vs objectAtIndex的用法有什么区别:0?

今天我已经testing使用firstObject和objectAtIndex:0。 如果数组大小为0,则使用前者不会导致崩溃,而后者会导致崩溃。 所以我在想,使用firstObject比objectAtIndex:0更好。 但是在使用firstObject over objectAtIndex方面还有什么问题:0? 我也一直在阅读NSArray的文档 ,我很惊讶,不知道为什么他们没有在文档中提到这个事实。

如何将NSString转换为NSArray

我有一个像 NSString* str = @"[90, 5, 6]"; 我需要将它转换为一个数组 NSArray * numbers = [90, 5 , 6]; 我做了这样一个很长的路: +(NSArray *)stringToArray:(NSString *)str { NSString * sep = @“[,”; NSCharacterSet * set = [NSCharacterSet characterSetWithCharactersInString:sep]; NSArray * temp = [str componentsSeparatedByCharactersInSet:set]; NSMutableArray * numbers = [[NSMutableArray alloc] init]; for(NSString * s in temp){ NSNumber * n = [NSNumber […]

无法从plist读取

我正在尝试做一些我已经知道该怎么做的事情,但这并不奏效。 寻找想法来解决这个问题。 我认为这与Xcode 4.1创buildplist文件的方式有关。 我试图从一个plist文件中读取string,并将其转储到一个NSArray中。 这是我的代码: NSString *myFile = [[NSBundle mainBundle] pathForResource:@"File1"ofType:@"plist"]; myArray = [[NSArray alloc]initWithContentsOfFile: myFile]; 我在Xcode中创build了一个plist文件 – 顶层数组和一些string。 myArray始终为空。 我试图在文本编辑器中打开plist,因为我在其他地方读到了stackoverflow,Xcode 4创build了顶级字典的plist。 我手动编辑,使其在顶层的数组 – 没有成功。 最后,我回到顶级字典,并试图将其读入NSDictionary – 也没有成功。 我在教程后观看了教程,并在StackOverflow上阅读了许多类似的问题,但是我无法从plist文件中读取任何东西 – 它肯定是在包中。 我已经无数次地在Xcode中重新创build了plist。 感谢任何build议。 这是plist的样子: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>New item</key> <array> <string>Ping</string> <string>Pang</string> <string>Pong</string> </array> […]

单个数组分成两个数组的代码如何?

当我使用从我需要的URL的JSONparsing,但我在这里我不喜欢得到2,1,4,4,6,5,8,7,10,9,12和11在单个数组中,我必须得到两个数组的总响应我的意思是一个数组集合将包括2,4,6,8,10和其他数组必须是3,5,7,9和11。 那么如何在iPhone中将单个数组的响应分解成两个数组呢? "(\n 2,\n 1\n)", "(\n 4,\n 3\n)", "(\n 6,\n 5\n)", "(\n 8,\n 7\n)", "(\n 10,\n 9\n)", "(\n 12,\n 11\n)"

在一个空的NSArray中复制NSArray

我有第一个NSArray firstArray ,我做 [firstArray removeAllObjects]; 之后我想填充其他数组secondArray的内容 是这样写的吗? firstArray = secondArray;

removeAllObjects崩溃的应用程序

我想清除我的arrays,我做的是, 我有我的应用程序中的tableview视图,首先我从服务器获取数据并将其加载到tableView中。 -(void)viewDidLoad{ //fetching data from server using background thread and storing it in array called (msg_array) [table reloadData]; } 当最后一行出现在屏幕上,我想从服务器获取新的数据,我想显示它, -(void)LoadMoreData{ //this method gets fire when last cell is on screen if ([msg_array count]>0) { [msg_array removeAllObjects]; //crashes here } } 这给出了错误: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI removeAllObjects]: unrecognized selector […]