我一直在学习Swift编程语言并且遇到了障碍。我已经弄清楚如何通过使用NSString来检查一个单词是否真实,但是我想知道一旦单词被声明为真有一种方法来定义单词。这是声明它是否真实的代码。
func wordIsReal(word: String) -> Bool {
let checker = UITextChecker()
let range = NSMakeRange(0, word.characters.count)
let misspelledRange = checker.rangeOfMisspelledWordInString(word, range: range, startingAt: 0, wrap: false, language: "en")
return misspelledRange.location == NSNotFound
}
答案 0 :(得分:1)
您可以使用public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name', 'entity', array(
'class' => 'AppBundle\Entity\Type',
//'property' => 'name', is deprecated use 'choice_label' instead
'expanded' => true,
'choice_label' => 'name',
'choice_translation_domain' => 'entity',
));
}
检查单词是否有定义并显示该定义。
答案 1 :(得分:1)
谢谢你,你给了我找到这个词的解决方案。我试过了。
let word = "word
if UIReferenceLibraryViewController.dictionaryHasDefinitionForTerm(word)
{
let ref: UIReferenceLibraryViewController = UIReferenceLibraryViewController(term: word)
self.presentViewController(ref, animated: true, completion: nil)
}
使用TextChecker的另一种方法
func wordIsReal(word: String) -> Bool
{
let checker = UITextChecker()
let range = NSMakeRange(0, word.characters.count)
let misspelledRange = checker.rangeOfMisspelledWordInString(word, range: range, startingAt: 0, wrap: false, language: "en_US")
NSLog("misspelledRange:\(misspelledRange)")
NSLog("word:\(word)")
let arrGuessed:NSArray? = checker.guessesForWordRange(misspelledRange, inString: word, language: "en_US")as NSArray!
NSLog("arrGuessed:\(arrGuessed)")
return misspelledRange.location == NSNotFound
}
请参阅以下答案和解决方案