V
V
Vitaly2016-11-06 13:15:57
Objective-C
Vitaly, 2016-11-06 13:15:57

Why can't I set a new value for an int variable?

All the best!
I'm quite new to Objective-c and C languages ​​in general. Coding only in javascript. Ran into an int
problem . I have a property In the implementation code itself, I try to assign the length of the array to it: but x-code swears :( The following options also do not work:
@property (assign,nonatomic) int counter;
_counter = [_myArray count];

_counter = [NSNumber numberWithInteger:[_myArray count]];
_counter = [ intValue];

Tell me how to do it right

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
ManWithBear, 2016-11-06
@ManWithBear

How does he swear? Copy the error.
if
_counter = [[_myArray count] intValue];
then bad receiver type nsuinteger aka int
Because intValue is a method that the simple type nsuinteger does not have.
Treated in 2 ways
1. Knowing the type:
2. Do not use obsolete int, but use NSInteger, in your particular example NSUInteger
UPD. Personal opinion: if you are just starting, then start with swift. There is more information on it now and it is more relevant.

R
RedHairOnMyHead, 2016-11-06
@ThePyzhov

I'm quite new to Objective-c and C languages ​​in general. Coding only in javascript

Not from that you started, oh not from that ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question