nsset

NSSet containsObject Not Working?

99封情书 提交于 2019-12-25 05:08:09
问题 I am trying to check if the annotation exists before adding it to array. I can't figure out why [visibleAnnotations containsObject:annotation] always returns False. MKMapRect mRect = self.locationView.visibleMapRect; NSSet *visibleAnnotations =[self.locationView annotationsInMapRect:mRect]; NSLog(@"Annotation in Rect %@",visibleAnnotations); for(NSArray * obj in JSON){ coordinates.latitude=[[obj valueForKey:@"Latitude"] doubleValue]; coordinates.longitude=[[obj valueForKey:@"Longitude"]

iOS - Comparing 2 Arrays and Objects in an array - Logic Issue

你离开我真会死。 提交于 2019-12-24 21:49:31
问题 I have an NSArray which contains Person objects. This person object contains the following; > Name > Age > School > Address > Telephone_Number Later on i will be setting values to this person object, like person.Name=@"Jemmy"; (but i will not be setting other attributes, Age, School etc.). I have an NSArray called personArray , and it contains 1000 person object records in it. Now i need to Filter out all the objects that contains the Name Jemmy . How can i do this ? What i was thinking of

NSSet -member to check equality of NSValue

醉酒当歌 提交于 2019-12-23 15:03:09
问题 I have a NSSet containing many thousands of NSValue objects (wrapping CGPoints ). I would like to very quickly find if a given CGPoint value exists in the NSSet . It seems to me that the member: method of an NSSet might do the job here, except that it checks for equality using isEqual: . NSValue objects use isEqualToValue: , and so when I execute the code: [mySet member:valueToCheck]; it actually causes Xcode to crash. 1) Is there some way to use a custom equality check to make this work for

Objective c - NSMutableSet unique object property

前提是你 提交于 2019-12-18 04:35:16
问题 In my app I have a class Person with personId property. Now I need some data structure to hold a bunch of unique Person objects (unique = different personId) So I guess I should use NSMutableSet as my data structure, but how do I make the NSMutableSet compare the personId property when adding a person (so I won't add the same person more then ones)? My goal is to have a collection of unique persons all the time (even if I add two persons with the same id), I want that the NSMutableSet will do

NSCountedSet - get count of items in set

北慕城南 提交于 2019-12-17 19:45:10
问题 I have a array of info that has multiple Names that I want to match and count then move to a table view such as you would see on a messages app. I have reached to this point. Where I can log and see what I want but simply can not find any solution pulling that info from the set and placing into a tableview accordingly. example - (void)directMessagesReceived:(NSArray *)messages forRequest:(NSString *)connectionIdentifier{ for(NSDictionary *d in messages) { // NSLog(@"See Direct Messageges

How to display an NSSet in a UITableView?

♀尐吖头ヾ 提交于 2019-12-14 00:45:05
问题 How would you proceed to display the content of an NSSet in a UITableView ? As you know, the table view will ask for the element at a given row, but since the NSSet elements aren't ordered, this doesn't mix well. My current solution is to iterate through the NSSet until I reach the element at a given index, but this really doesn't feel right. You may ask why I don't use an NSArray instead. This is because I'm using Core Data, which uses NSSet s to store collection of elements. Any help would

Grab random entry in NSDictionary

纵然是瞬间 提交于 2019-12-12 14:42:27
问题 Is there a way to grab a totally random key in the NSDictionary? NSString *key = [enumeratorForKeysInDictionary nextObject]; I have this code which iterates over the dictionary in a non-random way. Should I add all the keys to an NSSet and then pull randomly from there? Is there a more efficient way to do this? 回答1: See this: NSArray *array = [dictionary allKeys]; int random = arc4random()%[array count]; NSString *key = [array objectAtIndex:random]; 回答2: NSArray* allKeys = [dictionary allKeys

Convert Swift Set to NSMutableSet

丶灬走出姿态 提交于 2019-12-12 12:16:40
问题 I can convert from NSMutableSet to Set no problem, but I'm running into problems when doing the reverse. E.g. this works: let nsSet = NSMutableSet(array: ["a", "b"]) let swiftSet = nsSet as! Set<String> But when I try: let nsSet2 = swiftSet as? NSMutableSet nsSet2 ends up being nil . 回答1: Looks like swift Sets need to be converted to NSSet first: let nsSet2 = NSMutableSet(set: set as NSSet) Or shorthand: let nsSet2 = NSMutableSet(set: set) Or to go from NSSet to Swift Set and back to NSSet:

How to save to and read from a NSObject

佐手、 提交于 2019-12-12 10:23:05
问题 I have two NSObject's. @interface Car : NSObject{ @property (strong) NSSet *cars; } and @interface Model : NSObject{ @property (strong) UIImage *picture; @property (strong) NSString *name; } Basically the object Car has a NSSet cars and each object of the NSSet cars has the properties picture and name. How can I relate this two NSObject's and how can I save a string or image to the Car NSSet using the properties of the Model NSObject. Thanks. 回答1: For easy adding or removing, your " cars "

Is NSSet faster than NSArray?

≯℡__Kan透↙ 提交于 2019-12-12 09:13:48
问题 i am new to iOS. Anyone know if NSSet are faster than NSArray ? Why wouldn't I always just use an NSArray ? Anyone explain me difference between NSSet and NSArray ? 回答1: NSSet is used to have unique objects. NSArray may have duplicate objects. NSSet is an unordered collection. NSArray is an ordered collection. NSArray is faster than NSSet for simply holding and iterating. As little as 50% faster for constructing and as much as 500% faster for iterating. if you only need to iterate contents,