objective c - Handling magic constants during 64-bit migration -


i confess did dumb , bites me. used magic number constant defined nsuintegermax define special case index. value used index access selected item in nsarray. in special case, denoted magic number value elsewhere, instead of array.

this index value serialized in user defaults nsnumber.

with xcode 5.1 ios app gets compiled standard architecture includes arm64. changed value of nsuintegermax, after deserialization 32-bit value of nsuintegermax, no longer matches in comparisons magic number, value 64-bit nsuintegermax. , results in nsrangeexception reason: -[__nsarrayi objectatindex:]: index 4294967295 beyond bounds [0 .. 10].

it minor issue in code, given normal range of array small, may away redefining magic number 4294967295. doesn't feel right. how should have handled issue properly? guess avoiding magic number altogether robust approach?

note

i think problem magic number equivalent happened nsnotfound constant. apple's 64-bit transition guide cocoa touch says in section common type-conversion problems in cocoa touch:

  • working constants defined in framework nsinteger. of particular note nsnotfound constant. in 64-bit runtime, value larger maximum range of int type, truncating value causes errors in app.

… not should done, except careful ;-)

if use nsinteger/nsuinteger it's 4b on 32bit os , 8b on 64 os.

if want use the same size integer both oss should consider use int (4) or long long (8) or int32_t/int64_t. max int int can use cast:

(int)int_max //or long_max 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -