nsarray

How to display unique elements of an array using Swift? [duplicate]

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 13:39:06
This question already has an answer here: Removing duplicate elements from an array in Swift 38 answers Swift 3 Generics: How to Find The Common Set of Two Generic Arrays 2 answers I have a formula retuning an array as example var Array = [a,s,d,s,f,g,g,h,e] . What I want is to run a for loop or some other option that gives me back a,s,d,f,g,h,e - only the unique values. How can I do this with ios Swift? If you don't care about order: Simply use a set: let set: Set = ["a", "s", "d", "s", "f", "g" , "g", "h", "e"] print(set) // ["a", "s", "f", "g", "e", "d", "h"] If you care about the order:

How to plot the markers in google maps from a dictionay in ios?

拜拜、爱过 提交于 2019-11-28 13:04:20
问题 In my app, I have done JSON parsing and I got the coordinates in the form of a dictionary, I want to use the coordinates angd plot it in the map, I have using this SBJsonParser *jsonParser = [SBJsonParser new]; NSArray *jsonData = (NSArray *) [jsonParser objectWithString:outputData error:nil]; for(int i=0;i<[jsonData count];i++) { NSDictionary *dict=(NSDictionary *)[jsonData objectAtIndex:i]; Nslog(@"%@",dict); double la=[[dict objectForKey:@"latitude"] doubleValue]; double lo=[[dict

Maximum amount of objects in NSArray

岁酱吖の 提交于 2019-11-28 12:15:47
What is the largest amount of objects I can put in my NSArray? The NSArray initWithCapacity method, takes an unsigned int as an argument. So whatever the maximum value of an unsigned int is on your platform may be the theoretical limit. However the actual limit is more likely to depend on the amount of memory you have available. Have you tried to find out? ;) NSMutableArray * a = [[NSMutableArray alloc] init]; NSUInteger i = 0; @try { while (1) { [a addObject:@"hi"]; i++; } } @catch (NSException * e) { NSLog(@"added %llu elements", i); } In most cases concerning the upper limits of programming

Passing array between view controllers?

大兔子大兔子 提交于 2019-11-28 11:51:19
I really need some more help! I am trying to pass an array from one view controller to another. I think the latter being a 'child' view controller? My code is as follows: MainViewController.h: #import <UIKit/UIKit.h> #import <AudioToolbox/AudioToolbox.h> #import <AVFoundation/AVFoundation.h> @interface HelloWorldIOS4ViewController : UIViewController <UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate, AVAudioPlayerDelegate> { NSMutableArray *countProductCode; UIPopoverController *detailViewPopover; } @property (nonatomic, retain) NSMutableArray *countProductCode; @property

Sorting in nsmutable array

被刻印的时光 ゝ 提交于 2019-11-28 11:05:12
问题 Suppose I have following data in my game. I have developed game in cocos2d. Name Score Sagar 10000 Amit 2000 Vishal 90 Above data is stored in plist file. Plist has an array as root. Within that there are 10 dictionary. Each dictionary has two values: String values - Name Number value - score When I use NSMutableArray *x=[[NSMutableArray alloc] initWithContentsOfFile:@"Sagar.plist"]; I want to sort this mutable array by score. Is it possible? 回答1: Use a sort descriptor: NSSortDescriptor *

Does NSArray copy objects?

北战南征 提交于 2019-11-28 10:52:13
When I make an NSArray using + [NSArray arrayWithObjects:] , does it copy those objects? If I release the objects after adding them to the array, will I run into problems? No, it doesn't copy them. It retains them. Yes, you can safely release the objects after adding them to the array. The docs , as always, spell this out very clearly: Arrays maintain strong references to their contents—in a managed memory environment, each object receives a retain message before its id is added to the array and a release message when it is removed from the array or when the array is deallocated. If you want a

Save NSArray of Class to cacheDirectory

最后都变了- 提交于 2019-11-28 10:26:50
问题 I'd like to NSArray of Class to the cacheDirectory. I've wrote as following, however it returns false. Could you tell me how to solve this problem? Thank you for your kindness. let paths2 = NSSearchPathForDirectoriesInDomains( .CachesDirectory, .UserDomainMask, true) let cachesPath: AnyObject = paths2[0] var cachedQuestions:NSArray = questions as NSArray let filePath = cachesPath.stringByAppendingPathComponent("CachedQuestions") class Dog { var id:Int? var name:String? init(id:Int, name

NSArray - check if objects are in an array?

左心房为你撑大大i 提交于 2019-11-28 10:00:03
问题 I have 2 arrays. One is a large static group of 600 objects, the other is a small varying group of 10 objects. I want to take any common objects between the two groups and put them in a new array. So lets say the large group contains 600 objects named 1 to 600. The smaller group contains 9 objects: 1, 2, 3, 4, 5, 6, a, b, c. I want to be able to create a new array that contains the objects 1, 2, 3, 4, 5, 6. What is the best way to do this? 回答1: Are you sure that you need NSArray s? For

Why can I send messages to a deallocated instance of NSArray?

被刻印的时光 ゝ 提交于 2019-11-28 09:29:50
问题 I just noticed a surprising behavior of NSArray , that's why I'm posting this question. I just added a method like: - (IBAction) crashOrNot { NSArray *array = [[NSArray alloc] init]; array = [[NSArray alloc] init]; [array release]; [array release]; } Theoretically this code will crash. But In my case it never crashed !!! I changed the NSArray with NSMutableArray but this time the app crashed. Why this happens, why NSArray not crashing and NSMutableArray crashes ? 回答1: In general, when you

How to perform binary search on NSArray?

眉间皱痕 提交于 2019-11-28 09:06:52
What is the simplest way to do a binary search on an (already) sorted NSArray ? Some potential ways I have spotted so far include: The use of CFArrayBSearchValues (mentioned here ) - would this work on an NSArray ? The method indexOfObject:inSortedRange:options:usingComparator: of NSArray assumes the array is sorted and takes an opts param of type NSBinarySearchingOptions - does this mean it performs a binary search? The docs just say: Returns the index, within a specified range, of an object compared with elements in the array using a given NSComparator block. Write my own binary search