Back to Swiftgen

Inline Swift5

Documentation/templates/plist/inline-swift5.md

6.6.32.1 KB
Original Source

Template Information

NameDescription
File nameplist/inline-swift5.stencil
Configuration example<pre>plist:
inputs: path/to/plist/dir-or-file
outputs:
templateName: inline-swift5
output: Plist.swift</pre> |

| Language | Swift 5 | | Author | David Jennes |

When to use it

  • When you need to generate Swift 5 code.
  • Embeds the data from the Plist file directly in your Swift code.

Customization

You can customize some elements of this template by overriding the following parameters when invoking swiftgen. See the dedicated documentation.

Parameter NameDefault ValueDescription
enumNamePlistFilesAllows you to change the name of the generated enum containing all files.
forceFileNameEnumN/ASetting this parameter will generate an enum <FileName> even if only one FileName was provided as input.
preservePathN/ASetting this parameter will disable the basename filter applied to all file paths. Use this if you added your data folder as a "folder reference" in your Xcode project, making that folder hierarchy preserved once copied in the build app bundle. The path will be relative to the folder you provided to SwiftGen.
publicAccessN/AIf set, the generated constants will be marked as public. Otherwise, they'll be declared internal.

Generated Code

Extract:

swift
internal enum PlistFiles {
  internal enum Configuration {
    internal static let environment: String = "development"
    internal static let options: [String: Any] = ["Animation Style": "Party Mode"]
  }
  internal enum ShoppingList {
    internal static let items: [String] = ["Eggs", "Bread", "Milk"]
  }
}

Full generated code

Usage example

swift
// This will be an array
let foo = PlistFiles.ShoppingList.items

// This will be an String
let bar = PlistFiles.Configuration.environment