Quote:
Originally Posted by alphaJA
Hello all,
First off, I am new to this forum, and I am excited to be a part of this community!
Although I have been programming for about 3 years(in an academic setting), I am new to the iPhone platform as well as the concept of working on my personal projects(All I've done so far in my life is school projects).
I have taken a Data Structures and an Algorithms course at my University, so I believe I have the very basics of programming down.
To get used to the iPhone platform, I am trying to make a Random Band Name Generator that fetches the words from websites.
For starters, I already made version 1, which generates a random name based on the 10 nouns and adjectives that I chose. I basically have two NSArrays(adjectiveArray and nounArray).
This one was fairly easy, and it's working fine.
So here's my question:
I want to fetch a random word from say dictionary.com. How do I go about doing that?
Thanks peop!
|
You need support from the server to do what you are asking for. It might be easier to get a list of words and store it locally. I have a link to a tutorial in my signature that generates random passwords using pairs of words from a public domain word list I found online. The word list I found contained over 100,000 English words.
In my app, I do a one-time conversion where I convert a text-based list of words to a plist, which is a Cocoa structured file that is easy to read into a Cocoa NSArray. I run that step once and then install the plist file into the app. The code that does the text file to plist file conversion is in the project. It might need to be modified somewhat depending on the format of the word list file you find. (The file I found used carriage return/linefeed to terminate each line, which is a Windows convention. Files for Mac/Unix use different line terminators)
After conversion, my 100,000+ word file is only about 1.9 megabytes long, which is fairly small by today's standards, and would be no problem to embed in an iOS app.
If you're determined to get a random word from an online dictionary, you would need an API from the server. It might be something as simple as sending a specially formatted URL - something like this:
PHP Code:
http://www.dictionaryserver.com/randomnoun.php
or
PHP Code:
http://www.dictionaryserver.com/randomadjective.php
That would trigger a PHP script on the server which would generate a random word of the requested type and return it.
You could then use the call stringWithContentsOfURL:encoding:error: to send that URL to the server and capture the results into a string object. However, you would need somebody to set up a server with your word list, and write the php scripts to do that.
It sounds like you need two separate lists: nouns and adjectives. You'd have to search around on the 'net for such lists, but I bet you could find them. My random password generator project contains a lot of the code you would need.