Search Results

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

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

  • Learning Objective-C: Need advice on populating NSMutableDictionary

    - by Zigrivers
    I am teaching myself Objective-C utilizing a number of resources, one of which is the Stanford iPhone Dev class available via iTunes U (past 2010 class). One of the home work assignments asked that I populate a mutable dictionary with a predefined list of keys and values (URLs). I was able to put the code together, but as I look at it, I keep thinking there is probably a much better way for me to approach what I'm trying to do: Populate a NSMutableDictionary with the predefined keys and values Enumerate through the keys of the dictionary and check each key to see if it starts with "Stanford" If it meets the criteria, log both the key and the value I would really appreciate any feedback on how I might improve on what I've put together. I'm the very definition of a beginner, but I'm really enjoying the challenge of learning Objective-C. void bookmarkDictionary () { NSMutableDictionary* bookmarks = [NSMutableDictionary dictionary]; NSString* one = @"Stanford University", *two = @"Apple", *three = @"CS193P", *four = @"Stanford on iTunes U", *five = @"Stanford Mall"; NSString* urlOne = @"http://www.stanford.edu", *urlTwo = @"http://www.apple.com", *urlThree = @"http://cs193p.stanford.edu", *urlFour = @"http://itunes.stanford.edu", *urlFive = @"http://stanfordshop.com"; NSURL* oneURL = [NSURL URLWithString:urlOne]; NSURL* twoURL = [NSURL URLWithString:urlTwo]; NSURL* threeURL = [NSURL URLWithString:urlThree]; NSURL* fourURL = [NSURL URLWithString:urlFour]; NSURL* fiveURL = [NSURL URLWithString:urlFive]; [bookmarks setObject:oneURL forKey:one]; [bookmarks setObject:twoURL forKey:two]; [bookmarks setObject:threeURL forKey:three]; [bookmarks setObject:fourURL forKey:four]; [bookmarks setObject:fiveURL forKey:five]; NSString* akey; NSString* testString = @"Stanford"; for (akey in bookmarks) { if ([akey hasPrefix:testString]) { NSLog(@"Key: %@ URL: %@", akey, [bookmarks objectForKey:akey]); } } } Thanks for your help!

    Read the article

  • Saving a single NSMutableDictionary in a plist

    - by yesimarobot
    I have one dictionary I need to save into a plist. The paletteDictionary always returns nil: - (void)saveUserPalette:(id) sender { [paletteDictionary setObject:matchedPaletteColor1Array forKey:@"1"]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *path = [documentsDirectory stringByAppendingPathComponent:@"UserPaletteData.plist"]; // write plist to disk [paletteDictionary writeToFile:path atomically:YES]; } I'm reading the data back in a different view like: NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *path = [documentsDirectory stringByAppendingPathComponent:@"UserPaletteData.plist"]; NSMutableDictionary *plistDictionary = [NSMutableDictionary dictionaryWithContentsOfFile:path]; if(plistDictionary==nil ){ NSLog(@"failed to retrieve dictionary from disk"); }

    Read the article

  • iPhone noob - setting NSMutableDictionary entry inside Singleton?

    - by codemonkey
    Yet another iPhone/Objective-C noob question. I'm using a singleton to store app state information. I'm including the singleton in a Utilities class that holds it (and eventually other stuff). This utilities class is in turn included and used from various view controllers, etc. The utilities class is set up like this: // Utilities.h #import <Foundation/Foundation.h> @interface Utilities : NSObject { } + (id)GetAppState; - (id)GetAppDelegate; @end // Utilities.m #import "Utilities.h" #import "CHAPPAppDelegate.h" #import "AppState.h" @implementation Utilities CHAPPAppDelegate* GetAppDelegate() { return (CHAPPAppDelegate *)[UIApplication sharedApplication].delegate; } AppState* GetAppState() { return [GetAppDelegate() appState]; } @end ... and the AppState singleton looks like this: // AppState.h #import <Foundation/Foundation.h> @interface AppState : NSObject { NSMutableDictionary *challenge; NSString *challengeID; } @property (nonatomic, retain) NSMutableDictionary *challenge; @property (nonatomic, retain) NSString *challengeID; + (id)appState; @end // AppState.m #import "AppState.h" static AppState *neoAppState = nil; @implementation AppState @synthesize challengeID; @synthesize challenge; # pragma mark Singleton methods + (id)appState { @synchronized(self) { if (neoAppState == nil) [[self alloc] init]; } return neoAppState; } + (id)allocWithZone:(NSZone *)zone { @synchronized(self) { if (neoAppState == nil) { neoAppState = [super allocWithZone:zone]; return neoAppState; } } return nil; } - (id)copyWithZone:(NSZone *)zone { return self; } - (id)retain { return self; } - (unsigned)retainCount { return UINT_MAX; //denotes an object that cannot be released } - (void)release { // never release } - (id)init { if (self = [super init]) { challengeID = [[NSString alloc] initWithString:@"0"]; challenge = [NSMutableDictionary dictionary]; } return self; } - (void)dealloc { // should never be called, but just here for clarity [super dealloc]; } @end ... then, from a view controller I'm able to set the singleton's "challengeID" property like this: [GetAppState() setValue:@"wassup" forKey:@"challengeID"]; ... but when I try to set one of the "challenge" dictionary entry values like this: [[GetAppState() challenge] setObject:@"wassup" forKey:@"wassup"]; ... it fails giving me an "unrecognized selector sent..." error. I'm probably doing something really obviously dumb? Any insights/suggestions will be appreciated.

    Read the article

  • nsmutabledictionary is showing memory leak

    - by Narasimhaiah Kolli
    Why doing assigning nil to nsmutabledictioanry and allocating is crashing ans showing memory release at this point of place?? self.delegate.replenishAddedmaterials = nil; self.delegate.replenishAddedmaterials = [[NSMutableDictionary alloc] init]; MATERIAL_ITEM *materialItem = [[MATERIAL_ITEM alloc] init]; VENDOR_HEADER *vendor = [[VENDOR_HEADER alloc] init]; PURCHASING_ORG_HEADER *purOrg = [[PURCHASING_ORG_HEADER alloc] init]; [self.delegate.replenishAddedmaterials setObject:[NSMutableArray arrayWithObject:materialItem] forKey:materialItem]; [[self.delegate.replenishAddedmaterials objectForKey:materialItem] addObject:vendor]; [[self.delegate.replenishAddedmaterials objectForKey:materialItem] addObject:purOrg]; After executing allocation of nsmutabledictionary i am getting following message * -[MATERIAL_ITEM release]: message sent to deallocated instance 0x11e62810I have implemented my project in ARC

    Read the article

  • Memory Management - Objective C NSString

    - by reising1
    I have an NSMutableDictionary called "output" and I am adding an NSString into it that is an integer. What is the proper way to do this? I can't figure it out. Everything I've tried ends up giving memory leaks. This is what I currently have: val is an int countryName is an NSString Here is how I declare "output": NSMutableDictionary *output = [[[NSMutableDictionary alloc] init] autorelease]; Here is the code that causes a memory leak: NSString *temp = [NSString stringWithFormat:@"%d",val]; [output setValue:temp forKey:countryName];

    Read the article

  • converting NSMutableData to NSMutableDictionary?

    - by senthilmuthu
    hi, i am accumulating data from NSMutableDictionary to NSMutabledata like NSMutableData *data = [receivedData objectForKey:@"tag1"]; and also data = [receivedData objectForKey:@"tag2"]; after this one , how can i get data for @"tag2" only from NSMutableData? NSMutableData tag2Data = [Data forKey:@"tag2"]; is not working?

    Read the article

  • Passing NULL value

    - by FFXIII
    Hi. I use an instance of NSXMLParser. I store found chars in NSMutableStrings that are stored in an NSMutableDictionary and these Dicts are then added to an NSMutableArray. When I test this everything seems normal: I count 1 array, x dictionnaries and x strings. In a detailview controller file I want to show my parsed results. I call the class where everthing is stored but I get (null) returned. This is what I do (wrong): XMLParser.h @interface XMLParser : NSObject { NSMutableArray *array; NSMUtableDictionary *dictionary; NSSMutabletring *element; } @property (nonatomic, retain) NSMutableArray *array; @property (nonatomic, retain) NSMutableDictionary *dictionary; @property (nonatomic, retain) NSMutableString *element; XMLParser.m @synthesize array, dictionary, element; //parsing goes on here & works fine //so 'element' is filled with content and stored in a dict in an array //and released at the end of the file In my controller file I do this: controller.h @class XMLParser; @interface controller : UIViewController { XMLParser *aXMLParser; } @property (nonatomic, retain) XMLParser *aXMLParser; controller.m #import "XMLParser.h" @synthesize aXMLParser; - (void)viewDidLoad { NSLog(@"test array: %@", aXMLParser.array); NSLog(@"test dict: %@", aXMLParser.dictionary); NSLog(@"test element: %@", aXMLParser.element); } When I test the value of my array, a dict or an element in the XMLParser.h file I get my result. What am I doing wrong so I can't call my results in my controller file? Any help is welcome, because I'm pretty stuck right now :/

    Read the article

  • NSMutableDictionary of NSMutableSets... sorting this out

    - by Mike
    I have a NSMutableDictionary of NSMutableSets. Each set entry is a string, something like this: NSMutableSet *mySet = [NSMutableSet setWithObjects: [NSString stringWithFormat:@"%d", time1], [NSString stringWithFormat:@"%d", time2], [NSString stringWithFormat:@"%d", time3], nil]; // time 1,2,3, are NSTimeInterval variables then I store each set on the dictionary using this: NSString *rightNowString = [NSString stringWithFormat:@"%d", rightNow]; [myDict setValue:mySet forKey:rightNow]; // rightNow is NSTimeInterval as rightNow key can occur out of order, I end with a NSDictionary that is not ordered by rightNow. How can I sort this NSDictionary by its keys considering that they are numbers stored as strings on the dictionary...? I don't care for ordering the sets, just the dictionary. thanks for any help.

    Read the article

  • NSUndoManager won't undo editing of a NSMutableDictionary

    - by xon1c
    Hi, I'm experiencing problems with the undo operation. The following code won't undo an removeObjectForKey: operation but the redo operation setObject:ForKey: works. - (void) insertIntoDictionary:(NSBezierPath *)thePath { [[[window undoManager] prepareWithInvocationTarget:self] removeFromDictionary:thePath]; if(![[window undoManager] isUndoing]) [[window undoManager] setActionName:@"Save Path"]; NSLog(@"Object id is: %d and Key id is: %d", [currentPath objectAtIndex:0], thePath); [colorsForPaths setObject:[currentPath objectAtIndex:0] forKey:thePath]; } - (void) removeFromDictionary:(NSBezierPath *)thePath { [[[window undoManager] prepareWithInvocationTarget:self] insertIntoDictionary:thePath]; if(![[window undoManager] isUndoing]) [[window undoManager] setActionName:@"Delete Path"]; NSLog(@"Object id is: %d and Key id is: %d", [[colorsForPaths allKeys] objectAtIndex:0], thePath); [colorsForPaths removeObjectForKey:thePath]; } The output on the console looks like: // Before setObject:ForKey: Object id is: 1184384 and Key id is: 1530016 // Before removeObjectForKey: UNDO Object id is: 2413664 and Key id is: 1530016 I don't get why the Object id is different although the Key id remains the same. Is there some special undo/redo handling of NSMutableDictionary objects? thx xonic

    Read the article

  • iPhone app throwing EXC_BAD_ACCESS with dictionary from contents of file

    - by Mark Szymanski
    I have the code NSArray *paths = [[NSArray alloc] initWithArray:NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES)]; NSString *docsDirectory = [[NSString alloc] initWithString:[paths objectAtIndex:0]]; NSLog(@"This app's documents directory: %@",docsDirectory); NSString *docsDirectoryWithPlist = [[NSString alloc] initWithFormat:@"%@/Stuff.plist", docsDirectory]; BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:docsDirectoryWithPlist isDirectory:NO]; if (fileExists) { chdir([docsDirectory UTF8String]); NSMutableDictionary *readDict = [[NSMutableDictionary alloc] initWithContentsOfFile:@"Stuff.plist"]; in an application's applicationDidFinishLaunching method and whenever it gets to the last line it crashes, throwing EXC_BAD_ACCESS along the way. Thanks in advance!

    Read the article

  • Dynamic name of NSMutableDictionary?

    - by Bruno
    Hi everyone I load from a txt file many info, and I would like, if possible, to dynamically create NSmutable dictionary with the elements of the txt. For example, each is like that: id of element | date | text What I'm asking is the equivalent of the NSString stringWithFormat:. Can we do the same for an Mutable Dictionary? To be more practical, let's say the NSString *date is equal to "23/12/2009" (for europe). I want to create a dictionary called 23/12/2009 without declaring *23/12/2009 but just something like dictionaryWithFormat: @"%@", date]; I'm stuck on this, and I don't even know if it is possible. If not, what's the best way to approach that? Thanks everyone Regards

    Read the article

  • Sorting array containing strings in objective c

    - by jakob
    Hello experts! I have an array named 'names' with strings looking like this: ["name_23_something", "name_25_something", "name_2_something"]; Now I would like to sort this array in ascending order so it looks like this: ["name_25_something", "name_23_something", "name_2_something"]; I guess that should start of with extracting the numbers since I want that the sorting is done by them: for(NSString *name in arr) { NSArray *nameSegments = [name componentsSeparatedByString:@"_"]; NSLog("number: %@", (NSString*)[nameSegments objectAtIndex:1]); } I'm thinking of creating a dictionary with the keys but I'm not sure if that is the correct objective-c way, maybe there some some methods I could use instead? Could you please me with some tips or example code how this sorting should be done in a proper way. Thank you

    Read the article

  • A NSMutableArray is destroying my life!

    - by camilo
    EDITED to show the relevant part of the code Hi. There's a strange problem with an NSMutableArray which I'm just not understanding... Explaining: I have a NSMutableArray, defined as a property (nonatomic, retain), synthesized, and initialized with 29 elements. realSectionNames = [[NSMutableArray alloc] initWithCapacity:29]; After the initialization, I can insert elements as I wish and everything seems to be working fine. While I'm running the application, however, if I insert a new element in the array, I can print the array in the function where I inserted the element, and everything seems ok. However, when I select a row in the table, and I need to read that array, my application crashes. In fact, it cannot even print the array anymore. Is there any "magical and logical trick" everybody should know when using a NSMutableArray that a beginner like myself can be missing? Thanks a lot. I declare my array as realSectionNames = [[NSMutableArray alloc] initWithCapacity:29]; I insert objects in my array with [realSectionNames addObject:[category categoryFirstLetter]]; although I know i can also insert it with [realSectionNames insertObject:[category categoryFirstLetter] atIndex:i]; where the "i" is the first non-occupied position. After the insertion, I reload the data of my tableView. Printing the array before or after reloading the data shows it has the desired information. After that, selecting a row at the table makes the application crash. This realSectionNames is used in several UITableViewDelegate functions, but for the case it doesn't matter. What truly matters is that printing the array in the beginning of the didSelectRowAtIndexPath function crashes everything (and of course, doesn't print anything). I'm pretty sure it's in that line, for printing anything he line before works (example): NSLog(@"Anything"); NSLog(@"%@", realSectionNames); gives the output: 2010-03-24 15:16:04.146 myApplicationExperience[3527:207] Anything [Session started at 2010-03-24 15:16:04 +0000.] GNU gdb 6.3.50-20050815 (Apple version gdb-967) (Tue Jul 14 02:11:58 UTC 2009) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i386-apple-darwin".sharedlibrary apply-load-rules all Attaching to process 3527. Still not understanding what kind of stupidity I've done this time... maybe it's not too late to follow the career of brain surgeon?

    Read the article

  • How to track dealloc of an abstract object class (NSMutable...)

    - by Thomas Tempelmann
    I have a bug in my code caused by a premature freeing of a ObjC object. I seem not to be able to find it by just looking at my code. There's usually a simple trick to track the dealloc to any class: Implement dealloc, and set a breakpoint. This even usually works with standard objects, by subclassing them and making sure I instantiate the subclass instead of the standard class. However, this does not seem to work with NSMutableArray, and probably neither with similar NSMutable... classes. Some explanations for this can be found here: link text Any other ideas how to track the dealloc invocation of a particular class or object so that I can see the call stack? It's probably possible with DTrace. Any pointers without having to read the entire dtrace docs first?

    Read the article

  • How can I get the Twitter following and follower Email id and MobileNo in the iPhone sdk Using MGTwitterEngine?

    - by user1808090
    I'm unable to get the Twitter following and Followers Email id and MobileNo i am using below code for that using below code i am able to get only Twitter following name and Id Please help? if([[NSUserDefaults standardUserDefaults] valueForKey:@"UseridLoop"]==nil) { urlString = [NSString stringWithFormat:@"https://api.twitter.com/1/friends/ids.json?cursor=-1&user_id=%@",[[NSUserDefaults standardUserDefaults] valueForKey:@"Userid"]]; } else { urlString = [NSString stringWithFormat:@"https://api.twitter.com/1/followers/ids.json?cursor=-1&user_id=%@",[[NSUserDefaults standardUserDefaults] valueForKey:@"UseridLoop"]]; } NSURLRequest *notificationRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]]; NSHTTPURLResponse *response; NSError *error; NSData *responData; responData = [NSURLConnection sendSynchronousRequest:notificationRequest returningResponse:&response error:&error]; NSLog(@"%@",responData); NSString *dataString = [[NSString alloc] initWithData:responData encoding:NSUTF8StringEncoding]; // NSDictionary *dict = [[NSDictionary alloc] initWithDictionary:(NSDictionary *)[dataString JSONValue]]; // // NSMutableDictionary *globalCelebDict=[[NSMutableDictionary alloc]initWithDictionary:(NSMutableDictionary *)[dataString JSONValue ] ]; // //NSMutableDictionary *globalCelebDictNext=[[NSMutableDictionary alloc]initWithDictionary:(NSMutableDictionary *)[[ globalCelebDict objectForKey:@"GetGroupDetailsResult"] JSONValue]]; // NSLog(@"dict %@",dict); SBJSON *json = [[SBJSON alloc] init]; NSMutableDictionary *customDetailDict=[[NSMutableDictionary alloc]init]; customDetailDict=[json objectWithString:dataString error:&error]; // NSDictionary *customDetailDict = [json objectWithString:dataString error:&error]; NSLog(@"%@",customDetailDict); if (customDetailDict!=nil) { array=[[customDetailDict objectForKey:@"ids"]retain]; NSLog(@"%@",array); NSLog(@"%d",[array count]); [[NSUserDefaults standardUserDefaults]removeObjectForKey:@"UseridLoop"]; NSLog(@"%@",[[NSUserDefaults standardUserDefaults]valueForKey:@"UseridLoop"]); } }

    Read the article

  • How do you get and set a class property across multiple functions in Objective-C?

    - by editor
    Following up on this question about sharing objects between classes, I now need to figure out how to share the objects across various functions in a class. First, the setup: In my App Delegate I load menu information from JSON into a NSMutableDictionary and message that through to a view controller using a function called initWithData. I need to use this dictionary to populate a new Table View, which has methods like numberOfRowsInSection and cellForRowAtIndexPath. I'd like to use the dictionary count to return numberOfRowsInSection and info in the dictionary to populate each cell. Unfortunately, my code never gets beyond the init stage and the dictionary is empty so numberOfRowsInSection always returns zero. I thought I could create a class property, synthesize it and then set it. But it doesn't seem to want to retain the property's value. What am I doing wrong here? In the header .h: @interface FirstViewController:UIViewController <UITableViewDataSource, UITableViewDelegate, UITabBarControllerDelegate> { NSMutableDictionary *sectorDictionary; NSInteger sectorCount; } @property (nonatomic, retain) NSMutableDictionary *sectorDictionary; - (id)initWithData:(NSMutableDictionary*)data; @end in the implementation .m: - (id) testFunction:(NSMutableDictionary*)dictionary { NSLog(@"Count #1: %d", [dictionary count]); return nil; } - (id)initWithData:(NSMutableDictionary *)data { if (!(self=[super init])) { return nil; } [self testFunction:data]; // this is where I'd like to set a retained property self.sectorDictionary = data; return nil; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { NSLog(@"Count #2: %d", [self.sectorDictionary count]); return [self.sectorDictionary count]; } Output from NSLog: 2010-05-04 23:00:06.255 JSONApp[15890:207] Count #1: 9 2010-05-04 23:00:06.259 JSONApp[15890:207] Count #2: 0

    Read the article

  • How to save a value in a plist file in iphone?

    - by Warrior
    I am new to iphone development.I am using the below code to add the value to the plist but when check the plist after executing the code i dont see any value saved in the plist.Where do i go wrong? please help me out.The plist i have created is in the resource folder.Thanks. NSString *path = [[NSBundle mainBundle] bundlePath]; NSString *finalPath = [path stringByAppendingPathComponent:@"regvalue.plist"]; NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:finalPath]; [plistDict setValue:@"hello" forKey:@"choice"]; [plistDict writeToFile:finalPath atomically: YES]; For retrieving the value NSString *path = [[NSBundle mainBundle] bundlePath]; NSString *finalPath = [path stringByAppendingPathComponent:@"regvalue.plist"]; NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:finalPath]; NSString *value; value = [plistDict objectForKey:@"choice"]; NSLog(@"the value is %@",value); It gives only null value.Please help me out.Thanks.

    Read the article

  • Why doe my UITableView only show two rows of each section?

    - by Mike Owens
    I have a UITableView and when I build it only two rows will be displayed. Each section has more than two cells to be displayed, I am confused since they are all done the same?`#import #import "Store.h" import "VideoViewController.h" @implementation Store @synthesize listData; // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [self createTableData]; [super viewDidLoad]; } (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } (void)viewDidUnload { //self.listData = nil; //[super viewDidUnload]; // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } pragma mark - pragma mark Table View Data Source Methods // Customize the number of sections in the table view. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return [videoSections count]; } //Get number of rows -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [self.listData count]; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *StoreTableIdentifier = @"StoreTableIdentifier"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:StoreTableIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:StoreTableIdentifier] autorelease]; } cell.textLabel.text = [[[listData objectAtIndex:indexPath.section] objectAtIndex:indexPath.row] objectForKey:@"name"]; //Change font and color of tableView cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; cell.textLabel.font=[UIFont fontWithName:@"Georgia" size:16.0]; cell.textLabel.textColor = [UIColor brownColor]; return cell; } -(NSString *)tableView: (UITableView *)tableView titleForHeaderInSection: (NSInteger) section { return [videoSections objectAtIndex:section]; } -(void)tableView: (UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath { VideoViewController *videoViewController = [[VideoViewController alloc] initWithNibName: @"VideoViewController" bundle:nil]; videoViewController.detailURL = [[NSURL alloc] initWithString: [[[listData objectAtIndex:indexPath.section] objectAtIndex:indexPath.row] objectForKey:@"url"]]; videoViewController.title = [[[listData objectAtIndex:indexPath.section] objectAtIndex:indexPath.row] objectForKey:@"name"]; [self.navigationController pushViewController:videoViewController animated:YES]; [videoViewController release]; } pragma mark Table View Methods //Data in table cell -(void) createTableData { NSMutableArray *beginningVideos; NSMutableArray *intermediateVideos; videoSections = [[NSMutableArray alloc] initWithObjects: @"Beginning Videos", @"Intermediate Videos", nil]; beginningVideos = [[NSMutableArray alloc] init]; intermediateVideos = [[NSMutableArray alloc] init]; [beginningVideos addObject:[[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Shirts", @"name", @"http://www.andalee.com/iPhoneVideos/testMovie.m4v", @"url", nil]]; [beginningVideos addObject:[[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Posters", @"name", @"http://devimages.apple.com/iphone/samples/bipbopall.html", @"url", nil]]; [beginningVideos addObject:[[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Stickers",@"name", @"http://www.andalee.com/iPhoneVideos/mov.MOV",@"url",nil]]; [beginningVideos addObject:[[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Egyptian",@"name", @"http://www.andalee.com/iPhoneVideos/2ndMovie.MOV",@"url",nil]]; [intermediateVideos addObject:[[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Drum Solo", @"name", @"http://www.andalee.com", @"url", nil]]; [intermediateVideos addObject:[[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Veil", @"name", @"http://www.andalee.com", @"url", nil]]; [intermediateVideos addObject:[[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Three Quarter Shimmy",@"name", @"http://www.andalee.com", @"url",nil]]; listData = [[NSMutableArray alloc] initWithObjects:beginningVideos, intermediateVideos, nil]; [beginningVideos release]; [intermediateVideos release]; } (void)dealloc { [listData release]; [videoSections release]; [super dealloc]; } @end `

    Read the article

  • Release Quickie

    - by Meltemi
    How to succinctly handle this situation. I'm not properly releasing contactDictionary in the if statement... NSNumber *pIDAsNumber; ... NSMutableDictionary *contactDictionary = [NSMutableDictionary dictionaryWithDictionary:[defaults dictionaryForKey:kContactDictionary]]; if (!contactDictionary) { contactDictionary = [[NSMutableDictionary alloc] initWithCapacity:1]; } [contactDictionary setObject:pIDAsNumber forKey:[myClass.personIDAsNumber stringValue]]; [defaults setObject:contactDictionary forKey:kContactDictionary];

    Read the article

  • Javascript style objects in Objective-C

    - by awolf
    Background: I use a ton of NSDictionary objects in my iPhone and iPad code. I'm sick of the verbose way of getting/setting keys to these state dictionaries. So a little bit of an experiment: I just created a class I call Remap. Remap will take any arbitrary set[VariableName]:(NSObject *) obj selector and forward that message to a function that will insert obj into an internal NSMutableDictionary under the key [vairableName]. Remap will also take any (zero argument) arbitrary [variableName] selector and return the NSObject mapped in the NSMutableDictionary under the key [variableName]. e.g. Remap * remap = [[Remap alloc] init]; NSNumber * testNumber = [NSNumber numberWithInt:46]; [remap setTestNumber:testNumber]; testNumber = [remap testNumber]; [remap setTestString:@"test string"]; NSString * testString = [remap testString]; NSMutableDictionary * testDict = [NSMutableDictionary dictionaryWithObject:testNumber forKey:@"testNumber"]; [remap setTestDict:testDict]; testDict = [remap testDict]; where none of the properties testNumber, testString, or testDict are actually defined in Remap. The crazy thing? It works... My only question is how can I disable the "may not respond to " warnings for JUST accesses to Remap? P.S. : I'll probably end up scrapping this and going with macros since message forwarding is quite inefficient... but aside from that does anyone see other problems with Remap? Here's Remap's .m for those who are curious: #import "Remap.h" @interface Remap () @property (nonatomic, retain) NSMutableDictionary * _data; @end @implementation Remap @synthesize _data; - (void) dealloc { relnil(_data); [super dealloc]; } - (id) init { self = [super init]; if (self != nil) { NSMutableDictionary * dict = [[NSMutableDictionary alloc] init]; [self set_data:dict]; relnil(dict); } return self; } - (void)forwardInvocation:(NSInvocation *)anInvocation { NSString * selectorName = [NSString stringWithUTF8String: sel_getName([anInvocation selector])]; NSRange range = [selectorName rangeOfString:@"set"]; NSInteger numArguments = [[anInvocation methodSignature] numberOfArguments]; if (range.location == 0 && numArguments == 4) { //setter [anInvocation setSelector:@selector(setData:withKey:)]; [anInvocation setArgument:&selectorName atIndex:3]; [anInvocation invokeWithTarget:self]; } else if (numArguments == 3) { [anInvocation setSelector:@selector(getDataWithKey:)]; [anInvocation setArgument:&selectorName atIndex:2]; [anInvocation invokeWithTarget:self]; } } - (NSMethodSignature *) methodSignatureForSelector:(SEL) aSelector { NSString * selectorName = [NSString stringWithUTF8String: sel_getName(aSelector)]; NSMethodSignature * sig = [super methodSignatureForSelector:aSelector]; if (sig == nil) { NSRange range = [selectorName rangeOfString:@"set"]; if (range.location == 0) { sig = [self methodSignatureForSelector:@selector(setData:withKey:)]; } else { sig = [self methodSignatureForSelector:@selector(getDataWithKey:)]; } } return sig; } - (NSObject *) getDataWithKey: (NSString *) key { NSObject * returnValue = [[self _data] objectForKey:key]; return returnValue; } - (void) setData: (NSObject *) data withKey:(NSString *)key { if (key && [key length] >= 5 && data) { NSRange range; range.length = 1; range.location = 3; NSString * firstChar = [key substringWithRange:range]; firstChar = [firstChar lowercaseString]; range.length = [key length] - 5; // the 4 we have processed plus the training : range.location = 4; NSString * adjustedKey = [NSString stringWithFormat:@"%@%@", firstChar, [key substringWithRange:range]]; [[self _data] setObject:data forKey:adjustedKey]; } else { //assert? } } @end

    Read the article

  • Where would I implement this array to pass?

    - by Keeano Martin
    I currently build an NSMutableArray in Class A.m within the ViewDidLoad Method. - (void)viewDidLoad { [super viewDidLoad]; //Question Array Setup and Alloc stratToolsDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:countButton,@"count",camerButton,@"camera",videoButton,@"video",textButton,@"text",probeButton,@"probe", nil]; stratTools = [[NSMutableArray alloc] initWithObjects:@"Tools",stratToolsDict, nil]; stratObjectsDict = [[NSMutableDictionary alloc]initWithObjectsAndKeys:stratTools,@"Strat1",stratTools,@"Strat2",stratTools,@"Strat3",stratTools,@"Strat4", nil]; stratObjects = [[NSMutableArray alloc]initWithObjects:@"Strategies:",stratObjectsDict,nil]; QuestionDict = [[NSMutableDictionary alloc]initWithObjectsAndKeys:stratObjects,@"Question 1?",stratObjects,@"Question 2?",stratObjects,@"Question 3?",stratObjects,@"Question 4?",stratObjects,@"Question 5?", nil]; //add strategys to questions QuestionsList = [[NSMutableArray alloc]init]; for (int i = 0; i < 1; i++) { [QuestionsList addObject:QuestionDict]; } NSLog(@"Object: %@",QuestionsList); At the end of this method you will see QuestionsList being initialized and now I need to send this Array to Class B. So I place its setters and getters using the @property and @Synthesize method. Class A.h @property (retain, nonatomic) NSMutableDictionary *stratToolsDict; @property (retain, nonatomic) NSMutableArray *stratTools; @property (retain, nonatomic) NSMutableArray *stratObjects; @property (retain, nonatomic) NSMutableDictionary *QuestionDict; @property (retain, nonatomic) NSMutableArray *QuestionsList; Class A.m @synthesize QuestionDict; @synthesize stratToolsDict; @synthesize stratObjects; @synthesize stratTools; @synthesize QuestionsList; I use the property method because I am going to call this variable from Class B and want to be able to assign it to another NSMutableArray. I then add the @property and @class for Class A to Class B.h as well as declare the NSMutableArray in the @interface. #import "Class A.h" @class Class A; @interface Class B : UITableViewController<UITableViewDataSource, UITableViewDelegate>{ NSMutableArray *QuestionList; Class A *arrayQuestions; } @property Class A *arrayQuestions; Then I call NSMutableArray from Class A in the Class B.m -(id)initWithStyle:(UITableViewStyle)style { if ([super initWithStyle:style] != nil) { //Make array arrayQuestions = [[Class A alloc]init]; QuestionList = arrayQuestions.QuestionsList; Right after this I Log the NSMutableArray to view values and check that they are there and it returns NIL. //Log test NSLog(@"QuestionList init method: %@",QuestionList); Info about Class B- Class B is a UIPopOverController for Class A, Class B has one View which holds a UITableView which I have to populate the results of Class A's NSMutableArray. Why is the NsMutableArray coming back as NIL? Ultimately would like some help figuring it out as well, it seems to really have me confused. Help is greatly appreciated!!

    Read the article

  • Problem with sorting NSDictionary

    - by Stas Dmitrenko
    Hello. I need to sort a NSDictionary of dictionaries. It looks like: {//dictionary RU = "110.1"; //key and value SG = "150.2"; //key and value US = "50.3"; //key and value } Result need to be like: {//dictionary SG = "150.2"; //key and value RU = "110.1"; //key and value US = "50.3"; //key and value } I am trying this: @implementation NSMutableDictionary (sorting) -(NSMutableDictionary*)sortDictionary { NSArray *allKeys = [self allKeys]; NSMutableArray *allValues = [NSMutableArray array]; NSMutableArray *sortValues= [NSMutableArray array]; NSMutableArray *sortKeys= [NSMutableArray array]; for(int i=0;i<[[self allValues] count];i++) { [allValues addObject:[NSNumber numberWithFloat:[[[self allValues] objectAtIndex:i] floatValue]]]; } [sortValues addObjectsFromArray:allValues]; [sortKeys addObjectsFromArray:[self allKeys]]; [sortValues sortUsingDescriptors:[NSArray arrayWithObject:[[[NSSortDescriptor alloc] initWithKey:@"floatValue" ascending:NO] autorelease]]]; for(int i=0;i<[sortValues count];i++) { [sortKeys replaceObjectAtIndex:i withObject:[allKeys objectAtIndex:[allValues indexOfObject:[sortValues objectAtIndex:i]]]]; [allValues replaceObjectAtIndex:[allValues indexOfObject:[sortValues objectAtIndex:i]] withObject:[NSNull null]]; } NSLog(@"%@", sortKeys); NSLog(@"%@", sortValues); NSLog(@"%@", [NSMutableDictionary dictionaryWithObjects:sortValues forKeys:sortKeys]); return [NSMutableDictionary dictionaryWithObjects:sortValues forKeys:sortKeys]; } @end This is the result of NSLog: 1) { SG, RU, US } 2) { 150.2, 110.1, 50.3 } 3) { RU = "110.1"; SG = "150.2"; US = "50.3"; } Why is this happening? Can you help me with this problem?

    Read the article

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