i'm running interesting error message today:
cannot invoke 'map' argument list of type '(anyobject)'
i don't know there type in swift called (anyobject)!
the context is, i'm using closure callback after http request:
datahandler: ((anyobject) -> ())?,
and trying implement datahandler in piece of code:
datahandler: { (obj: anyobject) -> () in ...}
at moment, swift take "obj" type: (anyobject)...
thanks @sketchytech's inspiring answer, objectmapper seems need concrete type of "anyobject", cast array or dictionary. code works:
if let dic = res as? [string: anyobject], res = mapper<mappabletype>().map(dic) { ... }
when used concrete type, rather generic type, anyobject
enables call objc method (but of course must able respond method @ runtime avoid crashing).
when used concrete type, known
@objc
methods , properties available, implicitly-unwrapped-optional methods , properties respectively, on each instance ofanyobject
. (swift header file)
its primary role passing objects between objc , strongly-typed language of swift.
for instance of type anyobject
used higher order swift functions must first cast type can applied, e.g.
datahandler: {arr in if let = arr as? [int] { a.map{$0+1} }}
Comments
Post a Comment