Swift3 Template Information¶ ↑
| Name | Description | | ——— | —————– | | Folder name | templates/swift3 | | Invocation example | gyro -m <model> -t swift3 …
| | Language | Swift 3 and Swift 4 |
When to use it¶ ↑
This template is the reference for swift 3 with Realm generation code. This template is compatible with swift 4. You can use it when you need to work with Realm
Customization¶ ↑
You can use the following parameters to inject custom values to this template (using --param KEY:VALUE
on the command line):
Parameter Key | Description |
---|---|
`public` | If set to true, every generated model and properties will be declared `public`. Otherwise it will not be annotated with access scope keyword, so will default to `internal` |
Description¶ ↑
In this template, optional Realm objects (Attributes - RealmOptional - or Relationships - List<> -) are let
properties (which is conform to the Realm documentation). This is the template to use when you use RealmSwift.
// Attribute generation {%- if attribute.is_number == true or attribute.is_bool == true %} let {{ attribute.name }} = RealmOptional<{{ convert_type }}>() {%- else %} @objc dynamic var {{ attribute.name }}: {{ convert_type }}? {%- endif -%} // Relationship generation {%- if relationship.inverse == false %} {%- if relationship.type == "to_many" %} let {{ relationship.name }} = List<{{ relationship.inverse_type }}>() {%- else %} @objc dynamic var {{ relationship.name }}: {{ relationship.inverse_type }}? {%- endif %} {%- endif %}
Generated Code¶ ↑
Product.swift
:
/* DO NOT EDIT | Generated by gyro */ import RealmSwift import Foundation final class Product: Object { enum Attributes: String { case brand = "brand" case name = "name" case price = "price" case users = "users" } @objc dynamic var brand: String? @objc dynamic var name: String = "" let price = RealmOptional<Int32>() let users = List<Users>() }