I've been trying to use UITextChecker to see if a word inside a string is, in fact, actually a word. I've pieced the code together using examples I've found online, but I don't really understand it, and it's a bit above my level. Can anyone help me figure out how to check if a word in a string is really a word? I'm still learning all of this so thanks a ton!
-(IBAction)pushButton:(id)sender{
label.text = textField.text;
NSString * currentWord;
currentWord = label.text;
NSRange range = NSMakeRange(0, 0);
range = [textChecker rangeOfMisspelledWordInString:[currentWord lowercaseString]
range:NSMakeRange(0, [currentWord length])
startingAt:0
wrap:NO
language:@"en_US"];
if (range.location == NSNotFound) {
NSLog(@"Word found");
}
else {
NSLog(@"Word not found");
}
}
UPDATE: I'm still having trouble with this, as my log is showing "Word not found" no matter what I put in the textfield. I wanted to post my .h file as well to see if something is incorrect. Also here is a link to where I received the original code, in case that helps. Thanks again.
#import <UIKit/UIKit.h>
#import <UIKit/UITextChecker.h>
@interface CheckIfWordViewController : UIViewController {
IBOutlet UILabel * label;
IBOutlet UITextField * textField;
IBOutlet UIButton * button;
UITextChecker * textChecker;
}
@property (retain, nonatomic) UITextChecker * textChecker;
@property (retain, nonatomic) UIButton * button;
@property (retain, nonatomic) UILabel * label;
@property (retain, nonatomic) UITextField * textField;
-(IBAction)pushButton:(id)sender;
@end