简体   繁体   English

我应该如何与iPhone应用程序中的单词基础进行交互?

[英]How should i interact with a base of words in iPhone app?

I'm making a word game for iPhone. 我正在为iPhone做文字游戏。 User can construct words from separate letters. 用户可以从单独的字母构造单词。 And i need to check is this a real word, which user made, or some kind of pointless stuff like "sfugh". 我需要检查的是这是用户创建的真实单词,还是诸如“ sfugh”之类的毫无意义的东西。 How i should better implement this? 我应该如何更好地实现这一点? Should i have kind dictionary in program(I think it's a bad idea, because with a large amount of words it would work very slow) or maybe there is kind of online dictionaries, where i can check the word from my code, or should i make a trie? 我应该在程序中使用友好的字典吗(我认为这是一个坏主意,因为使用大量单词会导致非常慢的工作),或者可能存在某种在线词典,可以在我的代码中检查单词,还是应该试一试? Or maybe where is other solutions? 也许其他解决方案在哪里?

Use a pre-populated sqlite database. 使用预先填充的sqlite数据库。 That way, you can use string indexes to make the searches in the db faster. 这样,您可以使用字符串索引来加快数据库中的搜索速度。

You can use Apple's native UITextChecker to determine whether or not a word is misspelled/valid. 您可以使用Apple的本机UITextChecker来确定单词是否拼写错误/有效。 Here's a sample project on GitHub . 这是GitHub上的示例项目 This way, you don't have to worry about assembling your own database full of words. 这样,您就不必担心组装充满单词的数据库。

For easy digestion, here's the code that does all the work 为了易于消化,下面是完成所有工作的代码

- (IBAction)textFieldTextDidChange:(id)sender {
    NSRange rangeOfMisspelling = [self.textChecker rangeOfMisspelledWordInString:self.textField.text
                                                                           range:NSMakeRange(0, self.textField.text.length)
                                                                      startingAt:0
                                                                            wrap:NO
                                                                        language:@"en_US"];
    // no misspellings
    if (rangeOfMisspelling.location == NSNotFound) {
        self.textLabel.text = @"Valid word!";
    }

    // misspellings
    else {
        self.textLabel.text = @"Not a word.";
    }
}

One thing to note is UITextChecker seems to count individual letters as valid words. 需要注意的一件事是UITextChecker似乎将单个字母视为有效单词。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iPhone应用程序如何与CouchDB交互? - How does an iPhone app interact with CouchDB? 我应该为 iOS 应用准备多大的基本图像大小? - How base image size should I prepare for iOS app? 如何在iPhone应用程序中管理和引用许多图像文件? - How should I manage and reference many images files in an iPhone app? 我应该如何在tabbar iPhone应用程序中管理我的NSTimer? - How should I manage my NSTimer in a tabbar iPhone app? 我应该如何使用JSON作为媒介来构建应用程序以将数据从服务器发送到iPhone? - How should I archecture app to send data from server to iPhone using JSON as medium? 如何在不触摸的情况下与iPhone浏览器进行交互? - How to interact with iPhone browser without touching it? 我应该使用哪个SDK版本的iPhone应用程序? 4.2还是3? - What sdk version of iPhone app should I use? 4.2 or 3.? 我应该在哪里存储我的iPhone应用程序的SQLite数据库? - Where should I store the SQLite DB for my iPhone app? 我应该在这个简单的iPhone应用程序中使用哪种类型的ViewController - What type of ViewController should I use in this simple iPhone app 用于iPhone应用程序开发的Storyboard或XIB,我应该选择哪一个? - Storyboard or XIB for iphone app development, which one should I pick?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM