Tag: nsarray

如何在iPhone中以降序对数组进行sorting

我想按降序对数组进行sorting,我可以按升序对数组进行sorting,这里是我的代码按升序sorting, NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"year" ascending:NO]; NSArray * descriptors = [NSArray arrayWithObjects:sortDescriptor, nil]; sortedArray = [array sortedArrayUsingDescriptors:descriptors]; dictionaryWithSortedYears = [[NSMutableDictionary alloc] init]; NSString *tempDateKey = nil; for (TreeXmlDetails *list in sortedArray) { id obj = [dictionaryWithSortedYears objectForKey:list.year]; if(!obj) { if(tempDateKey == nil) { arrayFromList = [[NSMutableArray alloc] init]; tempDateKey = list.year; } } […]

如何将JSON转换为NSArray

我有一个JSON数组在页面上输出。 我想将这个JSON数组转换成NSArray。 或者像这样转换这个json: 有人可以让我知道这一步可能是什么? 谢谢!

如何从一个NSMutableArray获得货币的总和

我想从NSMutableArray的货币的总和。 例如:我有一个数组A(1,234.56,2,345.67),并且在数组中添加项之后,我想要结果显示为:3,580.23把它放在标签上。 有没有办法来实现这个? 谢谢

使用NScanner来parsingCSV文件到字典数组

我创build了一个iPhone应用程序,它包含一个位置(lat,long,point)的字典数组。 我通过手动input每个值来创build数组。 myLocationArray = @[ @{ kStation : @"1", kLatitude : @( 41.656467), kLongitude : @(-81.277963) }, @{ kStation : @"2", kLatitude : @(41.657118), kLongitude : @(-81.276545) }, @{ kStation : @"3", kLatitude : @(41.658493), kLongitude : @(-81.273542) }, … 这是好的,但工程,但现在我想通过从.CSV文件获取数据编程创build此数组。 我有一个.CSV文件(TestCSV.csv),看起来像这样。 41.656467,-81.277963,27200 41.657118,-81.276545,27650 41.658493,-81.273542,28631.5 41.660728,-81.268547,30195 41.661830,-81.266065,30991 41.662828,-81.263819,31700 41.663677,-81.261962,32300 41.664578,-81.259909,32950 41.666210,-81.256312,34100 41.666921,-81.254708,34605 41.668043,-81.252191,35400 41.669044,-81.250043,36099 我想通过使用NScannerparsingTestCSV.csv来创buildmyLocationArray(格式如图所示)。 […]

如何使用objective-c从数组中select不同的图像

我已经在NSArray中存储了10张图片。 在UIViewController中,我放置了6个UIImageView,并在.h文件中给出了sockets。 我需要从数组中select任何6张图像怎么办? 并需要在UIImageView中显示图像。 – (void)viewDidLoad { [super viewDidLoad]; images=[[NSMutableArray alloc]initWithObjects:[UIImage imageNamed:@"Navarre-Family-Eye-Care-Navarre-Florida-Optometrist-Santa-Christmas-Toy-Safety.jpg"],[UIImage imageNamed:@"Christmas-Wallpapers-HD-Picture.jpg"],[UIImage imageNamed:@"Christmas-Wallpaper-jesus-9413550-1024-768.jpg"],[UIImage imageNamed:@"tree.jpg"],[UIImage imageNamed:@"luxury-christmas-napkins-father-christmas-1635-p.jpg"],[UIImage imageNamed:@"Navarre-Family-Eye-Care-Navarre-Florida-Optometrist-Santa-Christmas-Toy-Safety.jpg"],[UIImage imageNamed:@"Christmas-Wallpapers-HD-Picture.jpg"],[UIImage imageNamed:@"Christmas-Wallpaper-jesus-9413550-1024-768.jpg"],[UIImage imageNamed:@"tree.jpg"],[UIImage imageNamed:@"luxury-christmas-napkins-father-christmas-1635-p.jpg"], nil]; NSString *dd=[NSString stringWithFormat:@"%@", images]; NSLog(@"%@",dd); } – (void)setImagesForImageViews:(NSArray<UIImageView*>*)viewsArray fromArray:(NSArray<UIImage*>*)imageArray { if(images == nil || viewsArray == nil || viewsArray.count > images.count) { return; // early return } NSMutableArray* randomImageArray = [NSMutableArray arrayWithCapacity:viewsArray.count]; while […]

parsing一个Json表到一个NSMutableArray

目前我直接通过本地目标C代码填写我的数组: Datas *pan1 = [[Datas alloc] initWithTitle:@"My array 1" title:@"Shakespeare's Book" location:@"London"]; Datas *pan2 = [[Datas alloc] initWithTitle:@"My array 2" title:@"Moliere's Book" location:@"London"]; NSMutableArray *datasListe = [NSMutableArray arrayWithObjects:pan1, pan2, nil]; 但是我想通过这个Json列表来填充这个NSMutableArray: { "myIndex" : [ { "name":"My array 1", "title": "Shakespeare's Book", "location": "London" }, { "name":"My Array 2", "title": "Moliere's Book", "location": "Paris" } […]

对NSDictionary的SIGABRT objectAtIndex:无法识别的select器

我在这里有一个奇怪的错误。 我有一个名为__ImageData的数组: static NSArray *__ImageData = nil; NSString *path = [[NSBundle mainBundle] pathForResource:@"ImageData" ofType:@"plist"]; NSData *plistData = [NSData dataWithContentsOfFile:path]; NSString *error; NSPropertyListFormat format; _ImageData = [NSPropertyListSerialization propertyListFromData:plistData mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&error]; 当我NSLog出arrays的内容,我得到这个输出: 2012-08-23 16:36:35.573 CAT[28814:c07] { "Item 0" = { height = 7121; name = Map1; width = 8556; }; "Item 1" = { height = […]

“string”与“AnyObject”错误不相同

我试图通过NSUserDefaults从我的应用程序传递数据到Apple Watch应用程序时遇到问题。 每当我尝试检索存储的数组,我得到的错误'String' is not identical to 'AnyObject' 。 我一直在试图找出一个解决scheme,但我不能解决这个问题,因为我在我的应用程序中的其他地方使用相同的方法,它没有问题。 这是我在苹果手表的一部分: var defaults = NSUserDefaults(suiteName: "group.AffordIt") tempNames = defaults?.objectForKey("namesWatch") as NSArray tempDates = defaults?.objectForKey("datesWatch") as NSArray tempAmounts = defaults?.objectForKey("valuesWatch") as NSArray 包含的应用程序部分: defaults?.setObject(names, forKey: "namesWatch") defaults?.setObject(dates, forKey: "datesWatch") defaults?.setObject(values, forKey: "valuesWatch") 名称,date和值是string数组。 有任何想法吗?

如何追加数组。 或者我如何将模型转换为nsmuttable数组

在我的应用程序中,我使用alamofire对象映射器来使用MVC结构。 现在我得到一个数组,我适合模型类。 这里是模型类 class OrderDetailSecond: Mappable { var id : Int? var isRxMedicine : Int? var medicineTypeId : String? var name : String? var orderId : String? var price : String? var quentity : Int? var strength : String? required init?(_ map: Map){ } func mapping(map: Map) { id <- map["id"] isRxMedicine <- map["is_rx_medicine"] medicineTypeId […]

有没有办法在数组中复制NSDictionaries的数量?

我目前在我的表格视图中有这个NSDictionary数组,但是我需要在表格视图向下滚动时复制数组中的字典数。 有没有办法做到这一点,还指定或知道什么字典名称将? NSMutableDictionary *d0 = [[NSMutableDictionary alloc] init]; NSMutableDictionary *d1 = [[NSMutableDictionary alloc] init]; NSMutableDictionary *d2 = [[NSMutableDictionary alloc] init]; NSMutableDictionary *d3 = [[NSMutableDictionary alloc] init]; NSMutableDictionary *d4 = [[NSMutableDictionary alloc] init]; objects = [NSMutableArray arrayWithObjects:d0, d1, d2, d3, d4, nil];