Questions tagged [swift-stencil]

6 questions
8
votes
1 answer

How to get a SubString of variable using stencil templating tool for swift

I'm using the stencil template language tool for swift found here: https://github.com/stencilproject/Stencil Using master branch. The Problem given the following .json file { "xcassets" : "dev Sources test1" } I want to be able to retrieve the…
2
votes
1 answer

Remove substring in a string with Stencil

I'm trying to play around with Sourcery to extend some library. I almost succeeded, but at some point I have a type, returned from a func and it is an optional. I want to make it non-optional instead. For this, I have to some how remove the question…
Vladyslav Zavalykhatko
  • 15,202
  • 8
  • 65
  • 100
1
vote
0 answers

Iterating over generic types in a Sourcery template / Swift-Stencil

Does anyone know if there's a way in Sourcery to get a reference to the type a generic inherits from? I'm assuming this question doesn't make immediate sense, so here's some code for what I'm trying to do: Say I have the following in Swift: public…
0
votes
1 answer

How to call a Stencil in swift with different variable name?

I have 2 stencil templates, which pretty much the same except the variable name is different: template #1 {% for p in anArray %} {% if p.property1 = "abc" %} // some logic {% endif %} {% endfor %} template #2 {% for a in aDifferentNameArray…
hap497
  • 154,439
  • 43
  • 83
  • 99
0
votes
2 answers

Access random array element using Sourcery and Stencil

I'm doing some code generation stuff using Sourcery and Stencil. I'm trying to add an extension to all my enums that has a method that returns a random case of the enum. So, in my case, I need a way to access a random array element. I know that we…
Mo Abdul-Hameed
  • 6,030
  • 2
  • 23
  • 36
0
votes
0 answers

How to add array of objects to stencil context?

I created Codable struct Person. And I tried to add array of objects of this struct to stencil's context (See code down). But it doesn't work. How do it right? struct Person: Codable { public var name: String public var age: UInt8 …