This question already has answers here:
Comparing NSNumbers in Objective C
(5 answers)
Closed 9 years ago.
So, in my previous question (check out this > If-else: NSString) I've known how to check two strings. But now my task is compare two numbers.
isEqualToNumber isn't I need. For example: if the first number has a value 13, the second value has a value 20. How to compare these numbers?
Thank you everyone. Which method do I should use?
My code:
NSNumber *foo1 = #13;
NSNumber *foo2 = #14;
I need to compare them:
if ( foo1 < foo2) {
//some actions
}
if ([foo1 compare:foo2] == NSOrderedAscending) { ... some actions ... }
Related
This question already has answers here:
Perform .join on value in array of objects
(14 answers)
Closed 4 months ago.
skills = [
{skill_id: 1, skill_name: “IT”},
{skill_id: 2, skill_name: “cooking”}
]
Desired output:
IT, Cooking
I have tried to use merge() to merge the two objects. However, I cannot seem to get the desired output.
You can use map() to transform array values like
const values = skills.map(skill => skill.skill_name);
This question already has answers here:
How can I get a random number in Kotlin?
(24 answers)
Closed 1 year ago.
Hi how can you generate a random int between 0 and 10 in kotlin ? I tried Random().nextInt() and val rnds = (0..10).random() but i can't generate one. Thanks
To generate random number you can do as follow:
val randomNumber: Int = Random().nextInt(10) // here you can set your own bound value. This will give you random number from 0 to 10
This question already has an answer here:
How do I append a string/number to a string ?
(1 answer)
Closed 6 years ago.
I have label and I want to give it value of two elements that one of them NSInteger and the other string
_imgIndex.text = [#(index+1) stringValue]; //how to add string here?
It appears that you have an integer value (index) and a Obj-C string object (stringValue) and you want to concatenate them. There are lots of ways of doing this, here are two:
_imgIndex.text = [NSString stringWithFormat:#"%lu%#",index,stringValue];
The other technique would be to first convert the integer into a string, then concatenate the other string:
_imgIndex.text = [#(index).description stringByAppendingString:stringValue];
This question already has answers here:
How to add percent sign to NSString
(7 answers)
Closed 9 years ago.
Sorry I'm a bit new to objective c and I can't find out how to do something as simple as include a percent sign in a string. How is this accomplished in objective c?
Here's what I tried:
NSString *string = #"%";
brightnessLabel.text = [NSString stringWithFormat:[#"Brightness: %.0f" stringByAppendingString:string],slider.value];
but the percent doesn't show up. Thanks for the help.
You need to use "%%". So like this:
NSString *string = #"%%";
If you want a number with a percent after it:
brightnessLabel.text = [NSString stringWithFormat:#"Brightness: %.0f%%", slider.value];
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How do I concatenate strings in Objective-C?
Hello everyone I am new to Objc, I want to concatenate strings of the Integer value with string value.
Here is my code:
[runtime setText:[NSString stringWithFormat:#"%#",self.movie.runtime]];
The result will be: 120
The result that I wish to concatenate string is: 120 Minutes.
Please share me about this.
Thanks
I guess, you want this
[runtime setText:[NSString stringWithFormat:#"%# Minutes",self.movie.runtime]];
while concatenating would be:
NSString *newString = [aString stringByAppendingString:anotherString];
for immutable NSStrings
and
[aMuteableString appendString:anotherString];
for NSMutableStrings