Last active
February 15, 2018 13:00
-
-
Save SteeweGriffin/568ef9fb29d4d8ad66a3644e09d77962 to your computer and use it in GitHub Desktop.
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 UIKit | |
protocol Printable { | |
func printMe() | |
} | |
class PFObject:Printable {} | |
class PFDictionary:Printable { | |
var data:[String:Any] = [:] | |
} | |
extension Printable where Self: PFObject { | |
func printMe() { | |
print(self) | |
} | |
} | |
extension Printable where Self: PFDictionary { | |
func printMe() { | |
print(data["autore"]) | |
} | |
} | |
func myGenericFunc<T:Printable>(objs: [T]) { | |
objs.forEach { (object) in | |
object.printMe() | |
} | |
} | |
let pfObject = PFObject() | |
let pfDictionary = PFDictionary() | |
pfDictionary.data["autore"] = "Pippo Baudo" | |
let objsA: [PFObject] = [pfObject] | |
let objsB: [PFDictionary] = [pfDictionary] | |
myGenericFunc(objs: objsA) | |
myGenericFunc(objs: objsB) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment