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 am trying to put a number from a textfield on a Parse database and I need to specify that it is a number. How can I do this?
I have done the equivalent with a string using .text
Your question is unclear but I think you mean something like this:
UITextField *textField = ... // some text field
int age = [textField.text intValue];
user[#"age"] = #(age);
You need to convert the string value from the UITextField to a number, (e.g. int, double, or NSNumber).
NSString *textInput = myTextField.text;
int intValue = [textInput intValue];
NSNumber *age = [NSNumber numberWithInt:intValue];
user[#"age"] = age;
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 4 years ago.
Improve this question
I am new to swift programming.I am working in an app of emoji.When i click an emoji from Apple keyboard it show the unicode of that emoji.How can i get this.
Here is list of uicodes
https://apps.timwhitlock.info/emoji/tables/unicode
you can also use Edit->Emoji and drag the to the text
let str = "Ti😁 \u{1F601} tle"
use Swift Unicode escape sequence concept:
let emojiString = "\u{1F4C4}"
and if you want to get all emoji's Unicode then try this
let emojiRanges = [
0x1F601...0x1F64F,
0x2702...0x27B0,
0x1F680...0x1F6C0,
0x1F170...0x1F251
]
for range in emojiRanges {
for i in range {
var c = String(UnicodeScalar(i))
print(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 5 years ago.
Improve this question
How to use objc_setAssociatedObject to associate with the object?
OBJC_EXPORT void objc_setAssociatedObject(id object, const void *key, id value, objc_AssociationPolicy policy)
The value must be an Objective-C object. You need to wrap the struct in an Objective-C class. You could use NSValue for this.
StructType s = ...;
NSValue* value = [NSValue valueWithBytes:&s objCType:#encode(StructType)];
objc_setAssociatedObject(obj, SPECIAL_KEY, value, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
...
NSValue* value = objc_getAssociatedObject(obj, SPECIAL_KEY);
StructType s;
[value getValue:&s];
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 6 years ago.
Improve this question
I want the new number to get a new line without removing the old number ?
See the picture
Try
if let exitingText = label.text
{
label.text = exitingText + "\n" + (textField.text ?? "")
}
and set
label.numberOflines = 0
Here is the code you can use on click of button
- (IBAction)btnAppendTextClicked:(id)sender
{
NSString *oldText=_lblWithText.text;
_lblWithText.text=[NSString stringWithFormat:#"%#\n%#",oldText,_txtValues.text];
_lblWithText.numberOfLines=0;
_lblWithText.preferredMaxLayoutWidth =self.view.frame.size.width;
[_lblWithText setNeedsDisplay];
}
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 have a string *strSearchNumber = #"9970405060" and want to check whether it is present in string *strPhoneMobile = #"+91997040560"
How can I check if last 6 or 8 characters of my string are present in some other string. Thanks in advance.
Simply use -[NSString hasSuffix:].
Use the NSString method hasSuffix:
NSString *strSearchNumber = #"9970405060";
NSString *strPhoneMobile = #"+91997040560";
if ([strPhoneMobile hasSuffix: strSearchNumber]) {
// do something
}
How do I check if a string contains another string in Objective-C?
Better then just checking the end or front of the string. You should check if the string contains the other bit of string. The link above will give you the answer.
Underneath the short version of the answer.
NSString *string = #"hello bla bla";
if ([string rangeOfString:#"bla"].location == NSNotFound) {
NSLog(#"string does not contain bla");
} else {
NSLog(#"string contains bla!");
}
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 have created an a nsstring idd variable in .h. and synthesized in .m. Now i have an int variable b and want to store the value of idd in b. Now when i convert idd to int. it not working the b always give me the 0 value.
.h
#property(retain, nonatomic) IBOutlet NSString *idd;
.m
int b=[idd intValue];
NSLog(#"the value of b=%d",b);
IBOutlets and IBActions are macros that mark variables and methods that can be referred to by Interface Builder to link UI elements to your code. They're typically linked to subclasses of NSResponder (like NSButton, NSView, etc.); not NSString's. Unless idd is bound to something in a NIB it won't have any value other than the default (zero). If idd is bound to a GUI object (control) then what you probably want is that controls value (in which case your code is correct).
idd probably doesn't have a value, or has a value that can't be parsed into an integer. Try NSLoging idd to see what it contains.
do
idd = #"2";
int b = [idd intValue];
NSLog(#"b = %i", b);
and that should display 2 as b
You need
int b=[self.idd intValue];