nsdictionary

ios - convert NSArray to NSDictionary

安稳与你 提交于 2019-12-13 04:19:21
问题 i want to convert an nsarray to nsdictionary i'm using to - (NSDictionary *) indexKeyedDictionaryFromArray:(NSArray *)array { id objectInstance; NSUInteger indexKey = 0; NSMutableDictionary *mutableDictionary = [[NSMutableDictionary alloc] init]; for (objectInstance in array) [mutableDictionary setObject:objectInstance forKey:[NSNumber numberWithUnsignedInt:indexKey++]]; return (NSDictionary *)[mutableDictionary autorelease]; } output result is: { 0 = { Event = ""; ID = 1; }; 3 = { Event = ""

Incorrectly parse json into NSDictionary

独自空忆成欢 提交于 2019-12-13 03:35:50
问题 I am trying store text fields data into a NSDictionary from json. I have used SBJson for this. { "fields":[ { "textFields":[ { "text":"Congratulations", "textSize":"12" }, { "text":"Best Wishes", "textSize":"15" }, { "text":"Test text", "textSize":"10" } ] }, { "imageFields":[ { "image":"test1.jpg", "width":"200", "height":"100" }, { "image":"test2.jpg", "width":"200", "height":"100" } ] } ] } My code: -(void)readJson{ NSDictionary *jsonDict = [jsonString JSONValue]; NSDictionary *fieldsDict

How to Upload NSDictionary in Memory to Dropbox, IOS

喜你入骨 提交于 2019-12-13 01:17:52
问题 I have an xml string that I want to upload as a .plist to a dropbox folder. Currently I create a NSDictionary and create a temp folder, I write dictionary as a plist to that temp folder and upload that .plist in that temp folder to dropbox. Which is I guess not a good programming solution; This works ok if([title isEqualToString:@"Upload to Dropbox"]) { //pass string in memory to nsdictionary NSData * data = [_uploadPlistString dataUsingEncoding:NSUTF8StringEncoding]; NSString *errorDesc =

Sort NSDates inside NSDictionary inside NSArray?

梦想的初衷 提交于 2019-12-13 01:14:33
问题 Currently in my app I have a NSArray that I load from NSUserDefaults. Each object in the NSArray is a NSDictionary that has about 5 different keys. I am re-order the NSDictionarys themselves based upon the NSDates inside of them. I do not want to sort the NSDates alone. I have tried to do this with this code: NSComparator sortByDate = ^(id dict1, id dict2) { NSDate* n1 = [dict1 objectForKey:@"Date"]; NSDate* n2 = [dict2 objectForKey:@"Date"]; return (NSComparisonResult)[n1 compare:n2]; };

How do I get out data from my NSDirectory (not just a property typo)?

雨燕双飞 提交于 2019-12-13 00:30:05
问题 I'm missing something simple I think, but been at it for days now without solving this. Even Started to create a "work-around" just to solve it for now, but still want to solve this the "right" way. Any suggestions? Thank's! . The problem: Seems to be missing the class Adealer (get error "-[Adealer objectAtIndex:]: unrecognized selector sent to instance 0x8c5f8b0"), but I did the import Adealer.h to this "detailsVC". But it's not just a simple error of naming the property wrong ( objectForKey

Initializing NSMutableDictionary

二次信任 提交于 2019-12-13 00:17:49
问题 I'm trying to create a filter. I have a function that returns an NSArray for the different categories I can have. I'd like one extra option for "All" to denote that no filter is being applied. For example, should display: All Soda Wine Beer I started with this, but I don't think it's very good implementation at all, and it's not correct either. It's just where I'm at so far: - (void)initCategoryDictionary { NSMutableArray *conditionCategories = (NSMutableArray *)[self GetAllCategories];

-[NSDictionary initWithObjects:forKeys:]: count of objects (0) differs from count of keys (2)

自作多情 提交于 2019-12-12 18:23:21
问题 I am getting the error of -[NSDictionary initWithObjects:forKeys:]: count of objects (0) differs from count of keys (2)' here is my code in saving the plist. @interface setting : UIViewController{ UIDatePicker *datePicker; IBOutlet UILabel * morningtime; UIDatePicker *afternoonpicker; NSString*morningtime1; NSString*afternoontime1; IBOutlet UILabel *afternoontime; } @property (nonatomic,retain) IBOutlet UIDatePicker *datePicker; @property (strong, nonatomic) IBOutlet UIDatePicker

Search String in NSDictionary store in NSMutableArray

浪尽此生 提交于 2019-12-12 17:03:58
问题 I am trying to search a String in NSDictionary stored in NSMutableArray for (int k = 0; k < [onlyActiveArr count]; k++) { NSString *localID = [onlyActiveArr objectAtIndex:k]; NSLog(@"%@",localID); int localIndex = [onlyActiveArr indexOfObject:localActiveCallID]; NSLog(@"%d",localIndex); for (NSDictionary *dict in self.SummaryArr) { NSLog(@"%@",[dict objectForKey:@"ActiveID"]); if (![[dict objectForKey:@"ActiveID"] isEqualToString:localID]) { NSLog(@"found such a key, e.g. %@",localID); } } }

Swift read data from NSDictionary

不打扰是莪最后的温柔 提交于 2019-12-12 15:41:15
问题 I am using this code to read data from NSDictionary : let itemsArray: NSArray = response.objectForKey("items") as! NSArray; let nextPageToken: String = response.objectForKey("nextPageToken") as! String var videoIdArray: [String] = [] for (item) in itemsArray { let videoId: String? = item.valueForKey("id")!.valueForKey("videoId") as? String videoIdArray.append(videoId!) } But when i items or nextPageToken are not exist i get this error: fatal error: unexpectedly found nil while unwrapping an

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