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 8738653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:46:28+00:00 2026-06-13T10:46:28+00:00

I’m not sure if this is possible, but I’ve seen people do crazy things

  • 0

I’m not sure if this is possible, but I’ve seen people do crazy things with regex and other tools.

I want to convert this plist to an Objective-C literals:

<dict>
    <key>ar</key>
    <array>
        <string>+54## #### ####</string>
        <string>## #### ####</string>
    </array>
    <key>at</key>
    <array>
        <string>+43 1 ########</string>
        <string>+43 ############</string>

</dict>

converted to:

NSDictionary *dic = @{ 
     @"ar" : @[@"+54## #### ####", @"## #### ####"],
     @"at" : @[@"+43 1 ########",@"+43 ############"]
};

Is it possible to automate such conversion? This guy did something similiar: he parsed a PHP list into an NSDictionary using VIM.

  • 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-06-13T10:46:29+00:00Added an answer on June 13, 2026 at 10:46 am

    Plist don’t have a separate ‘format’ for use in code (this question doesn’t quite make sense as-is). You either want to 1. generate Objective-C code which initializes the dictionary with these values, or 2. initialize the dictionary using the file, for which you can write

    NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:@"UIPhoneFormats.plist"];
    

    Edit: so you want to generate Objective-C code that in turn will reproduce the same dictionary. For this, you need to re-print the contents of the dictionary in a formatted way. You can write a program like this:

    #import <stdio.h>
    #import <Foundation/Foundation.h>
    
    NSString *recursiveDump(id object)
    {
        if ([object isKindOfClass:[NSString class]]) {
            return [NSString stringWithFormat:@"@\"%@\"", object];
        } else if ([object isKindOfClass:[NSNumber class]]) {
            return [NSString stringWithFormat:@"@%@", object];
        } else if ([object isKindOfClass:[NSArray class]]) {
            NSMutableString *str = [NSMutableString stringWithString:@"@["];
            NSInteger size = [object count];
            NSInteger i;
            for (i = 0; i < size; i++) {
                if (i > 0) [str appendString:@", "];
                [str appendString:recursiveDump([object objectAtIndex:i])];
            }
            [str appendString:@"]"];
            return str;
        } else if ([object isKindOfClass:[NSDictionary class]]) {
            NSMutableString *str = [NSMutableString stringWithString:@"@{"];
            NSString *key;
            NSInteger size = [object count];
            NSArray *keys = [object allKeys];
            NSInteger i;
            for (i = 0; i < size; i++) {
                if (i > 0) [str appendString:@", "];
                key = [keys objectAtIndex:i];
                [str appendFormat:@"%@: %@", recursiveDump(key), recursiveDump([object objectForKey:key])];
            }
            [str appendString:@"}"];
            return str;
        } else {
            // feel free to implement handling NSData and NSDate here,
            // it's not that straighforward as it is for basic data types.
        }
    }
    
    
    int main(int argc, char *argv[])
    {
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    
        NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:@"UIPhoneFormats.plist"];
        NSMutableString *code = [NSMutableString stringWithString:@"NSDictionary *dict = "];
        [code appendString:recursiveDump(dict)];
        [code appendString:@";"];
        printf("%s\n", [code UTF8String]);
    
        [pool release];
        return 0;
    }
    

    This program will generate (hopefully syntax error-free) Objective-C initialization code out of the provided property list which can be copy-pasted to a project and be used.

    Edit: I just run the program on a stripped version of the plist file OP has provided (the original file was way too large, so I cut it a bit) and it generated the following code:

    NSDictionary *dict = @{@"at": @[@"+43 1 ########", @"+43 ############", @"01 ########", @"00 $"], @"ar": @[@"+54## #### ####", @"## #### ####", @"00 $", @"18 ### $ "]};
    

    To verify it was really valid, I pasted this into the middle of an int main() to a file called ‘test.m’, so I got this program:

    #import <Foundation/Foundation.h>
    
    int main()
    {
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    
        NSDictionary *dict = @{@"at": @[@"+43 1 ########", @"+43 ############", @"0$
        NSLog(@"%@", dict);
    
        [pool release];
        return 0;
    }
    

    To verify, I run clang -o test test.m -lobjc -framework Foundation and surprise, surprise:

    It worked.

    Edit 2: I made this a command line utility, just to facilitate further work – who knows, this may be useful in the future. Plist2ObjC

    Hope this helps.

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

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this
I want to construct a data frame in an Rcpp function, but when I
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.