Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reference to all Swift Protocols?

Swift has a notion of class interfaces, called Protocols. However I can't seem to find a full reference of all protocols available in the Swift API. Where can I find a list of all protocols?

like image 388
Bouke Avatar asked Jun 23 '14 19:06

Bouke


Video Answer


3 Answers

Well I haven't seen any documentation, but here's a trick I've been using (in XCode):

import Swift

…and then [CMD] - click on "Swift" which takes you to the headers for the Swift std lib.

You can see lots of protocols and what they require in there, including the ones seen in the docs (mentioned in the comments by esqew) which is helpful for understanding how to use the headers (at least some of the things in there have an explanation)

Edit:

I just remembered that I saw a list of "Special Protocols" in one of the WWDC videos, and took a screenshot :)

They are (as seen in the slide):

  • LogicValueif logicValue {
  • Printable"\(printable)"
  • Sequencefor x in sequence
  • IntegerLiteralConvertible65536
  • FloatLiteralConvertible1.0
  • StringLiteralConvertible"abc"
  • ArrayLiteralConvertible[ a, b, c ]
  • DictionaryLiteralConvertible[ a: x, b: y ]

The Literal Convertible ones mean you can assign to them with a literal a la:

class MyString: StringLiteralConvertible {
  …
}

var x: MyString = "asdf"

Interestingly not mentioned: Equatable, and Comparable (which are covered in the docs mentioned above)

like image 196
Jiaaro Avatar answered Sep 18 '22 14:09

Jiaaro


Where can I find a list of all protocols?

You're surely not interested in a list of all protocols, but rather the protocols defined in a given framework. So, maybe you want the UIKit protocols, or the iAd framework protocols, etc. You'll find them in the documentation for the framework.

If you're instead trying to find all the protocols in your project, use Xcode's symbol navigator (second icon from the left at the top left part of the project window, just right of file navigator icon).

like image 34
Caleb Avatar answered Sep 22 '22 14:09

Caleb


Maybe too late to answer but for others that are also wondering about it.

There is an autogenerated documentation website for Swift which includes docs about Types, Protocols, Operators, Globals and, Functions. Changing version is also possible for finding removed protocols etc.

https://swiftdoc.org/

like image 27
Garui Gardi Avatar answered Sep 21 '22 14:09

Garui Gardi