简体   繁体   中英

How to import all English words to a set in Swift/Xcode?

I'm just learning and working through the Apple Xcode/Swift guide, and am currently working on the "Apple Pie" project (in case anyone is familiar). If you're not, it's a "hangman" style game, where you guess the letters in a word each round, and have a total number of guesses before you lose. The guide asks you to add your own list of words to an array, but that feels tedious and boring. I know this is just a guide to help me learn, but I think it'd be a lot more fun to pull a random word from a set of "all" English words (at least several thousand) to guess from.

How would I go about importing a set of words like this, to where I don't have to type them all hard coded? I found references to an "npm" that seems to contain what I'm looking for, but have no idea what an npm is or how to add it to my program as a searchable set.

The best thing you can do is to pull a request to a web were many english words are stored, for example: http://www.mieliestronk.com/corncob_caps.txt , create a file inside your app with all that words and then create an array in code where you can choose randomly from.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM