Skip to content

Instantly share code, notes, and snippets.

@eugeniobaglieri
Created February 15, 2018 09:59
Show Gist options
  • Save eugeniobaglieri/47dec1a20679cf4b197597de5558dcc5 to your computer and use it in GitHub Desktop.
Save eugeniobaglieri/47dec1a20679cf4b197597de5558dcc5 to your computer and use it in GitHub Desktop.
// Write some awesome Swift code, or import libraries like "Foundation",
// "Dispatch", or "Glibc"
class PFObject: Any {
}
let objsA: [PFObject] = []
let objsB: [[String: Any]] = [[:]]
private func myGenericFunc<T>(objs: [T], of type: T.Type) {
switch type {
case let x where x is PFObject.Type:
print("PFObject")
case let x where x is [String: Any].Type:
print("[String: Any]")
default:
print("Boh")
}
}
public func myGenericFunc<T>(objs: [T]) {
return myGenericFunc(objs: objs, of: T.self)
}
myGenericFunc(objs: objsA)
myGenericFunc(objs: objsB)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment