ios - Objective-C Conversion Errors -
i have project working on. project uses afnetworking 2.0 youtube gdata channel , load uitableview. there tutorial saw jared davidson showed me how so. great problem was in objective - c , project in swift. trying convert code swift have stumbled upon problem.
i tried converting this,
self.post = self.posts[@"data"][@"items"];   to in swift,
self.post = self.posts["data"]["items"] nsmutabledictionary   but error says...
'anyobject?' not have member named 'subscript'
i have tried numerous ways fix still don't know how it. appreciated
thanks !
accessing dictionary returns optional since key may not exist.. how compiler parses it:
call
posts. returnsnsdictionary.call
subscripton returned object, argument of "data." returns optionalanyobject.call
subscripton returnedanyobject?, argument of 'data'. causes error, because need unwrap it.
you need change to:
self.post = self.posts["data"]!["items"] nsmutabledictionary   now happens:
call
posts. returnsnsdictionary.call
subscripton returned object, argument of "data." returns optionalanyobject.unwrap optional. returns
anyobject(not optional).call
subscripton returnedanyobject, argument of 'data'.cast
nsmutabledictionary. believe cast unwraps it.call
setpostresult.
Comments
Post a Comment