Back to Swiftgen

Structured Swift4

Documentation/templates/files/structured-swift4.md

6.6.32.4 KB
Original Source

Template Information

NameDescription
File namefiles/structured-swift4.stencil
Configuration example<pre>files:
inputs: dir/to/search/with/filter
filter: .+.*$
outputs:
templateName: structured-swift4
output:Files.swift</pre> |

| Language | Swift 4 | | Author | Mike Gray |

When to use it

  • When you need to generate Swift 4 code.

Customization

Parameter NameDefault ValueDescription
bundleBundleToken.bundleAllows you to set from which bundle files are loaded from. By default, it'll point to the same bundle as where the generated code is.
enumNameFilesAllows you to change the name of the generated enum containing the file tree.
preservePathN/ASetting this parameter will disable the basename filter applied to all font paths. Use this if you added your font 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.
resourceTypeNameFileAllows you to change the name of the struct type representing a file.
useExtensiontrueWhether or not to use the extension in the name of the constant. i.e. let testTxt vs let test. Behavior is undefined with file name conflicts.

Generated Code

Extract:

swift
internal enum Files {
  /// test.txt
  internal static let testTxt = File(name: "test", ext: "txt", path: "", mimeType: "text/plain")
  /// subdir/
  internal enum Subdir {
    /// subdir/A Video With Spaces.mp4
    internal static let aVideoWithSpacesMp4 = File(name: "A Video With Spaces", ext: "mp4", path: "subdir", mimeType: "video/mp4")
  }
}

Full generated code

Usage example

swift
// Access files using the `url` or `path` fields
let txt = Files.testTxt.url
let video = Files.Subdir.aVideoWithSpacesMp4.path

// In addition, there are `url(locale:)` and `path(locale:)` to specify a locale
let txt = Files.testTxt.url(locale: Locale.current)
let video = Files.Subdir.aVideoWithSpacesMp4.path(locale: Locale.current)