This repository was archived by the owner on Sep 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathStoryboardSegueIdentifierProtocol.swift
96 lines (74 loc) · 2.56 KB
/
StoryboardSegueIdentifierProtocol.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//
// StoryboardSegueIdentifierProtocol.swift
// R.swift Library
//
// Created by Mathijs Kadijk on 06-12-15.
// From: https://github.com/mac-cain13/R.swift.Library
// License: MIT License
//
import Foundation
/// Segue identifier protocol
public protocol StoryboardSegueIdentifierType: IdentifierType {
/// Type of the segue itself
associatedtype SegueType
/// Type of the source view controller
associatedtype SourceType
/// Type of the destination view controller
associatedtype DestinationType
}
/// Segue identifier
public struct StoryboardSegueIdentifier<Segue, Source, Destination>: StoryboardSegueIdentifierType {
/// Type of the segue itself
public typealias SegueType = Segue
/// Type of the source view controller
public typealias SourceType = Source
/// Type of the destination view controller
public typealias DestinationType = Destination
/// Identifier string of this segue
public let identifier: String
/**
Create a new identifier based on the identifier string
- returns: A new StoryboardSegueIdentifier
*/
public init(identifier: String) {
self.identifier = identifier
}
/// Create a new StoryboardSegue based on the identifier and source view controller
public func storyboardSegue(withSource source: Source)
-> StoryboardSegue<Segue, Source, Destination>
{
return StoryboardSegue(identifier: self, source: source)
}
}
/// Typed segue information
public struct TypedStoryboardSegueInfo<Segue, Source, Destination>: StoryboardSegueIdentifierType {
/// Type of the segue itself
public typealias SegueType = Segue
/// Type of the source view controller
public typealias SourceType = Source
/// Type of the destination view controller
public typealias DestinationType = Destination
/// Segue destination view controller
public let destination: Destination
/// Segue identifier
public let identifier: String
/// The original segue
public let segue: Segue
/// Segue source view controller
public let source: Source
}
/// Segue with identifier and source view controller
public struct StoryboardSegue<Segue, Source, Destination> {
/// Identifier of this segue
public let identifier: StoryboardSegueIdentifier<Segue, Source, Destination>
/// Segue source view controller
public let source: Source
/**
Create a new segue based on the identifier and source view controller
- returns: A new StoryboardSegue
*/
public init(identifier: StoryboardSegueIdentifier<Segue, Source, Destination>, source: Source) {
self.identifier = identifier
self.source = source
}
}