Search Results

Search found 560 results on 23 pages for 'nsdictionary'.

Page 1/23 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Why 'initWithObjectsAndKeys:' doesn't throw a casting warning? (NSDictionary)

    - by rubdottocom
    Sorry if the question isn't correct, I'm very new in Objective-C. I understand why this code throw the Warning: "warning: passing argument 1 of 'initWithObjectsAndKeys:' makes pointer from integer without" NSDictionary *dictNames = [[NSDictionary alloc] initWithObjectsAndKeys: 3, @"", 4, @"", 5, @"",nil]; Keys and Values of a NSDictionary must be NSObject and not fundamental types, like the integers 3, 4 and 5. (Correct me if necessary). But I don't understand why this warning dissapears with the only "correct typing" of the first Key. NSDictionary *dictNames = [[NSDictionary alloc] initWithObjectsAndKeys: [NSNumber numberWithInteger:3], @"", 4, @"", 5, @"",nil]; It's because NSDictionary assumes the type of the other Keys? Is correct this manner of initialization?

    Read the article

  • Memory leak for NSDictionary loaded by plist file

    - by Pask
    I have a memory leak problem that just can not understand! Watch this initialization method: - (id)initWithNomeCompositore:(NSString *)nomeCompositore nomeOpera:(NSString *)nomeOpera { if (self = [super init]) { NSString *pathOpere = [[NSBundle mainBundle] pathForResource:kNomeFilePlistOpere ofType:kTipoFilePlist]; NSDictionary *dicOpera = [NSDictionary dictionaryWithDictionary: [[[NSDictionary dictionaryWithContentsOfFile:pathOpere] objectForKey:nomeCompositore] objectForKey:nomeOpera]]; self.nomeCompleto = [[NSString alloc] initWithString:nomeOpera]; self.compositore = [[NSString alloc] initWithString:nomeCompositore]; self.tipologia = [[NSString alloc] initWithString:[dicOpera objectForKey:kKeyTipologia]]; } return self;} Then this little variation (note self.tipologia): - (id)initWithNomeCompositore:(NSString *)nomeCompositore nomeOpera:(NSString *)nomeOpera { if (self = [super init]) { NSString *pathOpere = [[NSBundle mainBundle] pathForResource:kNomeFilePlistOpere ofType:kTipoFilePlist]; NSDictionary *dicOpera = [NSDictionary dictionaryWithDictionary: [[[NSDictionary dictionaryWithContentsOfFile:pathOpere] objectForKey:nomeCompositore] objectForKey:nomeOpera]]; self.nomeCompleto = [[NSString alloc] initWithString:nomeOpera]; self.compositore = [[NSString alloc] initWithString:nomeCompositore]; self.tipologia = [[NSString alloc] initWithString:@"Test"]; } return self;} In the first variant is generated a memory leak, the second is not! And I just can not understand why! The memory leak is evidenced by Instruments, highlighted the line: [NSDictionary dictionaryWithContentsOfFile:pathOpere] This is the dealloc method: - (void)dealloc { [tipologia release]; [compositore release]; [nomeCompleto release]; [super dealloc];}

    Read the article

  • NSDictionary: convert NSString keys to lowercase to search a string on them

    - by VansFannel
    Hello. I'm developing an iPhone application. I use a NSDictionary to store city's names as key, and population as value. I want to search the keys using lowercase. I've using this: NSDictionary *dict; [dict objectForKey:[[city stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] lowercaseString]]; But, it doesn't work. I know, I can do a for, convert keys to lowercase and compare with city. Is there any other way to do that? Maybe, with a NSDictionary method. UPDATE The NSDictionary is loaded from a property list. Thank you.

    Read the article

  • Updates to NSDictionary attribute in CoreData not saving

    - by sfkaos
    I have created an Entity in CoreData that includes a Transformable attribute type implemented as an NSDictionary. The NSDictionary attribute only contains values of a custom class. The properties of the custom class are all of type NSString. The custom class complies with NSCoding implementing: -(void)encodeWithCoder:(NSCoder*)coder; -(id)initWithCoder:(NSCoder *)coder When saving the Entity for the first time all attributes including the Transformable (NSDictionary) type are properly saved in the DB. When the same Entity is fetched from the DB and updated (including the Transformable attribute) it seems to be updated properly. However, when the app is closed and then reopened fetching the Entity does not show the updated Transformable attribute-type though the rest of the attributes of type NSDate and NSString are up-to-date. The Transformable attribute is the original saved value not the updated value. Is this a problem with KVO or am I missing something else when trying to save an NSDictionary filled with a custom class to CoreData?

    Read the article

  • Using NSDictionary throughout an iphone project

    - by Guy
    Hi guys, How do you access a NSDictionary in different NSViewControllers. The NSDictionary was initialized in my delegate file. Do I have to import my delegate file to each view controller file or do all my views on top of my delegate know of my NSDictionary? Do I possibly need to declare my Dictionary in each file? -Thanks Guy

    Read the article

  • Whats the maximum key length in NSDictionary?

    - by x3ro
    Hey there, I'm currently working on an app which displays a bunch of files in a table, and you can add and remove them and whatsoever. To prevent duplicates in the table, I'd like to create a NSDictionary using the files full path as keys for another NSDictionary which contains all the file information, but I am a little concerned about the maximum key length of NSDictionary, and also whether this solution would be performance killer or not... Looking forward to your answers. Best regards, x3ro

    Read the article

  • nested NSDictionary from plist

    - by Dror Sabbag
    Hello, Here is a question, i have a plist, with main NSDictoinary, which his keys are dates. for every date, i have NSDictionary which his keys are (let's say) categories every Category holds Keys and values. I would like to create 2 variables that each one will hold the correct NSDictionary NSDictionary *dates = ? NSDictionary *Categories = ? below is my plist, Please help to understand how this should be done. **Note: i do know how to assign the first dates dictionary from the plist.. just stuck with the Categories. NSDictionary *dict = [[NSDictionary alloc]initWithContentsOfFile:path]; self.dates = dict; [dict release]; The plist: <dict> <key>2010-05-08</key> <dict> <key>Catergory1</key> <dict> <key>key1</key> <string>value1</string> <key>key2</key> <string>value2</string> <key>key3</key> <string>value3</string> </dict> <key>Catergory2</key> <dict> <key>key1</key> <string>value1</string> <key>key2</key> <string>value2</string> <key>key3</key> <string>value3</string> </dict> <key>2010-01-02</key> <dict> <key>Catergory1</key> <dict> <key>key1</key> <string>value1</string> <key>key2</key> <string>value2</string> <key>key3</key> <string>value3</string> </dict> <key>Catergory2</key> <dict> <key>key1</key> <string>value1</string> <key>key2</key> <string>value2</string> <key>key3</key> <string>value3</string> </dict> </dict> </dict> </plist> any help would be greatly appriciated, as i searched over the forum history and found nothing which match my scenario. THANKS!

    Read the article

  • writing NSDictionary to plist

    - by ADude
    Hi I'm trying to write an NSDictionary to a plist but when I open the plist no data has been written to it. From the log my path looks correct and my code is pretty standard. Any ideas? NSArray *keys = [NSArray arrayWithObjects:@"key1", @"key2", @"key3", nil]; NSArray *objects = [NSArray arrayWithObjects:@"value1", @"value2", @"value3", nil]; NSDictionary *dictionary = [NSDictionary dictionaryWithObjects:objects forKeys:keys]; for (id key in dictionary) { NSLog(@"key: %@, value: %@", key, [dictionary objectForKey:key]); } NSString *path = [[NSBundle mainBundle] pathForResource:@"FormData" ofType:@"plist"]; NSLog(@"path:%@", path); [dictionary writeToFile:path atomically:YES];

    Read the article

  • NSDictionary with key => String and Value => c-Style array

    - by Gautam Borad
    I need an NSDictionary which has key in the form of string (@"key1", @"key2") and value in the form of a C-style two-dimentional array (valueArray1,valueArray2) where valueArray1 is defined as : int valueArray1[8][3] = { {25,10,65},{50,30,75},{60,45,80},{75,60,10}, {10,70,80},{90,30,80},{20,15,90},{20,20,15} }; And same for valueArray2. My aim is given an NSString i need to fetch the corresponding two-dimentional array. I guess using an NSArray, instead of c-style array, will work but then i cannot initialize the arrays as done above (i have many such arrays). If, however, that is doable please let me know how. Currently the following is giving a warning "Passing argument 1 of 'dictionaryWithObjectsAndKeys:' from incompatible pointer type" : NSDictionary *myDict = [NSDictionary dictionaryWithObjectsAndKeys:valueArray1,@"key1", valueArray2,@"key2",nil];

    Read the article

  • Can NSDictionary be used with TableView on iPhone?

    - by bobo
    In a UITableViewController subclass, there are some methods that need to be implemented in order to load the data and handle the row selection event: - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; //there is only one section needed for my table view } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [myList count]; //myList is a NSDictionary already populated in viewDidLoad method } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease ]; } // indexPath.row returns an integer index, // but myList uses keys that are not integer, // I don't know how I can retrieve the value and assign it to the cell.textLabel.text return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // Handle row on select event, // but indexPath.row only returns the index, // not a key of the myList NSDictionary, // this prevents me from knowing which row is selected } How is NSDictionary supposed to work with TableView? What is the simplest way to get this done?

    Read the article

  • iPhone SDK: NSUserDefaults or NSDictionary?

    - by Ricibald
    Compare the following: using NSUserDefaults saving it with synchronize using NSDictionary saving it with writeToFile in the app Documents folder What are the differences? Personally, I prefer to mantain different NSDictionary organized by topic rather than use a single NSUserDefaults. Am I thinking something wrong? Thanks

    Read the article

  • Using GameKit to transfer CoreData data between iPhones, via NSDictionary

    - by OscarTheGrouch
    I have an application where I would like to exchange information, managed via Core Data, between two iPhones. First turning the Core Data object to an NSDictionary (something very simple that gets turned into NSData to be transferred). My CoreData has 3 string attributes, 2 image attributes that are transformables. I have looked through the NSDictionary API but have not had any luck with it, creating or adding the CoreData information to it. Any help or sample code regarding this would be greatly appreciated.

    Read the article

  • Example of [NSDictionary getObjects:andKeys:]

    - by eagle
    I couldn't find a working example of the method [NSDictionary getObjects:andKeys:] on Google. The only link I could find, doesn't compile. I provided the errors/warnings here in case someone is searching for them. The documentation says that it returns a C array. NSDictionary *myDictionary = ...; id objects[]; // Error: Array size missing in 'objects' id keys[]; // Error: Array size missing in 'keys' [myDictionary getObjects:&objects andKeys:&keys]; for (int i = 0; i < count; i++) { id obj = objects[i]; id key = keys[i]; } . NSDictionary *myDictionary = ...; NSInteger count = [myDictionary count]; id objects[count]; id keys[count]; [myDictionary getObjects:&objects andKeys:&keys]; // Warning: Passing argument 1 of 'getObjects:andKeys:' from incompatible pointer type. for (int i = 0; i < count; i++) { id obj = objects[i]; id key = keys[i]; } Please provide a working example of this method.

    Read the article

  • 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

  • Cast an NSDictionary value while applying an NSPredicate?

    - by RickiG
    Hi I have an Array of NSDictionary objects. These Dictionaries are parsed from a JSON file. All value objects in the NSDictionary are of type NSString, one key is called "distanceInMeters". I had planned on filtering these arrays using an NSPredicate, so I started out like this: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(distanceInMeters <= %f)", newValue]; NSArray *newArray = [oldArray filteredArrayUsingPredicate:predicate]; I believe this would have worked if the value for the "distanceInMeters" key was an NSNumber, but because I have it from a JSON file everything is NSStrings. The above gives this error:* -[NSCFNumber length]: unrecognized selector sent to instance 0x3936f00** Which makes sense as I had just tried to treat an NSString as an NSNumber. Is there a way to cast the values from the dictionary while they are being filtered, or maybe a completely different way of getting around this? Hope someone can help me :)

    Read the article

  • Creating Drill-Down Detail UITableView from JSON NSDictionary

    - by Michael Robinson
    I'm have a load of trouble finding out how to do this, I want to show this in a UITableDetailView (Drill-Down style) with each item in a different cell. All of the things I've read all show how to load a single image on the detail instead of showing as a UITableView. Does the dictionary have to have "children" in order to load correctly? Here is the code for the first view creating *dict from the JSON rowsArray. I guess what I'm looking for is what to put in the FollowingDetailViewController.m to see the rest of *dict contents, so when selecting a row, it loads the rest of the *dict. I have rowsArray coming back as follows: '{ loginName = Johnson; memberid = 39; name = Kris; age = ;}, etc,etc... Thanks, // SET UP TABLE & CELLS - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; } NSDictionary *dict = [rowsArray objectAtIndex: indexPath.row]; cell.textLabel.text = [dict objectForKey:@"name"]; cell.detailTextLabel.text = [dict objectForKey:@"loginName"]; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; return cell; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; - (void)viewDidLoad { [super viewDidLoad]; //GET JSON FROM WEBSERVICES: NSURL *url = [NSURL URLWithString:@"http://10.0.1.8/~imac/iphone/jsontest.php"]; NSString *jsonreturn = [[NSString alloc] initWithContentsOfURL:url]; NSData *jsonData = [jsonreturn dataUsingEncoding:NSUTF32BigEndianStringEncoding]; NSError *error = nil; NSDictionary * dict = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error]; if (dict) { rowsArray = [dict objectForKey:@"member"]; [rowsArray retain]; } [jsonreturn release]; } //GO TO DETAIL VIEW: - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { FollowingDetailViewController *aFollowDetail = [[FollowingDetailViewController alloc] initWithNibName:@"FollowingDetailView" bundle:nil]; [self.navigationController pushViewController:aFollowDetail animated:YES]; }

    Read the article

  • Using objective-c objects with an NSDictionary

    - by Mark
    I want store a URL against a UILabel so that when a user touches the label it takes them to that URL in a UIWebView. I have declared a NSDictionary like so: NSMutableArray *linksArray = [[NSMutableArray alloc] init]; [linksArray addObject: [NSValue valueWithNonretainedObject: newsItem1ReadMoreLabel]]; [linksArray addObject: [NSValue valueWithNonretainedObject: newsItem2ReadMoreLabel]]; [linksArray addObject: [NSValue valueWithNonretainedObject: newsItem3ReadMoreLabel]]; [linksArray addObject: [NSValue valueWithNonretainedObject: newsItem4ReadMoreLabel]]; [linksArray addObject: [NSValue valueWithNonretainedObject: newsItem5ReadMoreLabel]]; //NSString *ageLink = @"http://www.theage.com.au"; NSArray *defaultLinks = [NSArray arrayWithObjects: @"1", @"2", @"3", @"4", @"5", nil]; self.urlToLinkDictionary = [[NSMutableDictionary alloc] init]; self.urlToLinkDictionary = [NSDictionary dictionaryWithObjects:defaultLinks forKeys:linksArray]; Considering I used a NSValue as the key, how do I get/set the URL associated with that key given that I only have references to the UILabels? this is what I have but it doesn't work: for(NSValue *key in [self.urlToLinkDictionary allKeys]) { if ([key nonretainedObjectValue] == linkedLabel) { [self.urlToLinkDictionary setValue:[newsItem link] forKey: key]; } } but I get an error: "objc_exception_throw" resolved

    Read the article

  • NSDictionary - Read BOOL from Internet-Downloaded Plist

    - by David Schiefer
    Hi, I am downloading a PLIST file from my server using NSURLDownload. Once it is downloaded, I read the file using NSDictionary's dictionaryWithContentsOfFile: method. I need to read a BOOL value, so this is my code: if ([dict objectForKey:string] == [NSNumber numberWithBool:YES]) This however always returns NO, no matter what the value is. The same happens if I replace the == with isEqual:. Am I doing this wrong?

    Read the article

  • Objective-C: Loop through NSDictionary to create seperate NSArray's

    - by Nic Hubbard
    I have a large NSDictionary structure that I need to loop through and create seperate NSArray's. Here is the structure: ( { id = { text = ""; }; sub = { text = " , "; }; text = ""; "thumb_url" = { text = ""; }; title = { text = "2010-2011"; }; type = { text = "title"; }; }, { id = { text = "76773"; }; sub = { text = "December 13, 2010"; }; text = ""; "thumb_url" = { text = "http://www.puc.edu/__data/assets/image/0004/76774/varieties/thumb.jpg"; }; title = { text = "College Days - Fall 2010"; }; type = { text = "gallery"; }; }, { id = { text = ""; }; sub = { text = ""; }; text = ""; "thumb_url" = { text = ""; }; title = { text = "2009-2010"; }; type = { text = "title"; }; }, { id = { text = "76302"; }; sub = { text = "December 3, 2010"; }; text = ""; "thumb_url" = { text = "http://www.puc.edu/__data/assets/image/0019/76303/varieties/thumb.jpg"; }; title = { text = "Christmas Colloquy"; }; type = { text = "gallery"; }; } ) Each section has a type key, which I need to check. When it finds the "title" key, I need to add those to an array. Then the next sections that would use the "gallery" key needs to be in its own array until it finds another "title" key. Then the "gallery" keys after that into their own array. I am using this a UITableView section titles and content. So, the NSDictionary above should have one NSArray *titles; array, and two other arrays each containing the galleries that came after the title. I have tried using a for loop but I just can't seem to get it right. And ideas would be appreciated.

    Read the article

  • Can I refer to NSDictionary items numerically?

    - by cannyboy
    I'm trying to set up a UITableView which acts as a form. Each cell has within it a UILabel and a UITextField, so one cell is: Name <enter name> ^ ^ UILabel UITextField Now, I'm trying to populate the UILabel and the UITextField from a NSDictionary (from a plist), where it's organized like so: Root Type Value Name String Address String City String etc But in order to get the right labels and textfields in the cellForRowAtIndexPath method, I would have to refer to the Dictionary numerically. Is there any way to do that?

    Read the article

  • Avoiding sorting in NSDictionary

    - by RVN
    I was using NSDictionary and i observed that the objects in the dictionary are sorted automatically with respect to the keys, so my question is how to avoid this sorting , any flag available to set it off, so i get the object in same order i entered. i know u may be thinking what difference it makes in dictionary since we retrieve the value with respect to key, but i am first getting allKeys from which i receive Array of keys , this order is what i need it to be in the order of how i entered just as in NSArray. give your comments if the question is not clear. Thanks

    Read the article

  • Unable to use 'class' as a key in NSDictionary with Xcode 4.5

    - by Vivin Paliath
    I'm trying to use a class as a key in an NSDictionary. I looked at the answer to this question and what I have is pretty much the same; I'm using setObject: forKey:. However, XCode complains, saying Incompatible pointer types sending 'Class' to parameter of type 'id<NSCopying>'. The call I have is: [_bugTypeToSerializerDictionary setObject: bugToStringSerializer forKey: [bugToStringSerializer serializedObjectType]]; bugToStringSerializer is an instance of BugToStringSerializer whose concrete implementations implement serializedObjectType. An example of a concrete implementation looks like this: - (Class) serializedObjectType { return [InfectableBug class]; } What am I doing wrong here?

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >