简体   繁体   中英

what is diffrence between integerValue and intValue in 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

  • 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM