Remove substring in a string with Stencil

362 views Asked by At

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 mark, but it seems to me language doesn't support it. My script is below if it can help somehow:

{% for type in types.structs %}
    {% if type.name == "_R" %}
        {% for innerType in type.containedTypes %}
            {% if innerType.name == "_R.nib" %}
                {% for nib in innerType.containedTypes %}
extension {{ nib.name }} {
                    {% for method in nib.methods %}
                        {% if method.selectorName == "firstView(owner:options:)" %}
    func firstView(owner ownerOrNil: AnyObject?, options optionsOrNil: [NSObject : AnyObject]? = nil) ->
    {{ method.returnTypeName }}
    {
        return instantiate(withOwner: ownerOrNil, options: optionsOrNil)[0] as? {{ method.returnTypeName }}
    }
                        {% endif %}
                    {% endfor %}
}

                {% endfor %}
            {% endif %}
        {% endfor %}
    {% endif %}
{% endfor %}

At this place {{ method.returnTypeName }} I have all the return types optional. I want to remove question mark. Is it possible?

1

There are 1 answers

0
Vladyslav Zavalykhatko On BEST ANSWER

Solved the issue using .unwrappedTypeName where I want to remove ?