Summing an array of numbers in Objective C -


basically. have array of numbers need sum. here code:

- (nsinteger ) sumofintegersinarray: (nsarray *)array {     nsinteger sum = 0;     (nsnumber *num in array) {         sum += [num intvalue];     }     return sum; } 

for reason doesn't work, if nslog sum, print 100 (which sum should be). why doesn't work?

the error keep getting is:

"incompatible integer pointer conversion return 'nsinteger (aka 'long') function result type 'nsinteger *' (aka 'long *'); take address &

(if let correct code return &sum, still doesn't work.

- (nsinteger*) sum {     nsinteger sum = 0;     for(nsnumber *num in array) {         sum += [num intvalue];     }     return sum; } 

i think work this.
have miss on return type

change this

- (nsinteger) sum {     nsinteger sum = 0;     for(nsnumber *num in array) {         sum += [num intvalue];     }     return sum; } 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -