Skip to content

This is notes I have taken on using protocols in Swift.

Notifications You must be signed in to change notification settings

JohnWYWallace/Protocols

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

Protocols

Protocols remind me of extensions in the Java programming language. They can be thought of as a certificate. To define a protocol it is similar to how you would define a structure, class and enumeration. A protocol can be used to define certain methods, properties, or other requirement that suits a particular task or piece of functionality.

Defining a protocol:

  • protocol MyProtocol { // Define requirements }

Adopting the protocol:

  • struct MyStruct: MyProtocol { }
  • class MyClass: MyProtocol { }

In the example below it has a superclass, and you must list the super class name before any protocols it adopts.

  • class MyClass: Superclass, FirstProtocol, AnotherProtocol { // class definition goes here }

About

This is notes I have taken on using protocols in Swift.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published