Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insert or update array values in plist #54

Open
swapnarachapalli opened this issue Jan 9, 2015 · 4 comments
Open

Insert or update array values in plist #54

swapnarachapalli opened this issue Jan 9, 2015 · 4 comments

Comments

@swapnarachapalli
Copy link

Hi,
i need to read the plist file and either insert or update the plist keys with newer values. The values could be array or simple String. How can i do that here ?

-Swapna

@mreinstein
Copy link
Collaborator

You can parse the plist file, which will return a JSON object. At that point you could manipulate the json however you see fit, and then call build() to generate an updated version of the plist file.

@swapnarachapalli
Copy link
Author

Hi,

Thanks a lot for the answer. Can you please help me how to add a "array"
value to key using json ? i was able to add key:value pairs of simple type.

Swapna

On Fri, Jan 9, 2015 at 10:43 PM, Mike Reinstein notifications@github.com
wrote:

You can parse the plist file, which will return a JSON object. At that
point you could manipulate the json however you see fit, and then call
build() to generate a plist file.


Reply to this email directly or view it on GitHub
#54 (comment).

@mreinstein
Copy link
Collaborator

@swapnarachapalli to be honest it's been a while since I've contributed to this library so my memory is a bit rusty. :)

Can you parse a plist that has an array, then inspect the parsed object in the browser console? that should give you a good sense of how to modify an array element.

@decates
Copy link

decates commented Feb 13, 2018

I know this is a while ago, but I needed this for setting arrays and dictionaries, and everything worked as expected:

For a dictionary:

XML:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

The key is modelled as an object, with each key/value pair from the dictionary as a property:

{
  "NSAppTransportSecurity": {
    "NSAllowsArbitraryLoads": true
  }
}

For an array:

XML:

<key>UISupportedInterfaceOrientations</key>
<array>
  <string>UIInterfaceOrientationPortrait</string>
  <string>UIInterfaceOrientationPortraitUpsideDown</string>
</array>

The key is modelled as a javascript array:

{
    "UISupportedInterfaceOrientations": [
       "UIInterfaceOrientationPortrait",
       "UIInterfaceOrientationPortraitUpsideDown"
     ],
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants