objective c - Assigning NSNumber to NSString -


 nsstring *string = [nsnumber numberwithint:2];  int var = [string intvalue]; 

var 2. so, why? understand, it's smth dynamic typing, what's under hood?

there no casting going on in code example: [string intvalue] regular objective c method provided nsnumber retrieve value stored inside integer. fact assigned object nsstring pointer not change anything: object inside remains nsnumber. not crash because objective c dynamically typed language. lets assign objects of wrong types, if try calling methods of nsstring on string object, going crash:

nsstring *string = [nsnumber numberwithint:2]; int var = [string intvalue];                // ok bool istwo = [string isequaltostring:@"2"]; // crash 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -