Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
-(IBAction)button:(id)sender{
If (cardsinplay >= 16){
NSNumber *cardValue = carsAndValue[14];
NSInteger *Value = [cardValue integerValue[;
From what i know this should read the NSNumber from the array and change it into a NSInteger
But i get this error.
Incompatible integer to pointer conversion initialization 'NSInteger*'(aka 'int*') with an expression of type 'NSInteger'(aka 'int*')
-[NSNumber integerValue] returns a NSInteger, not a pointer to one.
NSInteger *Value = [cardValue integerValue];
should be
NSInteger value = [cardValue integerValue];
Related
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
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
I am currently trying to make a simple craps app for the iPhone.
In the model I have a method:
-(NSString *)resultsOfRoll:(int)firstRoll :(int)secondRoll
{
NSString *results = #"";
NSArray *naturalNumbers = #[#7,#11];
NSArray *losingNumbers = #[#2, #3, #12];
NSArray *pointNumbers = #[#4,#5,#6,#8,#9,#10,#11];
int sum = firstRoll + secondRoll;
if(sum in naturalNumbers)
{
return #"You rolled a natural! You won";
}
return results
}
But I am getting an error. I am pretty new to Obj C and I haven't used much enumeration(If that is wrong please correct me) yet. Could someone let me know if I am initializing the loop correctly and how I can check to see if the sum (roll + roll) is in an array?
Also, does my method name look correct? I am coming from Java and these method sigs are still a little confusing for me.
if(sum in naturalNumbers) obviously isn't valid syntax. You're using something like 'for in' and with an int instead of an object.
What you want is:
if ([naturalNumbers containsObject:#(sum)]) {
Which asks the array if it contains an NSNumber instance containing the sum.
Your method doesn't name the second parameter, which is legal but not encouraged. It would be better as:
-(NSString *)resultsOfRoll:(int)firstRoll secondRoll:(int)secondRoll
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am having an NSString object as "HAI HELLO ABC".I want it to "HAIHELLOABC".Is there any function present?
[str stringByReplacingOccurrencesOfString:#" " withString:#""];
NSString * newString = [string stringByReplacingOccurrencesOfString:#" " withString:#""];
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am teaching myself Objective - C and I tried out some code to do a math equation. Can you please tell me what I am doing wrong?
- (IBAction)mathEquation:(id)sender {
int a = 6;
int b = 2;
self.showAnswer.text = int a + int b;
}
Can someone please rewrite to code the correct way and post it? Thank you!
int result = a + b;
self.showAnswer.text = [NSString stringWithFormat:#"%d", result];
In Objective-C, you can't just assign a number to a string, it won't work. As you see in my code, you need to convert from a numerical value into a string. The method [NSString stringWithFormat:] lets you do that, and what kind of number(s) you want to include in the string. E.g. the format expression %d is for an integer value.
Also, once you declared your variables (int a, etc.), you don't need to declare them again, you'll get an error.
I would strongly advice reading up on the basic syntax of 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
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]];