Skip to content

Latest commit

 

History

History
54 lines (41 loc) · 2.12 KB

inline-swift5.md

File metadata and controls

54 lines (41 loc) · 2.12 KB

Template Information

Name Description
File name json/inline-swift5.stencil
Configuration example
json:
inputs: path/to/json/dir-or-file
outputs:
templateName: inline-swift5
output: JSON.swift
Language Swift 5
Author David Jennes

When to use it

  • When you need to generate Swift 5 code.
  • Embeds the data from the JSON 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 Name Default Value Description
enumName JSONFiles Allows you to change the name of the generated enum containing all files.
forceFileNameEnum N/A Setting this parameter will generate an enum <FileName> even if only one FileName was provided as input.
preservePath N/A Setting 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.
publicAccess N/A If set, the generated constants will be marked as public. Otherwise, they'll be declared internal.

Generated Code

Extract:

internal enum JSONFiles {
  internal enum Array {
    internal static let items: [String] = ["Anna", "Bob"]
  }
  internal enum Configuration {
    internal static let apiVersion: String = "2"
    internal static let country: Any? = nil
    internal static let environment: String = "staging"
    internal static let options: [String: Any] = ["screen-order": ["1", "2", "3"]]
  }
}

Full generated code

Usage example

// This will be an dictionary
let foo = JSONFiles.Configuration.options

// This will be an [String]
let bar = JSONFiles.Array.items