Advertisement
Guest User

Untitled

a guest
Feb 28th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. public protocol P {
  2. var foo: Int { get }
  3. }
  4.  
  5. internal protocol Q {
  6. init(from: [String])
  7. }
  8.  
  9. public struct S: P, Q {
  10. public var foo: Int = 0
  11. public init() {}
  12.  
  13. internal init(from: [String]) {
  14. precondition(from.count > 0)
  15. self.foo = Int(from[0])!
  16. }
  17. }
  18.  
  19. public class ProviderOfThings {
  20. public func map<T: P>(before: T) -> T {
  21. return T(from: [String(before.foo + 1)])
  22. }
  23. }
  24.  
  25. public static func map<T: P>(before: T) -> T {
  26. return type(of: before as! Q).init(
  27. from: [String(before.foo + 1)]
  28. ) as! T
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement