1

This is a real example, I was looking to extend an array of a certain type in Swift. I searched Dash, online docs and the iBooks guide to no avail. I finally found this SO answer and tried a more refined search, yet still did not find anything.

Even going right the way down to the raw spec, there is no where clause:

extension type-identifier type-inheritance-clause {}

type-inheritance-clause -> : class-requirement

class-requirement -> class

Which I read as:

extension Array: Person {} // doesn't compile

but, this is valid (and what I needed):

extension Array where Element: Person {}
  • where is the correct documentation?
  • what should I have searched for?
Mogsdad
  • 44,709
  • 21
  • 151
  • 275
  • 1
    Although I agree that the documentation can be verbose and hard to read through sometimes, it does say "type inheritance clause" and that's exactly what you added to get it to compile. – pbush25 Nov 17 '15 at 17:46
  • 1
    blogpost about all the uses of `where` : [link](http://blog.krzyzanowskim.com/2015/11/13/where-where-may-be-used/?utm_campaign=This%2BWeek%2Bin%2BSwift&utm_medium=web&utm_source=This_Week_in_Swift_62) – R Menke Nov 17 '15 at 17:54
  • @RMenke Some of those are out of date, unfortunately; a bunch of the flow control-related ones now just use a comma rather than `where`. – Charles Srstka Mar 05 '18 at 01:57
  • Six years have passed and Apple still doesn't provide a good way to search Swift docs. They finally started accepting public feature requests on GitHub, so I added one: https://github.com/apple/swift-org-website/issues/24 – M. Leonhard Apr 09 '22 at 01:50

1 Answers1

0

You're currently looking at the framework references that covers things like stdlib and Foundation. This is a syntax-level issue, so you need to look at The Swift Programming Language. The specific section you're looking for is Extensions with a Generic Where Clause.

I'm not certain which spec you're looking at. It may be out of date, but if you look at the language reference, the current definition of extension includes the 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­
Rob Napier
  • 286,113
  • 34
  • 456
  • 610