objective c - Why is AnyObject[] bridged from NSArray in Obj-C Class Empty in "success" closure in Swift? -
objective c - Why is AnyObject[] bridged from NSArray in Obj-C Class Empty in "success" closure in Swift? -
i have class method in obj-c class:
+ (void) tagsfetchforid:(nsnumber *) tid successful:(void (^)(nsarray *tags)) successful failure:(void (^)()) failure;
this worked fine pre-swift, function named successful()
in implementation of above metho beingness used pass resulting array handling block in used obj-c class, did necessary info in array (it's async http situation several levels down, part still obj-c , still working).
the method bridges swift in manner code completion gives me this:
potsshareddata.tagsfetchforid(<tid: nsnumber?>, successful: <((anyobject[]!) -> void)?>, failure: <(() -> void)?>)
...which i've turned this:
potsshareddata.tagsfetchforid(transactionid, successful: { (fetchedtags: anyobject[]!) -> void in }, failure: { })
i'm not getting fetchedtags, despite fact when break on obj-c side, array beingness passed successful()
function much populated:
(lldb) po tagarray <__nscfarray 0x10d024060>( { tag = "tag multiple words"; tagid = 2728; }, { tag = singlewordtag; tagid = 2729; } )
it's array of dictionaries each nsstring tag , nsnumber tagid, nsstring keys.
in swift, literally nothing:
(lldb) po fetchedtags { value = none } (lldb)
i don't know begin one. far swift's single type collections rulea go, i'd expect array fine perhaps dictionaries problem there 2 types (nsstring , nsnumber) both of have specific bridging behaviours.
i'd understand why happening, might around it, bearing in mind i'm trying attack swift 1 class @ time, , won't ready migrate particular obj-c class until pretty much last.
edit: when simplified array of strings, result same. total implementation of obj-c method:
+ (void) tagsfetchforid:(nsnumber *) tid successful:(void (^)(nsarray *tags)) successful failure:(void (^)()) failure { nsarray *ar = @[@"one",@"two",@"three"]; successful(ar); }
i'm still receiving empty optional/nil within successful closure in swift class when invoking method. i've tried array of objects of 1 of own nsobject subclasses avoid bridging attempts, result still same.
because of generics weren't in objective-c. because of generics in swift when declare array of strings array can hold strings. seek place int in , compiler warn you. in objective-c set within of array (or dictionary) , smart collection contained. swift allows behavior anyobject type , that's why calls bridged way.
objective-c closures swift objective-c-blocks
Comments
Post a Comment