Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is diffrence between integerValue and intValue in objective C

Tags:

objective-c

hi i am new to obj C and i am assigning a text field value to int variable PaidLeaves as below: because text field return string value i have to cat it to int value so i use following code: for example

PaidLeaves = txtPaidLeaves.text.intValue;

and

PaidLeaves = txtPaidLeaves.text.integerValue;

above i am assigning a text field value to int value

and both works but what is difference between two expression

please tell me thank you

like image 397
Devil Decoder Avatar asked Oct 20 '25 01:10

Devil Decoder


1 Answers

  • intValue returns an int number.
  • integerValue returns a NSInteger number.

The difference between them is their number of bits, or in easier terms, the range of values that they can store. Has said in an answer of a different question:

int is always 32-bits.

long long is always 64-bits.

NSInteger and long are always pointer-sized. That means they're 32-bits on 32-bit systems, and 64 bits on 64-bit systems.

Reference: https://stackoverflow.com/a/4445467/4370893

Consider that Apple has only made 64 bit systems since Mac OS X 10.7 (Lion), which was released in 2011, so I'm gonna refer to NSInteger has a 64 bit long integer.

So what that means?

The first bit of a signed integer number, like NSInteger and int, is used to define if it's a positive or a negative number. The conclusion is that a signed integer number goes from -2^(number of bits-1) to 2^(number of bits-1)-1, so...

  • int: - 2,147,483,648 (- 2^31) to 2,147,483,647 (2^31-1)
  • NSInteger: - 9,223,372,036,854,775,808 (- 2^63) to 9,223,372,036,854,775,807 (2^63-1)
like image 164
VitorMM Avatar answered Oct 22 '25 04:10

VitorMM



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!