Invalid Operands to binary expression (NSNumber* __strong and NSNumber*) [closed] - objective-c

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
nsnumber *totaldur=0;
totalDur+=(NSNumber*)[dict valueForKey:#"tracktime"];

You can't perform addition on NSnumber for this
NSNumber * totaldur =[NSNumber numberWithInteger:20];
totaldur = [NSNumber numberWithInteger:([number1 integerValue] + [[dict valueForKey:#"tracktime"] integerValue])];
//// first of all convert both numbers to same data type like (nsinteger,int,float) and then apply addition on them and in the end save sum in nsnumber object
Hope it helps

Related

Can the ternary operator be used outside of assignment statements in Objective-C? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I know setting a variable conditionally is valid:
someProperty = [anObject aFunctionThatReturnsBool]? #"Yes" : #"No";
This question has an answer that details the use of ternary statements in preprocessor macros
#define statusString (statusBool ? #"Approved" : #"Rejected")
and within a string formatting method
[NSString stringWithFormat: #"Status: %#", (statusBool ? #"Approved" : #"Rejected")]
But what about within any method?
[NSNumber numberWithInt:(aVariableThatCouldBeSet)? 100 : 0)];
And conditional method calling?
[anObject aFunctionThatReturnsBool]? [self doThis] : [self doThat];
Bonus points for any other uses not listed.

NSString hasSuffix with wildcard, for example checking a year ends in 19xx or 20xx? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I want to check if an NSString ends with 19xx or 20xx, with the x's being any valid numbers.
How can I do this?
Sounds like a predicate with a regular expression fits your bill:
NSString *str = #"2013";
NSPredicate *yearPredicate = [NSPredicate predicateWithFormat: #"SELF MATCHES '(19|20)[0-9]{2}'"];
BOOL matched = [yearPredicate evaluateWithObject: str];

Put in string int and text [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I want to put in string int and text.
I have this code: chipsS = [NSString stringWithFormat:#"%i", chips];
What to do?
stringVariable = [NSString stringWithFormat:#"%i - %#", intVariable, stringVariable];

How do I turn an int into a float? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
int *SliderMaximum = V1.TeamAmountAfterSave;
[sliderTeamSelect setmaximum:SliderMaximum];
I need to convert SliderMaximum to a float how do I do this?
NSNumber *yourNumber = [NSNumber numberWithInt: SliderMaximum];
float yourFloat = [yourNumber floatValue];
and you don't need a pointer to int, it's useless, computationally allocate a pointer and write inside address pointer to int is same as allocate a int and write int in it.
Have you tried multiplying it by a float?
CGFloat sliderMaximum = SliderMaximum * 1.0f;
[sliderTeamSelect setmaximum:[[V1.TeamAmountAfterSave] floatValue]];

NSMutableArray sort cell [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have in tableView NSMutableArray "days" which contain 6 NSMutableArray (monday, tuesday...saturday)
Before I doing sort,this method is work
tuesday = [NSMutableArray arrayWithArray:[tuesday sortedArrayUsingComparator:^(id cont1, id cont2) { return [[(Lesson *) cont1 time1] compare:[(Lesson *) cont2 time1]]; }]];
but now I must doing [days objectAtIndex:0]=.... but how I do this if this expression is unacceptable
You can not assign an object to a NSMutableArray with the equal sign, use the following:
[days addObject:theObjectYouWantToAdd];
EDIT:
In case you would like to add the new object to a particular position on the original mutable array (say position 0), you have to remove the old one by:
[days removeObjectAtIndex:0];
Ant then insert the new one by:
[days insertObject:theObjectYouWantToInsert atIndex:0];