PadCodedocs

Files

Add JSON, CSV and text files to an app, and read them into variables with Load File.

Files are data your app carries with it: a menu as JSON, a price list as CSV, some text. Add them in the Assets tab, then read one into a variable with the Load File action.

#Add a file

  1. Open the Assets tab in the left panel (or press ⌘4).
  2. Under Files, tap Add file.
  3. Pick one or more files in Files.

Each file is listed under Files by its name and extension, like menu.json, with an icon for its kind. Files are named the way images are: lowercase letters, numbers, dashes and underscores, with a number added if the name is taken by another file, image or font.

Any kind of file can go in. Image files go to Images and .ttf or .otf fonts go to Fonts, where they belong; everything else goes to Files.

#Read a file in your app

The Load File action reads one of these files into a variable while the app runs:

  1. Select the view whose steps should load it, like a button, and open the Inspector's Actions tab.
  2. Pick when it runs, tap Add action and choose Load File (under Data).
  3. Set File to one of the app's files. The menu lists them by name, without the extension. With no files yet, it says Add one in Assets.
  4. Set Into to the variable that will hold what it reads.

What the variable gets depends on the file:

FileWhat it becomes
JSONIts values: a list, a record, a number, text and so on.
CSVA list of records, one per row. The first row names the fields, and every value is text.
Anything elseIts text.

If the file isn't there, or can't be read as text (a sound, say), the step fails with a message saying so. Wrap it in Try to handle that.

#Files people pick or save

The files in Assets are yours, and they're the same for everyone who uses the app. For files that people using your app choose or keep:

  • Pick File opens Files so the person can choose a file.
  • Save File saves text, JSON or a CSV table to Files. It opens Files so the person can choose where; it doesn't add the file to your app's Assets.

#Delete a file

Long-press a file and choose Delete File.

#See also