Search Results

Search found 190 results on 8 pages for 'nsmutabledictionary'.

Page 1/8 | 1 2 3 4 5 6 7 8  | Next Page >

  • NSMutableDictionary is being treated as an NSDictionary

    - by Marc Gelfo
    Hi, I have a simple class with an NSMutableDictionary member variable. However, when I call setObject:forKey I get an error ('mutating method sent to immutable object'). The source of the problem is obvious from the debugger -- my NSMutableDictionary is actually of type NSDictionary. I must be missing something incredibly simple but can't seem to fix it. Here is the relevant code: // Model.h @interface Model : NSObject { NSMutableDictionary *piers; } @property (nonatomic,retain) NSMutableDictionary *piers; @end // Model.m @implementation Model @synthesize piers; -(id) init { if (self = [super init]) { self.piers = [[NSMutableDictionary alloc] initWithCapacity:2]; [self createModel]; } return self; } -(void) createModel { [piers setObject:@"happy" forKey:@"foobar"]; } @end If I put a breakpoint anywhere in the code and investigate self.piers, it is of type NSDictionary. What am I missing so that it is treated as an NSMutableDictionary instead? Thanks!

    Read the article

  • Issue passing NSMutableDictionary to a method

    - by roswell
    Hello all, I've got a chunk of code that's passing an NSMutableDictionary (amongst other things) to a method in another class: [self.shuttle makeAPICallAndReturnResultsUsingMode:@"login" module:@"login" query:credentials]; The NSMutableArray credentials is previously defined like this: NSMutableDictionary *credentials = [[NSMutableDictionary alloc] init]; [credentials setObject:username forKey:@"username"]; [credentials setObject:password forKey:@"password"]; The method that receives it looks like this: -(id)makeAPICallAndReturnResultsUsingMode:(NSString *)mode module:(NSString *)module query:(NSMutableDictionary *)query The code works fine up until this point within the above method: [query setObject:self.sessionID forKey:@"session_id"]; At this point, the application terminates -- the console informs me of this exception: * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[NSCFDictionary setObject:forKey:]: method sent to an uninitialized mutable dictionary object' This leads me to believe that I must initialize NSMutableDictionary in some way in my new method before I can access it, but I have no idea how. Any advice?

    Read the article

  • Issue Passing NSMutableDictionary to Method

    - by roswell
    Hello all, I'm trying some basic iPhone programming -- all has been going well but recently I've hit a bit of a roadblock. I've got a chunk of code that's passing an NSMutableDictionary (amongst other things) to a method in another class: [self.shuttle makeAPICallAndReturnResultsUsingMode:@"login" module:@"login" query:credentials]; The NSMutableArray credentials is previously defined a bit above as such: NSMutableDictionary *credentials = [[NSMutableDictionary alloc] init]; [credentials setObject:username forKey:@"username"]; [credentials setObject:password forKey:@"password"]; The method that receives it looks like such: -(id)makeAPICallAndReturnResultsUsingMode:(NSString *)mode module:(NSString *)module query:(NSMutableDictionary *)query From debugging I have determined that the code works fine up until this point within the above method: [query setObject:self.sessionID forKey:@"session_id"]; At this point, the application terminates -- the Console informs me of this exception: * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[NSCFDictionary setObject:forKey:]: method sent to an uninitialized mutable dictionary object' This leads me to believe that I must initialize NSMutableDictionary in some way in my new method before I can access it, but I have no idea how. Any advice?

    Read the article

  • Objective-C NSMutableDictionary Disappearing

    - by blackmage
    I am having this problem with the NSMutableDictionary where the values are not coming up. Snippets from my code look like this: //Data into the Hash and then into an array yellowPages = [[NSMutableArray alloc] init]; NSMutableDictionary *address1=[[NSMutableDictionary alloc] init]; [address1 setObject:@"213 Pheasant CT" forKey: @"Street"]; [address1 setObject:@"NC" forKey: @"State"]; [address1 setObject:@"Wilmington" forKey: @"City"]; [address1 setObject:@"28403" forKey: @"Zip"]; [address1 setObject:@"Residential" forKey: @"Type"]; [yellowPages addObject:address1]; NSMutableDictionary *address2=[[NSMutableDictionary alloc] init]; [address1 setObject:@"812 Pheasant CT" forKey: @"Street"]; [address1 setObject:@"NC" forKey: @"State"]; [address1 setObject:@"Wilmington" forKey: @"City"]; [address1 setObject:@"28403" forKey: @"Zip"]; [address1 setObject:@"Residential" forKey: @"Type"]; [yellowPages addObject:address2]; //Iterate through array pulling the hash and insert into Location Object for(int i=0; i<locationCount; i++){ NSMutableDictionary *anAddress=[theAddresses getYellowPageAddressByIndex:i]; //Set Data Members Location *addressLocation=[[Location alloc] init]; addressLocation.Street=[anAddress objectForKey:@"Street"]; locations[i]=addressLocation; NSLog(addressLocation.Street); } So the problem is only the second address is printed, the 813 and I can't figure out why. Can anyone offer any help?

    Read the article

  • How to use NSMutableDictionary to store and retrieve data

    - by TechFusion
    I have created Window Based application and tab bar controller as root controller. My objective is to store Text Field data values in one tab bar VC and will be accessible and editable by other VC and also retrievable when application start. I am looking to use NSMutableDictionary class in AppDelegate so that I can access stored Data Values with keys. //TestAppDelegate.h extern NSString *kNamekey ; extern NSString *kUserIDkey ; extern NSString *kPasswordkey ; @interface TestAppDelegate :NSObject{ UIWindow *window; IBOutlet UITabBarController *rootController; NSMutableDictionary *outlineData ; } @property(nonatomic,retain)IBOutlet UIWindow *window; @property(nonatomic,retain)IBOutlet UITabBarController *rootController; @property(nonatomic,retain) NSMutableDictionary *outlineData ; @end //TestAppDelegate.m import "TestAppDelegate.h" NSString *kNamekey =@"Namekey"; NSString *kUserIDkey =@"UserIDkey"; NSString *kPasswordkey =@"Passwordkey"; @implemetation TestAppDelegate @synthesize outlineData ; -(void)applicationDidFinishLaunching:(UIApplication)application { NSMutableDictionary *tempMutableCopy = [[[NSUserDefaults standardUserDefaults] objectForKey:kRestoreLocationKey] mutableCopy]; self.outlineData = tempMutableCopy; [tempMutableCopy release]; if(outlineData == nil){ NSString *NameDefault = NULL; NSString *UserIDdefault= NULL; NSString *Passworddefault= NULL; NSMutableDictionary *appDefaults = [NSMutableDictionary dictionaryWithObjectsAndKeys: NameDefault, kNamekey , UserIDdefault, kUserIDkey , Passworddefault, kPasswordkey , nil]; self.outlineData = appDefaults; [appDefaults release]; } [window addSubview:rootController.view]; [window makeKeyAndVisible]; NSMutableDictionary *savedLocationDict = [NSMutableDictionary dictionaryWithObject:outlineData forKey:kRestoreLocationKey]; [[NSUserDefaults standardUserDefaults] registerDefaults:savedLocationDict]; [[NSUserDefaults standardUserDefaults] synchronize]; } -(void)applicationWillTerminate:(UIApplication *)application { [[NSUserDefaults standardUserDefaults] setObject:outlineData forKey:kRestoreLocationKey]; } @end Here ViewController is ViewController of Navigation Controller which is attached with one tab bar.. I have attached xib file with ViewController //ViewController.h @interface IBOutlet UITextField *Name; IBOutlet UITextField *UserId; IBOutlet UITextField *Password; } @property(retain,nonatomic) IBOutlet UITextField *Name @property(retain,nonatomic) IBOutlet UITextField *UserId; @property(retain,nonatomic) IBOutlet UITextField *Password; -(IBAction)Save:(id)sender; @end Here in ViewController.m, I am storing object values with keys. /ViewController.m -(IBAction)Save:(id)sender{ TestAppDelegate appDelegate = (TestAppDelegate)[[UIApplication sharedApplication] delegate]; [appDelegate.outlineData setObject:Name.text forKey:kNamekey ]; [appDelegate.outlineData setObject:UserId.text forKey:kUserIDkey ]; [appDelegate.outlineData setObject:Password.text forKey:kPasswordkey]; [[NSUserDefaults standardUserDefaults] synchronize]; } I am accessing stored object using following method. -(void)loadData { TabBarAppDelegate *appDelegate = (TabBarAppDelegate *)[[UIApplication sharedApplication] delegate]; Name = [appDelegate.outlineData objectForKey:kNamekey ]; UserId = [appDelegate.outlineData objectForKey:kUserIDkey ]; Password = [appDelegate.outlineData objectForKey:kPasswordkey]; [Name release]; [UserId release]; [Password release]; } I am getting EXEC_BAD_ACCESS in application. Where I am making mistake ? Thanks,

    Read the article

  • NSMutableDictionary withcontentofURL

    - by user347741
    Hi, I want to fill a NSMutableDictionary with content out of a URL File. What type file must it be and how must it be structured? NSMutableDictionary *myMutableDictionary = [[NSMutableDictionary alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://example.com/list.txt"]]; Thanks, Nostradamus

    Read the article

  • NSArrayController not working with NSMutableDictionary for NSTableView

    - by Miraaj
    Hi all, I am trying to display content in NSTableView using NSMutableArrayController of NSMutableDictionary records. I followed steps written below: In application delegate class, I created an NSMutableArray object with name 'geniuses' and stored some NSMutableDictionary objects with keys: 'geniusName' and 'domain'. I took an NSArrayController object in IB, binded its controller content property to application delegate class, and set its model key path to 'geniuses'. In attribute inspector pane set mode as class and class name as NSMutableDictionary. Added keys: 'geniusName' and 'domain' to it. In IB I took a table view object. Binded its content property to array controller, controller key path set as arranged objects. Binded value property of its first column to array controller, controller key path set as arranged objects, model key path set as 'geniusName'. Binded value property of its second column to array controller, controller key path set as arranged objects, model key path set as 'geniusName'. After following these steps when I tried to build and run the project I found un-populated table view. You can find my code here. Can anyone suggest me where I may be wrong? Thanks, Miraaj

    Read the article

  • NSMutableDictionary, alloc, init and reiniting...

    - by Marcos Issler
    In the following code: //anArray is a Array of Dictionary with 5 objs. //here we init with the first NSMutableDictionary *anMutableDict = [[NSMutableDictionary alloc] initWithDictionary:[anArray objectAtIndex:0]]; ... use of anMutableDict ... //then want to clear the MutableDict and assign the other dicts that was in the array of dicts for (int i=1;i<5;i++) { [anMutableDict removeAllObjects]; [anMutableDict initWithDictionary:[anArray objectAtIndex:i]]; } Why this crash? How is the right way to clear an nsmutabledict and the assign a new dict? Thanks guy's. Marcos.

    Read the article

  • iPhone NSMutableDictionary setObject forKey after initWithContentsOfFile

    - by andrew
    so here's my function + (void) AddAddress:(NSString*)ip:(NSString*)mac { NSMutableDictionary* currentAddresses = [[NSMutableDictionary alloc] initWithContentsOfFile:[self filePath:ADDRESSES_FILE]]; [currentAddresses setObject:mac forKey:ip]; [Configuration Write:currentAddresses]; [currentAddresses release]; } [self filePath:ADDRESSES_FILE] returns a string containing the full path of a file (ADDRESSES_FILE) located in the Documents. The file may not exist, in this case I want to just write an object to the dictionary and then write it down the problem is that when i do setObject forKey it doesn't add anything to the dict (if i just do alloc init to the dict, it works fine, but i want to read the records from the file, if there are any, and replace/add a record by using the AddAddress function)

    Read the article

  • NSMutableDictionary memory / address problem, release does not work?

    - by phil
    I am trying to create a NSMutableDictionary(dictA) with objectA. When I try to view my dictionary(NSLog), each key is pointing to the same address. I have an objectA_1 which is type objectA and used to setup the dictionary. Also, if I try to getObject, I always get the last key/value that was added to the dictionary. I tried setValue and got the same results. Is there something wrong with my objectA? Is the release method not working properly? Am I retaining when I shouldn't? Thank you. dictA = [[NSMutableDictionary alloc] init]; objectA *objectA = [[objectA alloc] init]; [dictA setObject:objectA_1 forKey:@"apple"]; [objectA_1 release]; [dictA setObject:objectA_1 forKey:@"japan"]; [objectA_1 release]; [dictA setObject:objectA_1 forKey:@"paris"]; [objectA_1 release]; [dictA setObject:objectA_1 forKey:@"pizza"]; [objectA_1 release]; //NSlog: apple = ""; japan = ""; paris = ""; pizza = "";

    Read the article

  • NSMutableDictionary with UIButton* as keys - iPhone development

    - by Alejandro A.
    Hi, I'm new to iPhone development and I have a question that may have a very simple answer. I am trying to add buttons to a view and these buttons are associated with a custom class that I defined. When I add the buttons to the view, I would like to know what class these buttons correspond to. This is because when I press the button, I need to get some information about the class, but the receiver of the message is another class. I couldn't find information about an error that I'm getting on the web. The problem I have is that I'm trying to create an NSMutableDictionary where the keys are of type UIButton* and the values are of my custom type: // create button for unit UIButton* unitButton = [[UIButton alloc] init]; [sourceButtonMap setObject:composite forKey:unitButton]; Of course, the sourceButtonMap is defined in the class and initialized in the init function as sourceButtonMap = [[NSMutableDictionary alloc] init]; The error I get when I try to add the key-value pair is: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UIButton copyWithZone:]: unrecognized selector sent to instance 0x3931e90' Is this happening because I can't store UIButton* as keys? Can anyone point me why I'm getting this error? Thank you all, aa

    Read the article

  • pulling a value from NSMutableDictionary

    - by Jared Gross
    I have a dictionary array with a key:@"titleLabel". I am trying to load a pickerView with ONE instance of each @"titleLabel" key so that if there are multiple objects with the same @"titleLabel" only one title will be displayed. I've done some research on this forum and looked at apples docs but haven't been able to put the puzzle together. Below is my code but I am having trouble pulling the values. Right now when I run this code it throws an error Incompatible pointer types sending 'PFObject *' to parameter of type 'NSString' which i understand but am just not sure how to remedy. Cheers! else { // found messages! self.objectsArray = objects; NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; for(id obj in self.objectsArray){ PFObject *key = [self.objectsArray valueForKey:@"titleLabel"]; if(![dict objectForKey:@"titleLabel"]){ [dict setValue:obj forKey:key]; } } for (id key in dict) { NSLog(@"Objects array is %d", [self.objectsArray count]); NSLog(@"key: %@, value: %@ \n", key, [dict objectForKey:key]); } [self.pickerView reloadComponent:0]; } }];` Here is where I define the PFObject and keys: PFObject *image = [PFObject objectWithClassName:@"Images"]; [image setObject:file forKey:@"file"]; [image setObject:fileType forKey:@"fileType"]; [image setObject:title forKey:@"titleLabel"]; [image setObject:self.recipients forKey:@"recipientIds"]; [image setObject:[[PFUser currentUser] objectId] forKey:@"senderId"]; [image setObject:[[PFUser currentUser] username] forKey:@"senderName"]; [image saveInBackground];

    Read the article

  • Modifying NSMutableDictionary from a single index format into nested (array within array)

    - by Michael Robinson
    I need to take the member ID off the top of this and create an array inside that contains the rest of the JSON return. Here is my JSON return. [{"F_Name_VC":"Frank", "L_Name_VC":"Johnson", "userid":"18", "age":"23", },] After it is json-deserialized it looks like this: I need convert it to be transformed into this, with children sub-array: Someone else posted a similar question but without the fact that it was coming from a JSON deserialization. There were two answers but no conclusion to the question. (Answer 1): NSDictionary *item1 = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@" member",[NSNumber numberWithInt:3],nil] forKeys:[NSArray arrayWithObjects:@"Title",@"View",nil]]; Answer (2): NSMutableArray *Rows = [NSMutableArray arrayWithCapacity: 1]; for (int i = 0; i < 4; ++i) { NSMutableArray *theChildren = [NSMutableArray arrayWithCapacity: 1]; [theChildren addObject: [NSString stringWithFormat: @"tester %d", i]]; NSString *aTitle = [NSString stringWithFormat: @"Item %d", i]; NSDictionary *anItem = [NSDictionary dictionaryWithObjectsAndKeys: aTitle, @"Title", theChildren, @"Children"]; [Rows addObject: anItem]; } NSDictionary *Root = [NSDictionary withObject: Rows andKey: @"Rows"]; Here is my JSON return and save code: NSData *jsonData = [jsonreturn dataUsingEncoding:NSUTF32BigEndianStringEncoding]; NSError *error = nil; NSDictionary * dict = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error]; if (dict) { rowsArray = [dict objectForKey:@"member"]; [rowsArray retain]; } Thanks in advance. Every tutorial on JSON only shows a simple array being returned, never with children..It's driving me crazy trying to figure this out.

    Read the article

  • how do we access values stored in NSMutableArray of NSMutableDictionary ?

    - by srikanth rongali
    I have stored values in NsMutableDictionaries . ThenI stored all the dictionaries in NSMutable Array. I need to access the values ? How can I do that ? -(void)viewDidLoad { [super viewDidLoad]; self.title = @"Library"; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Close" style:UIBarButtonItemStyleBordered target:self action:@selector(close:)]; cells = [[NSMutableArray alloc] initWithObjects:@"dict1", @"dict2", @"dict3", @"dict4", @"dict5", @"dict6", nil]; dict1 = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Mon, 01 Feb #2", @"date", @"0.7", @"time", @"1.2MB", @"size", @"200*200", @"pix", nil]; dict2 = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Wed, 02 Mar #3", @"date", @"1.2", @"time", @"2.2MB", @"size", @"300*300", @"pix", nil]; dict3 = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Tue, 03 Apr #5", @"date", @"1.7", @"time", @"2.5MB", @"size", @"240*240", @"pix", nil]; dict4 = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Mon, 01 Feb #2", @"date", @"0.7", @"time", @"1.2MB", @"size", @"200*200", @"pix", nil]; dict5 = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Mon, 10 Nov #5", @"date", @"2.7", @"time", @"4.2MB", @"size", @"200*400", @"pix", nil]; dict6 = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Mon, 11 Dec #6", @"date", @"4.7", @"time", @"2.2MB", @"size", @"500*200", @"pix", nil]; //[cells addObject:dict1]; //[cells addObject:dict2]; //[cells addObject:dict3]; //[cells addObject:dict4]; //[cells addObject:dict5]; //[cells addObject:dict6]; } // Customize the number of rows in the table view. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [cells count]; } // Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; //cell.contentView.frame = CGRectMake(0.0f, 0.0f, 320.0f, 80.0f); [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator]; UIImageView *image1 = [[UIImageView alloc]init]; image1.frame = CGRectMake(0.0f, 0.0f, 80.0f, 80.0f); image1.tag = tag7; UILabel *dateLabel = [[UILabel alloc]init]; dateLabel.frame = CGRectMake(100.0f, 5.0f, 120.0f, 25.0f); dateLabel.font = [UIFont fontWithName:@"Georgia" size:10]; dateLabel.tag = tag1; UILabel *timeLabel = [[UILabel alloc] init]; timeLabel.frame = CGRectMake(100.0f, 30.0f, 40.0f, 25.0f); timeLabel.font = [UIFont fontWithName:@"Georgia" size:10]; timeLabel.tag = tag2; UILabel *sizeLabel = [[UILabel alloc] init]; sizeLabel.frame = CGRectMake(160.0f, 30.0f, 40.0f, 25.0f); sizeLabel.font = [UIFont fontWithName:@"Georgia" size:10]; sizeLabel.tag = tag3; UILabel *pixLabel = [[UILabel alloc] init]; pixLabel.frame = CGRectMake(220.0f, 30.0f, 40.0f, 25.0f); pixLabel.font = [UIFont fontWithName:@"Georgia" size:10]; pixLabel.tag = tag4; UILabel *shareLabel = [[UILabel alloc] init]; shareLabel.frame = CGRectMake(100.0f, 55.0f, 100.0f, 25.0f); shareLabel.font = [UIFont fontWithName:@"Georgia" size:10]; shareLabel.tag = tag5; UILabel *deleteLabel = [[UILabel alloc] init]; deleteLabel.frame = CGRectMake(220.0f, 55.0f, 100.0f, 25.0f); deleteLabel.font = [UIFont fontWithName:@"Georgia" size:10]; deleteLabel.tag = tag6; [cell.contentView addSubview:dateLabel]; [cell.contentView addSubview:timeLabel]; [cell.contentView addSubview:sizeLabel]; [cell.contentView addSubview:pixLabel]; [cell.contentView addSubview:shareLabel]; [cell.contentView addSubview:deleteLabel]; [cell.contentView addSubview:image1]; [dateLabel release]; [timeLabel release]; [sizeLabel release]; [pixLabel release]; [shareLabel release]; [deleteLabel release]; [image1 release]; } // Set up the cell... [(UILabel *)[cell viewWithTag:tag1] setText:[cells objectAtIndex:[dict1 objectForKey: @"date"]]]; [(UILabel *)[cell viewWithTag:tag2] setText:[cells objectAtIndex:[dict1 objectForKey: @"time"]]]; [(UILabel *)[cell viewWithTag:tag3] setText:[cells objectAtIndex:[dict1 objectForKey: @"size"]]]; [(UILabel *)[cell viewWithTag:tag4] setText:[cells objectAtIndex:[dict1 objectForKey: @"pix"]]]; [(UILabel *)[cell viewWithTag:tag5] setText:@"Share"]; [(UILabel *)[cell viewWithTag:tag6] setText:@"Delete"]; cell.imageView.image = [UIImage imageNamed:@"image2.png"]; return cell; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 80.0f; } I did in above way but it is not working. I know the mistake is at the accessing values. but, I could not get how to do it ? Thank You.

    Read the article

  • Public class: The best way to store and access NSMutableDictionary?

    - by meridimus
    I have a class to help me store persistent data across sessions. The problem is I want to store a running sample of the property list or "plist" file in an NSMutableArray throughout the instance of the Persistance class so I can read and edit the values and write them back when I need to. The problem is, as the methods are publicly defined I cannot seem to access the declared NSMutableDictionary without errors. The particular error I get on compilation is: warning: 'Persistence' may not respond to '+saveData' So it kind of renders my entire process unusable until I work out this problem. Here is my full persistence class (please note, it's unfinished so it's just to show this problem): Persistence.h #import <UIKit/UIKit.h> #define kSaveFilename @"saveData.plist" @interface Persistence : NSObject { NSMutableDictionary *saveData; } @property (nonatomic, retain) NSMutableDictionary *saveData; + (NSString *)dataFilePath; + (NSDictionary *)getSaveWithCampaign:(NSUInteger)campaign andLevel:(NSUInteger)level; + (void)writeSaveWithCampaign:(NSUInteger)campaign andLevel:(NSUInteger)level withData:(NSDictionary *)saveData; + (NSString *)makeCampaign:(NSUInteger)campaign andLevelKey:(NSUInteger)level; @end Persistence.m #import "Persistence.h" @implementation Persistence @synthesize saveData; + (NSString *)dataFilePath { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; return [documentsDirectory stringByAppendingPathComponent:kSaveFilename]; } + (NSDictionary *)getSaveWithCampaign:(NSUInteger)campaign andLevel:(NSUInteger)level { NSString *filePath = [self dataFilePath]; if([[NSFileManager defaultManager] fileExistsAtPath:filePath]) { NSLog(@"File found"); [[self saveData] setDictionary:[[NSDictionary alloc] initWithContentsOfFile:filePath]]; // This is where the warning "warning: 'Persistence' may not respond to '+saveData'" occurs NSString *campaignAndLevelKey = [self makeCampaign:campaign andLevelKey:level]; NSDictionary *campaignAndLevelData = [[self saveData] objectForKey:campaignAndLevelKey]; return campaignAndLevelData; } else { return nil; } } + (void)writeSaveWithCampaign:(NSUInteger)campaign andLevel:(NSUInteger)level withData:(NSDictionary *)saveData { NSString *campaignAndLevelKey = [self makeCampaign:campaign andLevelKey:level]; NSDictionary *saveDataWithKey = [[NSDictionary alloc] initWithObjectsAndKeys:saveData, campaignAndLevelKey, nil]; //[campaignAndLevelKey release]; [saveDataWithKey writeToFile:[self dataFilePath] atomically:YES]; } + (NSString *)makeCampaign:(NSUInteger)campaign andLevelKey:(NSUInteger)level { return [[NSString stringWithFormat:@"%d - ", campaign+1] stringByAppendingString:[NSString stringWithFormat:@"%d", level+1]]; } @end I call this class like any other, by including the header file in my desired location: @import "Persistence.h" Then I call the function itself like so: NSDictionary *tempSaveData = [[NSDictionary alloc] [Persistence getSaveWithCampaign:currentCampaign andLevel:currentLevel]];

    Read the article

  • Core Data Relationship problem

    - by awattar
    I have a very simple model with two objects: Name and Category. One Name can be in many Categories (it's one way relationship). I'm trying to create 8 Categories every with 8 Names. Example code: NSMutableArray *localArray = [NSMutableArray arrayWithObjects: [NSMutableDictionary dictionaryWithObjectsAndKeys: @"g1", @"Name", @"g1", @"Icon", [NSNumber numberWithBool:YES] , @"Male", nil], [NSMutableDictionary dictionaryWithObjectsAndKeys: @"g2", @"Name", @"g2", @"Icon", [NSNumber numberWithBool:YES] , @"Male", nil], [NSMutableDictionary dictionaryWithObjectsAndKeys: @"g3", @"Name", @"g3", @"Icon", [NSNumber numberWithBool:YES] , @"Male", nil], [NSMutableDictionary dictionaryWithObjectsAndKeys: @"g4", @"Name", @"g4", @"Icon", [NSNumber numberWithBool:YES] , @"Male", nil], [NSMutableDictionary dictionaryWithObjectsAndKeys: @"g5", @"Name", @"g5", @"Icon", [NSNumber numberWithBool:YES] , @"Male", nil], [NSMutableDictionary dictionaryWithObjectsAndKeys: @"g6", @"Name", @"g6", @"Icon", [NSNumber numberWithBool:YES] , @"Male", nil], [NSMutableDictionary dictionaryWithObjectsAndKeys: @"g7", @"Name", @"g7", @"Icon", [NSNumber numberWithBool:YES] , @"Male", nil], [NSMutableDictionary dictionaryWithObjectsAndKeys: @"g8", @"Name", @"g8", @"Icon", [NSNumber numberWithBool:YES] , @"Male", nil], nil]; NSMutableArray *localArray2 = [NSMutableArray arrayWithObjects: [NSMutableDictionary dictionaryWithObjectsAndKeys: @"Test1", @"Name", nil], [NSMutableDictionary dictionaryWithObjectsAndKeys: @"Test2", @"Name", nil], [NSMutableDictionary dictionaryWithObjectsAndKeys: @"Test3", @"Name", nil], [NSMutableDictionary dictionaryWithObjectsAndKeys: @"Test4", @"Name", nil], [NSMutableDictionary dictionaryWithObjectsAndKeys: @"Test5", @"Name", nil], [NSMutableDictionary dictionaryWithObjectsAndKeys: @"Test6", @"Name", nil], [NSMutableDictionary dictionaryWithObjectsAndKeys: @"Test7", @"Name", nil], [NSMutableDictionary dictionaryWithObjectsAndKeys: @"Test8", @"Name", nil], nil]; NSError *error; NSManagedObjectContext *moc = [(AppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext]; for(NSMutableDictionary *item in localArray) { NSManagedObject *category = [NSEntityDescription insertNewObjectForEntityForName:@"Category" inManagedObjectContext:managedObjectContext]; [category setValue:[item objectForKey:@"Name"] forKey:@"Name"]; [category setValue:[item objectForKey:@"Icon"] forKey:@"Icon"]; [category setValue:[item objectForKey:@"Male"] forKey:@"Male"]; for(NSMutableDictionary *item2 in localArray2) { NSManagedObject *name = [NSEntityDescription insertNewObjectForEntityForName:@"Name" inManagedObjectContext:managedObjectContext]; [name setValue:[item2 objectForKey:@"Name"] forKey:@"Name"]; [[name mutableSetValueForKey:@"CategoryRelationship"] addObject:category]; } } [moc save:&error]; And here's a problem - i've checked that 8 Categories are saved, 64 Names are saved but only 8 from all Names are connected with any category. So when i query for Names in Categories [NSPredicate predicateWithFormat:@"CategoryRelationship.@count != 0"] there are 8 elements and when [NSPredicate predicateWithFormat:@"CategoryRelationship.@count = 0"] there are 56 elements. What is going one here?

    Read the article

  • NSMutableDictionary is adding quotes to keys and values - why?

    - by TimD
    I'm trying to add some additional key/value pairs to an NSMutableDictionary, using: Tag *tag1 = [results1 objectAtIndex:0]; [resultsDict setObject:[tag1 retrieveTextUpToDepth:1] forKey:@"image_url"]; Tag *tag2 = [results2 objectAtIndex:0]; [resultsDict setValue:[tag2 retrieveTextUpToDepth:1] forKey:@"majority"]; This adds the k/v pairs with no problem, except when I come to retrieve them, some of the values have been wrapped with double quotes: po extendedDataDictionary: "image_url" = "/images/mpsL/11727.jpeg"; majority = 3460; Both keys and values are NSStrings, with no quotes - so I'm stumped as to where they're appearing from. Is there any way of preventing this? Or am I going to have to live with it and try to strip off the quotes once I've retrieved the value? Thanks...

    Read the article

  • How to update NSMutableDictionary. My code doesn't work.

    - by dawatson833
    I've populated an array using. arrSettings = [[NSMutableArray alloc] initWithContentsOfFile:[self settingsPath]]; The file is a plist with the root as an array and then a dictionary with three three keys defined as number. I've also tried setting the keys to string. I display the values in the plist file on a view using. diaper = [[arrSettings objectAtIndex:0] objectForKey:@"Diaper Expenses"]; oil = [[arrSettings objectAtIndex:0] objectForKey:@"Oil Used"]; tree = [[arrSettings objectAtIndex:0] objectForKey:@"Wood Used"]; This code works fine, the values in the dictionary are assigned to the variables and they are displayed. The user can make changes and then press a save button. I use this code to extract the dictionary part of the array so I can update it. The assignment to editDictionary works. I've double checked the key names including case and that is correct. editDictionary = [[NSMutableDictionary alloc] init]; editDictionary = [arrSettings objectAtIndex:0]; NSNumber *myNumber = [NSNumber numberWithFloat:diaperAmount]; [editDictionary setValue:myNumber forKey:@"Diaper Expenses"]; myNumber = [NSNumber numberWithFloat:oilAmount]; [editDictionary setValue:myNumber forKey:@"Oil Used"]; myNumber = [NSNumber numberWithFloat:treeAmount]; [editDictionary setValue:myNumber forKey:@"Wood Used"]; In this example I've used a nsnumber. But I've also tried the xxxAmount field as part of SetValue instead of creating a NSNumber. Neither implementation works. Several strange things happen. Sometimes the first two setvalue statements work, but the last setvalue fails with a EXC_BAD_ACCESS failure. Other times the first setValue fails with the same error. I have no idea why the first two sometimes work. I'm at a loss of what to do next. I've tried several implentations and none of them work. Also, in the debugger how can I display the editDictionary elements. I can see editDictionary, but I don't know how to display the individual elements.

    Read the article

  • Urgent help needed on How to update NSMutableDictionary. My code doesn't work.

    - by dawatson833
    I've populated an array using. arrSettings = [[NSMutableArray alloc] initWithContentsOfFile:[self settingsPath]]; The file is a plist with the root as an array and then a dictionary with three three keys defined as number. I've also tried setting the keys to string. I display the values in the plist file on a view using. diaper = [[arrSettings objectAtIndex:0] objectForKey:@"Diaper Expenses"]; oil = [[arrSettings objectAtIndex:0] objectForKey:@"Oil Used"]; tree = [[arrSettings objectAtIndex:0] objectForKey:@"Wood Used"]; This code works fine, the values in the dictionary are assigned to the variables and they are displayed. The user can make changes and then press a save button. I use this code to extract the dictionary part of the array so I can update it. The assignment to editDictionary works. I've double checked the key names including case and that is correct. editDictionary = [[NSMutableDictionary alloc] init]; editDictionary = [arrSettings objectAtIndex:0]; NSNumber *myNumber = [NSNumber numberWithFloat:diaperAmount]; [editDictionary setValue:myNumber forKey:@"Diaper Expenses"]; myNumber = [NSNumber numberWithFloat:oilAmount]; [editDictionary setValue:myNumber forKey:@"Oil Used"]; myNumber = [NSNumber numberWithFloat:treeAmount]; [editDictionary setValue:myNumber forKey:@"Wood Used"]; In this example I've used a nsnumber. But I've also tried the xxxAmount field as part of SetValue instead of creating a NSNumber. Neither implementation works. Several strange things happen. Sometimes the first two setvalue statements work, but the last setvalue fails with a EXC_BAD_ACCESS failure. Other times the first setValue fails with the same error. I have no idea why the first two sometimes work. I'm at a loss of what to do next. I've tried several implentations and none of them work. Also, in the debugger how can I display the editDictionary elements. I can see editDictionary, but I don't know how to display the individual elements.

    Read the article

  • NSMutableDictionary confused over how to use keys with certain code ?

    - by Jules
    I'm getting data from a database and I need to add the string field value and the record id. However, I need this to work with some existing code... I'm replacing this (see code below) and getting data from my database. NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path]; self.allCategories = dict; [dict release]; But needs to work with these key and value search functions. - (void)resetSearch { NSMutableDictionary *allCategoriesCopy = [self.allCategories mutableDeepCopy]; self.Categories = allCategoriesCopy; [allCategoriesCopy release]; NSMutableArray *keyArray = [[NSMutableArray alloc] init]; [keyArray addObject:UITableViewIndexSearch]; [keyArray addObjectsFromArray:[[self.allCategories allKeys] sortedArrayUsingSelector:@selector(compare:)]]; self.keys = keyArray; [keyArray release]; } . - (void)handleSearchForTerm:(NSString *)searchTerm { NSMutableArray *sectionsToRemove = [[NSMutableArray alloc] init]; [self resetSearch]; for (NSString *key in self.keys) { NSMutableArray *array = [Categories valueForKey:key]; NSMutableArray *toRemove = [[NSMutableArray alloc] init]; for (NSString *name in array) { if ([name rangeOfString:searchTerm options:NSCaseInsensitiveSearch].location == NSNotFound) [toRemove addObject:name]; } if ([array count] == [toRemove count]) [sectionsToRemove addObject:key]; [array removeObjectsInArray:toRemove]; [toRemove release]; } [self.keys removeObjectsInArray:sectionsToRemove]; [sectionsToRemove release]; [table reloadData]; } Keep getting an error from this code... NSDictionary *arrayTmp= [[NSDictionary alloc] init]; ... loop records int cid = sqlite3_column_int(statementTMP, 0); NSString *category = [[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(statementTMP, 1)]; [arrayTmp setObject:category forKey:[NSString stringWithFormat:@"%i", cid]]; Error caused by line above * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString count]: unrecognized selector sent to instance 0x4d4c500' * Call stack at first throw * ... end loop self.allCategories = arrayTmp; [arrayTmp release];

    Read the article

  • If array is thread safe, what the issue with this function?

    - by Ajay Sharma
    I am totally lost with the things that is happening with my code.It make me to think & get clear with Array's thread Safe concept. Is NSMutableArray OR NSMutableDictionary Thread Safe ? While my code is under execution, the values for the MainArray get's changes although, that has been added to Array. Please try to execute this code, onyour system its very much easy.I am not able to get out of this Trap. It is the function where it is returning Array. What I am Looking to do is : -(Array) (Main Array) --(Dictionary) with Key Value (Multiple Dictionary in Main Array) ----- Above dictionary has 9 Arrays in it. This is the structure I am developing for Array.But even before #define TILE_ROWS 3 #define TILE_COLUMNS 3 #define TILE_COUNT (TILE_ROWS * TILE_COLUMNS) -(NSArray *)FillDataInArray:(int)counter { NSMutableArray *temprecord = [[NSMutableArray alloc] init]; for(int i = 0; i <counter;i++) { if([temprecord count]<=TILE_COUNT) { NSMutableDictionary *d1 = [[NSMutableDictionary alloc]init]; [d1 setValue:[NSString stringWithFormat:@"%d/2011",i+1] forKey:@"serial_data"]; [d1 setValue:@"Friday 13 Sep 12:00 AM" forKey:@"date_data"]; [d1 setValue:@"Description Details " forKey:@"details_data"]; [d1 setValue:@"Subject Line" forKey:@"subject_data"]; [temprecord addObject:d1]; d1= nil; [d1 release]; if([temprecord count]==TILE_COUNT) { NSMutableDictionary *holderKey = [[NSMutableDictionary alloc]initWithObjectsAndKeys:temprecord,[NSString stringWithFormat:@"%d",[casesListArray count]+1],nil]; [self.casesListArray addObject:holderKey]; [holderKey release]; holderKey =nil; [temprecord removeAllObjects]; } } else { [temprecord removeAllObjects]; NSMutableDictionary *d1 = [[NSMutableDictionary alloc]init]; [d1 setValue:[NSString stringWithFormat:@"%d/2011",i+1] forKey:@"serial_data"]; [d1 setValue:@"Friday 13 Sep 12:00 AM" forKey:@"date_data"]; [d1 setValue:@"Description Details " forKey:@"details_data"]; [d1 setValue:@"Subject Line" forKey:@"subject_data"]; [temprecord addObject:d1]; d1= nil; [d1 release]; } } return temprecord; [temprecord release]; } What is the problem with this Code ? Every time there are 9 records in Array, it just replaces the whole Array value instead of just for specific key Value.

    Read the article

  • NSMutableDictionary isn't stick around long enough

    - by Sean Danzeiser
    Sorry, beginner here . . . So I create an NSMutableDictionary in my app delegate when the application launches, and then later pass it on to a view controller, as it contains options for the VC like a background image, a url I want to parse, etc. Anyway, i wrote a custom init method for the VC, initWithOptions, where I pass the dictionary on. I'm trying to use this dictionary later on in other methods - so I created a NSMutableDictionary property for my VC and am trying to store the passed options dictionary there. However, when I go to get the contents of that property in later methods, it returns null. If i access it from the init method, it works. heres some sample code: -(id)initWithOptions:(NSMutableDictionary *)options { self = [super init]; if (self) { // Custom initialization self.optionsDict = [[NSMutableDictionary alloc]initWithDictionary:options]; NSLog(@"dictionary in init method %@",self.optionsDict); that NSLog logs the contents of the dictionary, and it looks like its working. then later when I do this: - (void)viewDidLoad { SDJConnection *connection = [[SDJConnection alloc]init]; self.dataArray = [connection getEventInfoWithURL:[dict objectForKey:@"urlkey"]]; NSLog(@"dictionary in connection contains: %@", [dict objectForKey:@"urlkey"]); [_tableView reloadData]; the dictionary returns null. Ive tried adjusting the property attributes, and it didn't work with either strong or retain. Any ideas?? THANKS!!

    Read the article

1 2 3 4 5 6 7 8  | Next Page >