Find by Protocol in Swift -
how can pass protocol parameter in swift?
in objective-c this:
id <currentusercontex> usercontex = [servicelocator locate:@protocol(currentusercontex)]; service locator:
+ (id)locate:(id)objecttype edit
after qbyte answer tried using:
servicelocator.locate(currentusercontex.self) but i'm getting 'currentusercontex.protocol' not confirm protocol 'anyobject'
so tried:
servicelocator.locate(currentusercontex.self as! anyobject) but get:
could not cast value of type 'applicationname.currentusercontex.protocol' (0x7fec15e52348) 'swift.anyobject' (0x7fec15d3d4f8).
i suggest use if currentusercontex name of protocol itself:
servicelocator.locate(currentusercontex.self) if currentusercontex variable type protocol use:
servicelocator.locate(currentusercontex) i hope solves problem
Comments
Post a Comment