Search Results

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

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

  • how do you make a "concurrent queue safe" lazy loader (singleton manager) in objective-c

    - by Rich
    Hi, I made this class that turns any object into a singleton, but I know that it's not "concurrent queue safe." Could someone please explain to me how to do this, or better yet, show me the code. To be clear I want to know how to use this with operation queues and dispatch queues (NSOperationQueue and Grand Central Dispatch) on iOS. Thanks in advance, Rich EDIT: I had an idea for how to do it. If someone could confirm it for me I'll do it and post the code. The idea is that proxies make queues all on their own. So if I make a mutable proxy (like Apple does in key-value coding/observing) for any object that it's supposed to return, and always return the same proxy for the same object/identifier pair (using the same kind of lazy loading technique as I used to create the singletons), the proxies would automatically queue up the any messages to the singletons, and make it totally thread safe. IMHO this seems like a lot of work to do, so I don't want to do it if it's not gonna work, or if it's gonna slow my apps down to a crawl. Here's my non-thread safe code: RMSingletonCollector.h // // RMSingletonCollector.h // RMSingletonCollector // // Created by Rich Meade-Miller on 2/11/11. // Copyright 2011 Rich Meade-Miller. All rights reserved. // #import <Foundation/Foundation.h> #import "RMWeakObjectRef.h" struct RMInitializerData { // The method may take one argument. // required SEL designatedInitializer; // data to pass to the initializer or nil. id data; }; typedef struct RMInitializerData RMInitializerData; RMInitializerData RMInitializerDataMake(SEL initializer, id data); @interface NSObject (SingletonCollector) // Returns the selector and data to pass to it (if the selector takes an argument) for use when initializing the singleton. // If you override this DO NOT call super. + (RMInitializerData)designatedInitializerForIdentifier:(NSString *)identifier; @end @interface RMSingletonCollector : NSObject { } + (id)collectionObjectForType:(NSString *)className identifier:(NSString *)identifier; + (id<RMWeakObjectReference>)referenceForObjectOfType:(NSString *)className identifier:(NSString *)identifier; + (void)destroyCollection; + (void)destroyCollectionObjectForType:(NSString *)className identifier:(NSString *)identifier; @end // ==--==--==--==--==Notifications==--==--==--==--== extern NSString *const willDestroySingletonCollection; extern NSString *const willDestroySingletonCollectionObject; RMSingletonCollector.m // // RMSingletonCollector.m // RMSingletonCollector // // Created by Rich Meade-Miller on 2/11/11. // Copyright 2011 Rich Meade-Miller. All rights reserved. // #import "RMSingletonCollector.h" #import <objc/objc-runtime.h> NSString *const willDestroySingletonCollection = @"willDestroySingletonCollection"; NSString *const willDestroySingletonCollectionObject = @"willDestroySingletonCollectionObject"; RMInitializerData RMInitializerDataMake(SEL initializer, id data) { RMInitializerData newData; newData.designatedInitializer = initializer; newData.data = data; return newData; } @implementation NSObject (SingletonCollector) + (RMInitializerData)designatedInitializerForIdentifier:(NSString *)identifier { return RMInitializerDataMake(@selector(init), nil); } @end @interface RMSingletonCollector () + (NSMutableDictionary *)singletonCollection; + (void)setSingletonCollection:(NSMutableDictionary *)newSingletonCollection; @end @implementation RMSingletonCollector static NSMutableDictionary *singletonCollection = nil; + (NSMutableDictionary *)singletonCollection { if (singletonCollection != nil) { return singletonCollection; } NSMutableDictionary *collection = [[NSMutableDictionary alloc] initWithCapacity:1]; [self setSingletonCollection:collection]; [collection release]; return singletonCollection; } + (void)setSingletonCollection:(NSMutableDictionary *)newSingletonCollection { if (newSingletonCollection != singletonCollection) { [singletonCollection release]; singletonCollection = [newSingletonCollection retain]; } } + (id)collectionObjectForType:(NSString *)className identifier:(NSString *)identifier { id obj; NSString *key; if (identifier) { key = [className stringByAppendingFormat:@".%@", identifier]; } else { key = className; } if (obj = [[self singletonCollection] objectForKey:key]) { return obj; } // dynamic creation. // get a class for Class classForName = NSClassFromString(className); if (classForName) { obj = objc_msgSend(classForName, @selector(alloc)); // if the initializer takes an argument... RMInitializerData initializerData = [classForName designatedInitializerForIdentifier:identifier]; if (initializerData.data) { // pass it. obj = objc_msgSend(obj, initializerData.designatedInitializer, initializerData.data); } else { obj = objc_msgSend(obj, initializerData.designatedInitializer); } [singletonCollection setObject:obj forKey:key]; [obj release]; } else { // raise an exception if there is no class for the specified name. NSException *exception = [NSException exceptionWithName:@"com.RMDev.RMSingletonCollector.failed_to_find_class" reason:[NSString stringWithFormat:@"SingletonCollector couldn't find class for name: %@", [className description]] userInfo:nil]; [exception raise]; [exception release]; } return obj; } + (id<RMWeakObjectReference>)referenceForObjectOfType:(NSString *)className identifier:(NSString *)identifier { id obj = [self collectionObjectForType:className identifier:identifier]; RMWeakObjectRef *objectRef = [[RMWeakObjectRef alloc] initWithObject:obj identifier:identifier]; return [objectRef autorelease]; } + (void)destroyCollection { NSDictionary *userInfo = [singletonCollection copy]; [[NSNotificationCenter defaultCenter] postNotificationName:willDestroySingletonCollection object:self userInfo:userInfo]; [userInfo release]; // release the collection and set it to nil. [self setSingletonCollection:nil]; } + (void)destroyCollectionObjectForType:(NSString *)className identifier:(NSString *)identifier { NSString *key; if (identifier) { key = [className stringByAppendingFormat:@".%@", identifier]; } else { key = className; } [[NSNotificationCenter defaultCenter] postNotificationName:willDestroySingletonCollectionObject object:[singletonCollection objectForKey:key] userInfo:nil]; [singletonCollection removeObjectForKey:key]; } @end RMWeakObjectRef.h // // RMWeakObjectRef.h // RMSingletonCollector // // Created by Rich Meade-Miller on 2/12/11. // Copyright 2011 Rich Meade-Miller. All rights reserved. // // In order to offset the performance loss from always having to search the dictionary, I made a retainable, weak object reference class. #import <Foundation/Foundation.h> @protocol RMWeakObjectReference <NSObject> @property (nonatomic, assign, readonly) id objectRef; @property (nonatomic, retain, readonly) NSString *className; @property (nonatomic, retain, readonly) NSString *objectIdentifier; @end @interface RMWeakObjectRef : NSObject <RMWeakObjectReference> { id objectRef; NSString *className; NSString *objectIdentifier; } - (RMWeakObjectRef *)initWithObject:(id)object identifier:(NSString *)identifier; - (void)objectWillBeDestroyed:(NSNotification *)notification; @end RMWeakObjectRef.m // // RMWeakObjectRef.m // RMSingletonCollector // // Created by Rich Meade-Miller on 2/12/11. // Copyright 2011 Rich Meade-Miller. All rights reserved. // #import "RMWeakObjectRef.h" #import "RMSingletonCollector.h" @implementation RMWeakObjectRef @dynamic objectRef; @synthesize className, objectIdentifier; - (RMWeakObjectRef *)initWithObject:(id)object identifier:(NSString *)identifier { if (self = [super init]) { NSString *classNameForObject = NSStringFromClass([object class]); className = classNameForObject; objectIdentifier = identifier; objectRef = object; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(objectWillBeDestroyed:) name:willDestroySingletonCollectionObject object:object]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(objectWillBeDestroyed:) name:willDestroySingletonCollection object:[RMSingletonCollector class]]; } return self; } - (id)objectRef { if (objectRef) { return objectRef; } objectRef = [RMSingletonCollector collectionObjectForType:className identifier:objectIdentifier]; return objectRef; } - (void)objectWillBeDestroyed:(NSNotification *)notification { objectRef = nil; } - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; [className release]; [super dealloc]; } @end

    Read the article

  • Trying to parse twitter trends

    - by timothy5216
    Im trying to parse twitter trends but i keep getting a parser error at "as_of". anyone know why this is happening? EDIT: Here is the code im using NSMutableArray *tweets; tweets = [[NSMutableArray alloc] init]; NSURL *url = [NSURL URLWithString:@"http://search.twitter.com/trends/current.json"]; trendsArray = [[NSMutableArray alloc] initWithArray:[CCJSONParser objectFromJSON:[NSString stringWithContentsOfURL:url encoding:4 error:nil]]]; NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; for (int i = 0; i < [trendsArray count]; i++) { dict = [[NSMutableDictionary alloc] init]; //[post setObject: [[currentArray objectAtIndex:i] objectForKey:@"query"]]; [dict setObject:[trendsArray objectAtIndex:i] forKey:@"trends"]; //[dict setObject:[trendsArray objectAtIndex:i] forKey:@"query"]; //[post setObject:[trendsArray objectAtIndex:i] forKey:@"as_of"]; [tweets addObject:dict]; //post = nil; }

    Read the article

  • Question about memory usage

    - by sudo rm -rf
    Hi there. I have the following method: +(NSMutableDictionary *)getTime:(float)lat :(float)lon { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init]; [dictionary setObject:hour forKey:@"hour"]; [dictionary setObject:minute forKey:@"minute"]; [dictionary setObject:ampm forKey:@"ampm"]; return dictionary; } A lot of the method is chopped off, so I think I need the pool for some other stuff in the method. Here's my question. I know that I need to release the following objects: [dictionary release]; [pool release]; However, I can't release the dictionary before I return it, but as soon as I return it the rest of the method isn't performed. What should I do?

    Read the article

  • Creating a JSONRepresentation of my NSDictionary messes up the order?

    - by Lewion
    Hi all, To pass data to my webservice, I create an NSDictionary with the objects and keys I need, and use JSONRepresentation to format it nicely so I can post it to my service. It all worked fine with the previous version where only 2 parameters were required. An array with listitems, and a UDID. No I also need to pass a version number because we need to provide more data for people with the application at this new version. Only problem is when I create my JSONRepresentation now, the order of things are all messed up. NSMutableDictionary *rowDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:arrayDict,@"basketListV2",sharedData.udid,@"UDID",@"1.4",@"version",nil]; It prints out version first, then UDID and then basketListV2. Anyone know what I can do to maintain the order of my NSDict? I tried both NSDictionary and NSMutableDictionary (Probably doesn't have to do anything with it but for testing purposes I had to try it.) Thanks in advance. Lewion

    Read the article

  • Approaches to create a nested tree structure of NSDictionaries?

    - by d11wtq
    I'm parsing some input which produces a tree structure containing NSDictionary instances on the branches and NSString instance at the nodes. After parsing, the whole structure should be immutable. I feel like I'm jumping through hoops to create the structure and then make sure it's immutable when it's returned from my method. We can probably all relate to the input I'm parsing, since it's a query string from a URL. In a string like this: a=foo&b=bar&a=zip We expect a structure like this: NSDictionary { "a" => NSDictionary { 0 => "foo", 1 => "zip" }, "b" => "bar" } I'm keeping it just two-dimensional in this example for brevity, though in the real-world we sometimes see var[key1][key2]=value&var[key1][key3]=value2 type structures. The code hasn't evolved that far just yet. Currently I do this: - (NSDictionary *)parseQuery:(NSString *)queryString { NSMutableDictionary *params = [NSMutableDictionary dictionary]; NSArray *pairs = [queryString componentsSeparatedByString:@"&"]; for (NSString *pair in pairs) { NSRange eqRange = [pair rangeOfString:@"="]; NSString *key; id value; // If the parameter is a key without a specified value if (eqRange.location == NSNotFound) { key = [pair stringByReplacingPercentEscapesUsingEncoding:NSASCIIStringEncoding]; value = @""; } else { // Else determine both key and value key = [[pair substringToIndex:eqRange.location] stringByReplacingPercentEscapesUsingEncoding:NSASCIIStringEncoding]; if ([pair length] > eqRange.location + 1) { value = [[pair substringFromIndex:eqRange.location + 1] stringByReplacingPercentEscapesUsingEncoding:NSASCIIStringEncoding]; } else { value = @""; } } // Parameter already exists, it must be a dictionary if (nil != [params objectForKey:key]) { id existingValue = [params objectForKey:key]; if (![existingValue isKindOfClass:[NSDictionary class]]) { value = [NSDictionary dictionaryWithObjectsAndKeys:existingValue, [NSNumber numberWithInt:0], value, [NSNumber numberWithInt:1], nil]; } else { // FIXME: There must be a more elegant way to build a nested dictionary where the end result is immutable? NSMutableDictionary *newValue = [NSMutableDictionary dictionaryWithDictionary:existingValue]; [newValue setObject:value forKey:[NSNumber numberWithInt:[newValue count]]]; value = [NSDictionary dictionaryWithDictionary:newValue]; } } [params setObject:value forKey:key]; } return [NSDictionary dictionaryWithDictionary:params]; } If you look at the bit where I've added FIXME it feels awfully clumsy, pulling out the existing dictionary, creating an immutable version of it, adding the new value, then creating an immutable dictionary from that to set back in place. Expensive and unnecessary? I'm not sure if there are any Cocoa-specific design patterns I can follow here?

    Read the article

  • iPhone App not saving values to .plist file

    - by Trent
    Hey everyone. I am working on an app that displays a modal the first time the consumer uses it. I have a .plist file that will store the information I request once the Save button is pressed. I can read from the .plist file fine and when I run my save method it SEEMS to work fine but the .plist file is not updating. I'm not so sure of the problem here. I show the modal like this. - (void) getConsumerInfo { NSString *filePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"consumer.plist"]; NSMutableDictionary *plistConsumerInfo = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath]; NSString *hasAppeared = [plistConsumerInfo objectForKey:@"HasAppeared"]; if(hasAppeared != kHasAppeared) { ConsumerInfoViewController *tmpConsumerInfoVC = [[ConsumerInfoViewController alloc] initWithNibName:@"ConsumerInfoView" bundle:nil]; self.consumerInfoViewController = tmpConsumerInfoVC; [self presentModalViewController:consumerInfoViewController animated:YES]; [tmpConsumerInfoVC release]; } } This is called by the viewDidLoad method in the first view phone when the app is started. Within the consumerInfoViewController I have textfields that have data entered and when the Save button is pressed it calls this method. - (IBAction)saveConsumerInfo:(id)sender { NSString *filePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"consumer.plist"]; NSMutableDictionary *plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath]; NSString *tmpDiversName = txtDiversName.text; NSString *tmpLicenseType = txtLicenseType.text; NSString *tmpLicenseNum = txtLicenseNumber.text; NSString *tmpHasAppeared = @"1"; NSString *tmpNumJumps = @"3"; [plistDict setValue:[[NSString alloc] initWithFormat:@"%@", tmpDiversName] forKey:@"ConsumerName"]; [plistDict setValue:[[NSString alloc] initWithFormat:@"%@", tmpLicenseType] forKey:@"LicenseType"]; [plistDict setValue:[[NSString alloc] initWithFormat:@"%@", tmpLicenseNum] forKey:@"LicenseNumb"]; [plistDict setValue:[[NSString alloc] initWithFormat:@"%@", tmpNumJumps] forKey:@"NumJumps"]; [plistDict setValue:[[NSString alloc] initWithFormat:@"%d", tmpHasAppeared] forKey:@"Show"]; [plistDict writeToFile:filePath atomically: YES]; NSLog([[NSString alloc] initWithContentsOfFile:filePath]); [self dismissModalViewControllerAnimated:YES]; } This all runs fine with no hiccups but the file is never updated. I would like it to update so I can use this information throughout the app and update the flag so it will not show the view again once the data is entered. Please let me know if there is anymore information you need. Thanks in advance!

    Read the article

  • wait after presentModalViewController

    - by Cesar
    I need to wait (don't execute the code) after the presentModalViewController until the modal view it's dismissed, it's possible or it's a conceptual error ? -(NSDictionary *)authRequired { [self presentModalViewController:loginRegView animated:YES]; //This view write the settings when dismissed. NSMutableDictionary *ret=[[NSMutableDictionary alloc] init]; [ret setObject:[app.settings get:@"user"] forKey:@"user"]; [ret setObject:[app.settings get:@"pass"] forKey:@"pass"]; return ret; }

    Read the article

  • ios how can user cancel facebook sign in?

    - by Jackson
    When a user gets to this screen, there is no way to cancel out of it. What can I do? To get this view in the first place I am running: NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys: vid, @"link", vid, @"source", vid, @"picture", @"My Place", @"name", @"YouTube Presentation", @"caption", title, @"description", @"Enjoy this Video", @"message", nil]; [app.facebook dialog:@"stream.publish" andParams:params andDelegate:self];

    Read the article

  • Iphone xcode simulator crashes when I move up and down on a table row

    - by Frames84
    I can't get my head round this. When the page loads, everything works fine - I can drill up and down, however 'stream' (in the position I have highlighted below) becomes not equal to anything when I pull up and down on the tableview. But the error is only sometimes. Normally it returns key/pairs. If know one can understand above how to you test for // (int)[$VAR count]} key/value pairs in a NSMutableDictionary object - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *FirstLevelCell = @"FirstLevelCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:FirstLevelCell]; if(cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:FirstLevelCell] autorelease]; } NSInteger row = [indexPath row]; //NSDictionary *stream = (NSDictionary *) [dataList objectAtIndex:row]; NSString *level = self.atLevel; if([level isEqualToString:@"level2"]) { NSMutableDictionary *stream = [[NSMutableArray alloc] init]; stream = (NSMutableDictionary *) [dataList objectAtIndex:row]; // stream value is (int)[$VAR count]} key/value pairs if ([stream valueForKey:@"title"] ) { cell.textLabel.text = [stream valueForKey:@"title"]; cell.textLabel.numberOfLines = 2; cell.textLabel.font =[UIFont systemFontOfSize:10]; NSString *detailText = [stream valueForKey:@"created"]; cell.detailTextLabel.numberOfLines = 2; cell.detailTextLabel.font= [UIFont systemFontOfSize:9]; cell.detailTextLabel.text = detailText; NSString *str = @"http://www.mywebsite.co.uk/images/stories/Cimex.jpg"; NSData *imageURL = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:str]]; UIImage *newsImage = [[UIImage alloc] initWithData:imageURL]; cell.imageView.image = newsImage; [stream release]; } } else { cell.textLabel.text = [dataList objectAtIndex:row]; } return cell; } Thanks for your time

    Read the article

  • CryptoExcercise Encryption/Decryption Problem

    - by venkat
    I am using apples "cryptoexcercise" (Security.Framework) in my application to encrypt and decrypt a data of numeric value. When I give the input 950,128 the values got encrypted, but it is not getting decrypted and exists with the encrypted value only. This happens only with the mentioned numeric values. Could you please check this issue and give the solution to solve this problem? here is my code (void)testAsymmetricEncryptionAndDecryption { uint8_t *plainBuffer; uint8_t *cipherBuffer; uint8_t *decryptedBuffer; const char inputString[] = "950"; int len = strlen(inputString); if (len > BUFFER_SIZE) len = BUFFER_SIZE-1; plainBuffer = (uint8_t *)calloc(BUFFER_SIZE, sizeof(uint8_t)); cipherBuffer = (uint8_t *)calloc(CIPHER_BUFFER_SIZE, sizeof(uint8_t)); decryptedBuffer = (uint8_t *)calloc(BUFFER_SIZE, sizeof(uint8_t)); strncpy( (char *)plainBuffer, inputString, len); NSLog(@"plain text : %s", plainBuffer); [self encryptWithPublicKey:(UInt8 *)plainBuffer cipherBuffer:cipherBuffer]; NSLog(@"encrypted data: %s", cipherBuffer); [self decryptWithPrivateKey:cipherBuffer plainBuffer:decryptedBuffer]; NSLog(@"decrypted data: %s", decryptedBuffer); free(plainBuffer); free(cipherBuffer); free(decryptedBuffer); } (void)encryptWithPublicKey:(uint8_t *)plainBuffer cipherBuffer:(uint8_t *)cipherBuffer { OSStatus status = noErr; size_t plainBufferSize = strlen((char *)plainBuffer); size_t cipherBufferSize = CIPHER_BUFFER_SIZE; NSLog(@"SecKeyGetBlockSize() public = %d", SecKeyGetBlockSize([self getPublicKeyRef])); // Error handling // Encrypt using the public. status = SecKeyEncrypt([self getPublicKeyRef], PADDING, plainBuffer, plainBufferSize, &cipherBuffer[0], &cipherBufferSize ); NSLog(@"encryption result code: %d (size: %d)", status, cipherBufferSize); NSLog(@"encrypted text: %s", cipherBuffer); } (void)decryptWithPrivateKey:(uint8_t *)cipherBuffer plainBuffer:(uint8_t *)plainBuffer { OSStatus status = noErr; size_t cipherBufferSize = strlen((char *)cipherBuffer); NSLog(@"decryptWithPrivateKey: length of buffer: %d", BUFFER_SIZE); NSLog(@"decryptWithPrivateKey: length of input: %d", cipherBufferSize); // DECRYPTION size_t plainBufferSize = BUFFER_SIZE; // Error handling status = SecKeyDecrypt([self getPrivateKeyRef], PADDING, &cipherBuffer[0], cipherBufferSize, &plainBuffer[0], &plainBufferSize ); NSLog(@"decryption result code: %d (size: %d)", status, plainBufferSize); NSLog(@"FINAL decrypted text: %s", plainBuffer); } (SecKeyRef)getPublicKeyRef { OSStatus sanityCheck = noErr; SecKeyRef publicKeyReference = NULL; if (publicKeyRef == NULL) { NSMutableDictionary *queryPublicKey = [[NSMutableDictionary alloc] init]; // Set the public key query dictionary. [queryPublicKey setObject:(id)kSecClassKey forKey:(id)kSecClass]; [queryPublicKey setObject:publicTag forKey:(id)kSecAttrApplicationTag]; [queryPublicKey setObject:(id)kSecAttrKeyTypeRSA forKey:(id)kSecAttrKeyType]; [queryPublicKey setObject:[NSNumber numberWithBool:YES] forKey:(id)kSecReturnRef]; // Get the key. sanityCheck = SecItemCopyMatching((CFDictionaryRef)queryPublicKey, (CFTypeRef *)&publicKeyReference); if (sanityCheck != noErr) { publicKeyReference = NULL; } [queryPublicKey release]; } else { publicKeyReference = publicKeyRef; } return publicKeyReference; } (SecKeyRef)getPrivateKeyRef { OSStatus resultCode = noErr; SecKeyRef privateKeyReference = NULL; if(privateKeyRef == NULL) { NSMutableDictionary * queryPrivateKey = [[NSMutableDictionary alloc] init]; // Set the private key query dictionary. [queryPrivateKey setObject:(id)kSecClassKey forKey:(id)kSecClass]; [queryPrivateKey setObject:privateTag forKey:(id)kSecAttrApplicationTag]; [queryPrivateKey setObject:(id)kSecAttrKeyTypeRSA forKey:(id)kSecAttrKeyType]; [queryPrivateKey setObject:[NSNumber numberWithBool:YES] forKey:(id)kSecReturnRef]; // Get the key. resultCode = SecItemCopyMatching((CFDictionaryRef)queryPrivateKey, (CFTypeRef *)&privateKeyReference); NSLog(@"getPrivateKey: result code: %d", resultCode); if(resultCode != noErr) { privateKeyReference = NULL; } [queryPrivateKey release]; } else { privateKeyReference = privateKeyRef; } return privateKeyReference; }

    Read the article

  • Editing key inside array item - plist

    - by F0u4d
    I have the following plist: <plist version="1.0"> <dict> <key>General</key> <dict> <key>Table 1</key> <array> <dict> <key>subheadingName</key> <string>Item 1 of table 1</string> <key>subheadingDetail</key> <string>details about item 1</string> </dict> <dict> <key>subheadingName</key> <string>Item 2 of table 1</string> <key>subheadingDetail</key> <string>details about item 2!</string> </dict> <dict> <key>subheadingName</key> <string>Item 3 of table 1</string> <key>subheadingDetail</key> <string>details about item 3!</string> </dict> </array> </dict> <key>Table 2</key> <dict> <key>subheadingArr</key> <array> <dict> <key>subheadingName</key> <string>Item 1 of table 2</string> <key>subheadingDetail</key> <string>details about item 1</string> </dict> <dict> <key>subheadingName</key> <string>Item 2 of table 2</string> <key>subheadingDetail</key> <string>details about item 2!</string> </dict> <dict> <key>subheadingName</key> <string>Item 3 of table 2</string> <key>subheadingDetail</key> <string>details about item 3!</string> </dict> </array> </dict> </dict> </plist> I am trying to write and read the I have made these 2 methods trying to read and write subheadingDetail for a specific subheadingName but they are wrong/incomplete and can't manage to get it work. -(void)updateInfo:(NSString *)info forSubHeadingName:(NSString *)subheadingName { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *path = [documentsDirectory stringByAppendingPathComponent:@"DeviceInformation.plist"]; NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile:path]; [data setObject:info forKey:subheadingName]; [data writeToFile:path atomically:YES]; } -(NSString *)readInfoForSubHeadingName:(NSString *)subheadingName { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *path = [documentsDirectory stringByAppendingPathComponent:@"DeviceInformation.plist"]; NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile:path]; return [data objectForKey:subheadingDetail]; } Tried searching around the answers, but couldn't find anything similar to my issue. Thanks in advance.

    Read the article

  • Problem with fetching dictionary objects in array from plist iphone sdk

    - by neha
    Hi all, What is the datatype you use to fetch items whose type is dictionary in plist i.e. nsmutabledictionary or nsdictionary? Because I'm using following code to retrieve dictionary objects from an array of dictionaries in plist. NSMutableDictionary *_myDict = [contentArray objectAtIndex:0]; NSLog(@"MYDICT : %@",_myDict); NSString *myKey = (NSString *)[_myDict valueForKey:@"Contents"] ; [[cell lblFeed] setText:[NSString stringWithFormat:@"%@",myKey]]; Here, on first line it's showing me objc_msgsend. ContentArray is an nsarray and it's contents are showing 2 objects that are there in plist. In plist they are dictionary objects. Then why this error? Can anybody please help? Thanx in advance.

    Read the article

  • How is the presentation layer of a CALayer generated?

    - by KJ
    Hi, I'm having difficulties animating my custom layer property using Core Anmiation. My question is how the presentation of a CALayer is generated. Here is what I have now: @interface MyLayer : CALayer { NSMutableDictionary* customProperties; } @property (nonatomic, copy) NSMutableDictionary* customProperties; @end And when I try to animate the key path "customProperties.roll" using CABasicAnimation and addAnimation:forKey:, it seems that the customProperties variable doesn't get copied from the model layer to the presentation layer, and the customProperties of the presentation layer appears to be nil, failing to update the value for the key "roll". Is there a way to animate values in a dictionary correctly? What is the exact relationship between a model layer and a presentation layer while being animated? Thanks!

    Read the article

  • Objective-C error... Cannot convert to pointer type (int)

    - by Flash84x
    I am attempting to use the TouchXML library and followed the example with the following code for (CXMLElement node in nodes) { NSMutableDictionary *item = [[NSMutableDictionary alloc] init]; int counter; for (counter = 0; counter < [node childCount]; counter++ ) { [item setObject:[[node childAtIndex:counter] stringValue] forKey:[[node childAtIndex:counter] name]]; } [rst addObject:item]; [item release]; } The compiler however is complaining about counter and throwing the following error for counter = 0 and both occurances in the setObject call. Cannot convert to pointer type Any help with my rusty C/ObjC would be appreciated

    Read the article

  • iPhone FBConnect, dashboard.addnews

    - by Dmitry
    Hi, The question is: how to add news via FBConnect?? I have the following code: NSString *newsBody = @"[{\"message\": \"News message\" }]"; NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObject:newsBody forKey:@"news"]; [[FBRequest requestWithDelegate:self] call:@"facebook.dashboard.addnews" params:params dataParam:nil]; After I sent the request I received the success responce. But I can't see the new news in the facebook account!! Also, I tried to add full info into news parameter (http://wiki.developers.facebook.com/index.php/Dashboard.addNews):: NSString *newsBody = @"[{\"message\": \"News message\",\"action_link\": {\"text\": \"link text\", \"href\": \"http: //google.com\"} }]"; But this request returns error :( Thanks in advance!

    Read the article

  • Get objc_exception_throw when setting cookie with ASIHTTPRequest

    - by TuanCM
    I got objc_exception_throw when trying to set cookies for a ASIHTTPRequest request. I tried both of these but it didn't work out. ASIHTTPRequest *request = [[ASIHTTPRequest alloc] initWithURL:url]; NSMutableDictionary *properties = [[NSMutableDictionary alloc] init]; [properties setValue:@".google.com" forKey:@"Domain"]; [properties setValue:@"/" forKey:@"path"]; [properties setValue:@"1600000000" forKey:@"expires"]; NSHTTPCookie *cookie = [[NSHTTPCookie alloc] initWithProperties:properties]; [request setRequestCookies:[NSMutableArray arrayWithObject:cookie]]; or replacing initiating code for cookie with this one NSHTTPCookie *cookie = [[NSHTTPCookie alloc] init]; When I commented out the following line, everything worked fine. [request setRequestCookies:[NSMutableArray arrayWithObject:cookie]]; Can you guys tell me what the problem here!

    Read the article

  • I can create a cookie, but can't delete it from my iPhone app

    - by squeezemylime
    I am creating an iPhone app, and am using this method to create a cookie that will be accessed site-wide: NSMutableDictionary *cookieDictionary = [NSMutableDictionary dictionaryWithCapacity:4]; [cookieDictionary setObject:@"status" forKey:NSHTTPCookieName]; [cookieDictionary setObject:[self.usernameField text] forKey:NSHTTPCookieValue]; [cookieDictionary setObject:@"http://www.mydomain.com" forKey:NSHTTPCookieDomain]; [cookieDictionary setObject:@"/" forKey:NSHTTPCookiePath]; // Build the cookie. NSHTTPCookie *cookie = [NSHTTPCookie cookieWithProperties:cookieDictionary]; // Store the cookie. [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie]; // Log the Cookie and display it for (cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) { NSLog(@"%@", cookie.value); } Now I am trying to delete it via the following method, but it isn't working, and the documentation isn't quite helping me: NSHTTPCookieStorage* cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; NSArray* theCookies = [cookieStorage cookiesForURL:[NSURL URLWithString:@"http://mydomain.com"]]; for (NSHTTPCookie *cookie in theCookies) { [cookieStorage deleteCookie:cookie]; }

    Read the article

  • iphone facebook friend status.

    - by Syed Faraz Haider Zaidi
    NSMutableDictionary * params = [[NSMutableDictionary alloc] init]; [params setValue:@"100000********" forKey:@"uid"]; [params setValue:@"1500" forKey:@"limit"]; [params setValue:@"results" forKey:@"callback"]; when im using this coding im getting my friend status... but when im using a dynamic value like this : [params setValue:[NSString stringWithFormat:@"%@", a] forKey:@"uid"]; im getting this error The operation couldn’t be completed. (facebookErrDomain error 10000.) looking forward for your help guys....

    Read the article

  • Passing Data thru NSTimer UserInfo

    - by zorro2b
    I a trying to pass data thru userInfo for an NSTimer call. What is the best way to do this? I am trying to use an NSDictionary, this is simple enough when I have objective c objects, but what about other data? I want to do something like this, which doesn't work as is: - (void) play:(SystemSoundID)sound target:(id)target callbackSelector:(SEL)selector { NSLog(@"pause ipod"); [iPodController pause]; theSound = sound; NSMutableDictionary *cb = [[NSMutableDictionary alloc] init]; [cb setObject:(id)&sound forKey:@"sound"]; [cb setObject:target forKey:@"target"]; [cb setObject:(id)&selector forKey:@"selector"]; [NSTimer scheduledTimerWithTimeInterval:0 target:self selector: @selector(notifyPause1:) userInfo:(id)cb repeats:NO]; }

    Read the article

  • Writing to a .plist file

    - by sg
    I have a .plist with 2 key values in it. It is of type Dictionary. I am trying to write value to one of the key values. What's wrong with the code below? I also tried using type "Array". That option also does not work. How can I get it to work using Dictionary & also Array? Anyone has working code example? Thanks. I would appreciate any help. NSString *filePath = @"myprefs.plist"; NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath]; [plistDict setValue:@"[email protected]" forKey:@"Email"]; [plistDict writeToFile:filePath atomically: YES];

    Read the article

  • Set Facebook status using iphone app

    - by gmcalab
    I have just started with the new graph api for facebook. I have gotten a few items to work like logging in and getting the user name and displaying this to the screen. I am having trouble figuring out how to set my status with the graph api... I have tried a couple things but I always receive and error response back. Any ideas? NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys: @"test2", @"test", nil]; [_facebook requestWithMethodName:@"status.set" andParams:params andHttpMethod:@"POST" andDelegate:self];

    Read the article

  • How to Insert a <a> tag link in a Facebook wall

    - by Diogo Hacka
    How can I insert a html link like the 2 posts below with the Facebook iOS SDK? Link to Image! In Train Conductor and "itunes.apple.com" for The Fleas post they use a bit.ly link. I tried to use the html tag <a href="www.mystuff.com">Whatever<\a but it didn't work. NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys: @"My game in iTunes", @"name", @"http://www.mystuff.com", @"link", @"Check out this cool game for iPhone.", @"description", nil]; This code works but that is just a normal post.

    Read the article

  • Expected specifier-qualifier-list before 'CGPoint'

    - by Rob
    My project compiles and runs fine unless I try to compile my Unit Test Bundle it bombs out on the following with an "Expected specifier-qualifier-list before 'CGPoint'" error on line 5: #import <Foundation/Foundation.h> #import "Force.h" @interface WorldObject : NSObject { CGPoint coordinates; float altitude; NSMutableDictionary *forces; } @property (nonatomic) CGPoint coordinates; @property (nonatomic) float altitude; @property (nonatomic,retain) NSMutableDictionary *forces; - (void)setObject:(id)anObject inForcesForKey:(id)aKey; - (void)removeObjectFromForcesForKey:(id)aKey; - (id)objectFromForcesForKey:(id)aKey; - (void)applyForces; @end I have made sure that my Unit Test Bundle is a target of my WorldObject.m and it's header is imported in my testing header: #define USE_APPLICATION_UNIT_TEST 1 #import <SenTestingKit/SenTestingKit.h> #import <UIKit/UIKit.h> #import "Force.h" #import "WorldObject.h" @interface LogicTests : SenTestCase { Force *myForce; WorldObject *myWorldObject; } @end

    Read the article

  • fetchedResultsController objectAtIndexPath: i "Passing argument 1 of objectAtIndexPath: makes pointer from integer without cast

    - by cocos2dbeginner
    NSMutableDictionary* dict = [[NSMutableDictionary alloc] init]; id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:0]; for (int i; i<[sectionInfo numberOfObjects]; i++) { NSManagedObject *o = [self.fetchedResultsController objectAtIndexPath:i]; [dict setObject:[[o valueForKey:@"frontCard"] description] forKey:@"frontCard"]; [dict setObject:[[o valueForKey:@"flipCard"] description] forKey:@"flipCard"]; } In this line NSManagedObject *o = [self.fetchedResultsController objectAtIndexPath:i]; i get this warning: warning: passing argument 1 of 'objectAtIndexPath:' makes pointer from integer without a cast

    Read the article

  • How do you pass objects between View Controllers in Objective-C?

    - by editor
    I've been trudging through some code for two days trying to figure out why I couldn't fetch a global NSMutableArray variable I declared in the .h and implemented in .m and set in a the viewDidLoad function. It finally dawned on me: there's no such thing as a global variable in Objective-C, at least not in the PHP sense I've come to know. I didn't ever really read the XCode error warnings, but there it was, even if not quite plain English: "Instance variable 'blah' accessed in class method." My question: What am I supposed to do now? I've got two View Controllers that need to access a central NSMutableDictionary I generate from a JSON file via URL. It's basically an extended menu for all my Table View drill downs, and I'd like to have couple other "global" (non-static) variables. Do I have to grab the JSON each time I want to generate this NSMutableDictionary or is there some way to set it once and access it from various classes via #import? Do I have to write data to a file, or is there another way people usually do this?

    Read the article

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