使用 Stencil 删除字符串中的子字符串
Remove substring in a string with Stencil
我正在尝试使用 Sourcery 来扩展一些库。我几乎成功了,但在某些时候我有一个类型,returned 来自 func,它是一个可选的。我想让它成为非可选的。为此,我必须了解如何删除问号,但在我看来语言不支持它。如果它能以某种方式提供帮助,我的脚本如下:
{% 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 %}
在这个地方 {{ method.returnTypeName }}
我有所有 return 类型可选。我想删除问号。可能吗?
使用 .unwrappedTypeName
解决了我想删除 ?
的问题
我正在尝试使用 Sourcery 来扩展一些库。我几乎成功了,但在某些时候我有一个类型,returned 来自 func,它是一个可选的。我想让它成为非可选的。为此,我必须了解如何删除问号,但在我看来语言不支持它。如果它能以某种方式提供帮助,我的脚本如下:
{% 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 %}
在这个地方 {{ method.returnTypeName }}
我有所有 return 类型可选。我想删除问号。可能吗?
使用 .unwrappedTypeName
解决了我想删除 ?