iphone - Cocoa consistency -
if can write:
test_string = [[nsstring alloc] init]; , test_date = [[nsdate alloc] init];
why, if reasons of consistency, can't write:
test_integer = [[nsinteger alloc] init]; or test_decimal = [[nsdecimal alloc] init];
and how set them up?
your first 2 examples real objects, must instantiated alloc
/init
(or shorthand form, new
.
an nsinteger
typedef int
or long
, depending on platform, is, name either int
or long
. both so-called primitive types. they're not real objects, simpler. don't have methods, ivars, etc. - in fact, numbers, while object representing number (for example [nsnumber numberwithint:1]
) more.
primitive types used when speed , memory efficiency important, , integers used considerations important here. way, smalltalk (the language inspired objective-c's syntax , object model) did not have primitive types. integers, boolean values objects. more consistent (and more powerful in regards), 1 of factors made smalltalk quite slow in seventies , eighties.
nsdecimal
not object, struct. struct list of named primitive values. other often-used structs in objective-c might more obvious cgpoint
(a struct containing 2 floats, x , y), cgsize
(again struct containing 2 floats, time called width , height), cgrect
(a struct containing cgpoint
struct named origin, , cgsize
struct named size).
Comments
Post a Comment