Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3877212
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:28:17+00:00 2026-05-19T22:28:17+00:00

I am not a Cocoa developer, but I have been dabbling in it to

  • 0

I am not a Cocoa developer, but I have been dabbling in it to build some plugins for PhoneGap. This particular plugin method is either 1) crashing the app without saying why or 2) complaining about how I release/don’t release an object. I have tried a ton of things on my end, including using an Enumerator instead of the for loop. If anyone can point me in the right direction, that would be awesome. I don’t mind legwork:

- (void)getPreferences:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options {
    NSUInteger argc = [arguments count];
    NSString* jsCallback = nil;

    if (argc > 0) {
        jsCallback = [arguments objectAtIndex:0];
    } else {
        NSLog(@"Preferences.getPreferences: Missing 1st parameter.");
        return;
    }

    NSDictionary *defaults = [[NSUserDefaults standardUserDefaults] dictionaryRepresentation];
    NSMutableArray *keys = (NSMutableArray *) [options objectForKey:@"keys"];
    NSMutableDictionary *values = [[NSMutableDictionary alloc] init];

    NSUInteger ky = [keys count];
    for (int i = 0; i < ky; i ++) {
        @try {

            [values  setObject:[defaults objectForKey:[keys objectAtIndex:i]] forKey:[keys objectAtIndex:i]];
        }
        @catch (NSException * err) {
            NSLog(@"Error %@", err);
        }
    }

    [keys release];

    NSString* jsString = [[NSString alloc] initWithFormat:@"%@(%@);", jsCallback, [values JSONRepresentation]];

    [defaults release];
    [values release];

    [webView stringByEvaluatingJavaScriptFromString:jsString];

    [jsString release];
}

Human version:

  1. options contains a dictionary with a single key of “keys”
  2. that key contains an array of strings (that are going to be used as keys for lookup)
  3. I want to loop through that array and
  4. For every value that exists in defaults for that key, copy it to values using the same key
  5. Finally, I want to send that values back as JSON (This part was working when I just passed the entire defaults object in, so I think the JSON method is working)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T22:28:18+00:00Added an answer on May 19, 2026 at 10:28 pm

    From your code, it follows that you ‘own’ objects values and jsString (the ones you created with alloc), so you should release them and not any other.
    You can read more on memory management here.

    Is this the whole code? Also, what exactly error do you get?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Comparing Strings in Cocoa Why is this code not recognising the NSString
I am playing with Autolayout in Cocoa and some things are not clear for
I have never made an app using XCode and Cocoa but I think following
First of all, I am a a very new Objective C/Cocoa iOS Developer but
I am an Objective-C newbie, who still does not have a Mac, but still
I've been a software developer (mainly Visual Studio) for many years and have been
I have been searching for this on Google for a while and maybe I'm
I know, this has been asked a few times, but mostly for Xcode 3.x.
I have read http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Collections/Articles/Arrays.html%23//apple_ref/doc/uid/20000132-SW5 But I did not find a solution to my problem.
I am Completely new to Objective C and Cocoa programming. Why does NSApplicationMain not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.