nsdictionary

NSDictionary, NSArray, NSSet and efficiency

我的梦境 提交于 2019-11-30 05:25:12
I've got a text file, with about 200,000 lines. Each line represents an object with multiple properties. I only search through one of the properties (the unique ID) of the objects. If the unique ID I'm looking for is the same as the current object's unique ID, I'm gonna read the rest of the object's values. Right now, each time I search for an object, I just read the whole text file line by line, create an object for each line and see if it's the object I'm looking for - which is basically the most inefficient way to do the search. I would like to read all those objects into memory, so I can

Updating UIImage orientation metaData?

混江龙づ霸主 提交于 2019-11-30 05:15:50
Basic Task: update the EXIF orientation property for the metaData asociated with a UIImage. My problem is that I don't know where the orientation property is in all the EXIF info. Convoluted Background: I am changing the orientation of the image returned by imagePickerController:didFinishPickingMediaWithInfo: so I am thinking that I also need to update the metaData before saving the image with writeImageToSavedPhotosAlbum:(CGImageRef)imageRef metadata:(NSDictionary *)metadata . In other words, unless I change it, the metaData will contain the old/initial orientation and thus be wrong. The

Weak object in an NSDictionary?

こ雲淡風輕ζ 提交于 2019-11-30 04:47:26
I would like to store a zeroing weak reference to an object in a NSDictionary . This is for a reference to a parent NSDictionary , so I can crawl back up a large structure without searching. I can not use __weak here; even if my local reference is weak, the NSDictionary will store a strong reference to the object that was weakly referenced. And, of course, NSDictionary can't have nil objects. I'm on iOS, not Mac, so NSHashTable isn't available. And I only want one object to be weak; the rest should still be strong. (I'm going to post my answer, so I have something to mark as accepted if there

Adding keys to Nested NSDictionary

泄露秘密 提交于 2019-11-30 04:40:55
问题 I am having problems creating new keys for a Nested NSDictionary. Here's what I have done I have this kind of NSMutableDictionary NSMutableDictionary *Ga=[NSMutableDictionary dictionaryWithDictionary:@{@"Node1" :@{@"SubNode11" :@40,@"SubNode12":@30}}]; Which NSLogs as: Node1 = { SubNode11 = 40; SubNode12 = 30; }; Now to add another root key and a nested key I did this, [Ga setObject:@{@"SubNode21" : @555} forKey:@"Node2"]; Now the NSLog outputs: Node1 = { SubNode11 = 40; SubNode12 = 30; };

How do I convert swift Dictionary to NSDictionary

北慕城南 提交于 2019-11-30 03:00:29
问题 I'm trying to convert a [String : String] (a Swift Dictionary) to NSDictionary , for later use on a JSON library that produces a string var parcelDict = ["trackingNumber" : parcel.number, "dstCountry" : parcel.countryCode]; if (parcel.postalService != nil) { parcelDict["postalService"] = parcel.postalService; } var errorPtr: NSErrorPointer let dict: NSDictionary = parcelDict var data = NSJSONSerialization.dataWithJSONObject(dict, options:0, error: errorPtr) as NSData return NSString(data:

Saving enum values into a dictionary

∥☆過路亽.° 提交于 2019-11-30 01:47:27
How does one save an enum value to a dictionary? When I try the following enum someEnum { field0 = 0, field1 = 1, field2 = 2, }; enum someEnum someEnumObject; and I try to save it to a dictionary using [NSDictionary dictionaryWithObjectsAndKeys:] someEnumObject, @"enum", I get this warning: Semantic Issue: Incompatible integer to pointer conversion sending 'enum behaviour' to parameter of type 'id' Use the following to save it to dictionary, [NSNumber numberWithInt:enumValue], @"enum", And you can retrieve it as, enumValue = [[dictionary valueForKey:@"enum"] intValue]; Better use NSNumber

get values of particular key in nsdictionary

假如想象 提交于 2019-11-29 23:34:56
I saved the json parsing result in a dictionary which look like: { "statusCode":"200", "body":[ { "status":"success", "remarks":null } ], "data":[ "abcd":[ { "category":"a", "title":"b", "id":"24" }, { "category":"c", "title":"crd", "id":"65" }, { "category":"ds", "title":"sd", "id":"18" } ] }, { "efgh":[ { "category":"ds", "title":"sd", "id":"18" }, { "category":"sd", "title":"sd", "id":"1" } ] }, { "ijkl":[ { "category":"ds", "title":"sd", "id":"18" }, { "category":"sd", "title":"sd", "id":"1" } ] } ] } The data for key @"data" can be saved into an array by using NSMutableArray *getdata=[

Store selector as value in an NSDictionary

不羁岁月 提交于 2019-11-29 22:48:20
Is there a way to store a selector in an NSDictionary , without storing it as an NSString ? SEL is just a pointer, which you could store in an NSValue : NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys: [NSValue valueWithPointer:@selector(foo)], @"foo", nil]; To get the selector back, you can use: SEL aSel = [[dict objectForKey:@"foo"] pointerValue]; An alternative to Georg's solution would be to convert the selector into an NSString before storing it the NSDictionary: NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys: NSStringFromSelector(@selector(foo)), @"foo",

Modify Object in Array with Swift?

戏子无情 提交于 2019-11-29 22:32:06
问题 I have array: var arrDicContact = udContact.valueForKey("arrDicContact") as [NSDictionary] and i want to change one contact in array: for let dicx:NSDictionary in arrDicContact{ if (dic.valueForKey("name") as String) == selectedName{ //how to modify dic to newdic: dic = newdic } } i can use for loop with int i from 0 to arrDicContact.count-1. But it's so not exited... i like for loop (for...in...) So anybody help me! :) Tks a lot. 回答1: Assuming we have the array like this: var array:

Filtering NSArray of NSDictionary objects using NSPredicate

人走茶凉 提交于 2019-11-29 21:56:54
I have an NSArray of NSDictionary objects. I want to filter the array based on keys of the dictionaries using NSPredicate. I have been doing something like this: NSString *predicateString = [NSString stringWithFormat:@"%@ == '%@'", key, value]; NSPredicate *predicate = [NSPredicate predicateWithFormat:predicateString]; NSArray *filteredResults = [allResultsArray filteredArrayUsingPredicate:predicate]; This works fine if they key passed in is one-word: Color, Name, Age. But it doesn't work if the key is multi-word, like: Person Age, Person Name. Basically, any key that contains a space, it