cyril cyril - 4 months ago 38
iOS Question

How do I obtain a .plist programmatically in Swift?

Background

I have a dictionary with more than 100 keys that I've stored in a property list that I can transfer/load/save to from one Xcode project to another.

Research

I've looked at several posts on StackOverflow but most of them seem to deal with loading a plist from the main bundle, copying it to the Documents directory and loading/saving it from there with no way of retrieving it to use in other projects.

TLDR

I want to be able to 'export' a plist created programmatically as a separate file I can use in other projects unrelated to the current one.

Update

Thanks to @NSNoob I've figured out that I can manually access the new plist from the Documents directory. Now the question is, how? Isn't iOS sandboxed without access to the filesystem unless it's jailbroken?

Answer

You can get Documents directory contents of your app like following:

  1. Connect your device to your mac
  2. Open your Xcode
  3. Click on Window and select Devices

enter image description here

  1. Click on your device
  2. Search for your app in installed apps list
  3. Click on your app
  4. Click on gear icon
  5. Click on Download Container.

enter image description here

  1. Right Click on Saved xcappdata file.
  2. Click on Show package contents.

enter image description here

That will open your documents directory and you will be able to find your modified plist there.