[英]How to properly search and use Apple's developer documentation for Swift?
这是一个真实的例子,我想在Swift中扩展某种类型的数组。 我搜索了Dash,在线文档和iBooks指南,但都无济于事。 我终于找到了这样的答案,并尝试了更精细的搜索,但仍然没有找到任何东西。
即使一直到原始规格,也没有where子句:
扩展类型标识符类型继承子句{}
类型继承子句->:类要求
类要求->类
我读为:
extension Array: Person {} // doesn't compile
但是,这是有效的(以及我所需要的):
extension Array where Element: Person {}
您目前正在查看涵盖stdlib和Foundation之类的框架参考。 这是一个语法级别的问题,因此您需要查看The Swift Programming Language 。 您要查找的特定部分是具有通用Where子句的扩展 。
我不确定您要查看哪个规格。 它可能已经过时,但是如果您查看语言参考, 当前extension
定义包括generic-where-clause
:
extension type-identifier type-inheritance-clause(opt) generic-where-clause(opt) extension-body
extension-body → {extension-members(opt)}
extension-members → extension-member extension-members(opt)
extension-member → declaration compiler-control-statement
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.