Last active
December 7, 2018 17:22
-
-
Save chungbkhn/11708a4b6d82158593aebd376cb721ee to your computer and use it in GitHub Desktop.
Nested protocol in swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
// Declare protocol | |
protocol EXModelExampleProtocol {} | |
// Namespace Model | |
enum Model {} | |
// Make alias for your protocol | |
extension Model { | |
typealias ExampleProtocol = EXModelExampleProtocol | |
} | |
// Use nested protocol | |
struct AwesomeObject: Model.ExampleProtocol {} | |
struct AnotherObject { | |
let injectedInstance: Model.ExampleProtocol | |
} | |
// Use nested protocol inside namespace | |
extension Model { | |
struct Awesome: ExampleProtocol {} | |
} | |
// Declare protocol 2 | |
protocol EXAPIExampleProtocol {} | |
// Namespace API | |
enum API {} | |
// Make alias for your protocol 2 | |
extension API { | |
typealias ExampleProtocol = EXAPIExampleProtocol | |
} | |
// Just use it with namespace | |
struct OtherObject: API.ExampleProtocol {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment