Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.
Reading, displaying and quering data from file using objective-c
I am working on a story book app which contains multiple pages & multiple character dialogues per page. I have to dynamically display the character dialogues as dynamic speech bubbles. I am thinking of storing the narration text and character dialogue(s) text into a text or xml file in following format:
[Page1_NARRATION] text=This is the narration text for Page 1. audio=Audio/Page1_STORY_NARR.mp3
[Page1_Character1_Dialogue1] text=This is the Page1 Character1 Dialogue1. audio=Audio/Page1_Character1_Dialogue1.mp3
[Page1_Character1_Dialogue2] text=This is the Page1 Character1 Dialogue2. audio=Audio/Page1_Character1_Dialogue2.mp3
[Page1_Character2_Dialogue1] text=This is the Page1 Character2 Dialogue1. audio=Audio/Page1_Character2_Dialogue1.mp3
[Page2_NARRATION] text=This is the narration text for Page 2. audio=Audio/Page2_STORY_NARR.mp3
[Page2_Character1_Dialogue1] text=This is the Page2 Character1 Dialogue1. audio=Audio/Page2_Character1_Dialogue1.mp3
[Page2_Character1_Dialogue2] text=This is the Page2 Character1 Dialogue2. audio=Audio/Page2_Character1_Dialogue2.mp3
[Page2_Character2_Dialogue1] text=This is the Page2 Character2 Dialogue1. audio=Audio/Page2_Character2_Dialogue1.mp3
Now I would have to read this file and populate and display character dialogues on every page appropriately. What is the best approach to do so? Should I be storing these in Text file or XML file? I think reading the file every time I am displaying the dialogues would be too much, how can I read once and cache it and query some array/dictionary/something-else every time I have to display the text?
I am working on a story book app which contains multiple pages & multiple character dialogues per page. I have to dynamically display the character dialogues as dynamic speech bubbles. I am thinking of storing the narration text and character dialogue(s) text into a text or xml file in following format:
[Page1_NARRATION] text=This is the narration text for Page 1. audio=Audio/Page1_STORY_NARR.mp3
[Page1_Character1_Dialogue1] text=This is the Page1 Character1 Dialogue1. audio=Audio/Page1_Character1_Dialogue1.mp3
[Page1_Character1_Dialogue2] text=This is the Page1 Character1 Dialogue2. audio=Audio/Page1_Character1_Dialogue2.mp3
[Page1_Character2_Dialogue1] text=This is the Page1 Character2 Dialogue1. audio=Audio/Page1_Character2_Dialogue1.mp3
[Page2_NARRATION] text=This is the narration text for Page 2. audio=Audio/Page2_STORY_NARR.mp3
[Page2_Character1_Dialogue1] text=This is the Page2 Character1 Dialogue1. audio=Audio/Page2_Character1_Dialogue1.mp3
[Page2_Character1_Dialogue2] text=This is the Page2 Character1 Dialogue2. audio=Audio/Page2_Character1_Dialogue2.mp3
[Page2_Character2_Dialogue1] text=This is the Page2 Character2 Dialogue1. audio=Audio/Page2_Character2_Dialogue1.mp3
Now I would have to read this file and populate and display character dialogues on every page appropriately. What is the best approach to do so? Should I be storing these in Text file or XML file? I think reading the file every time I am displaying the dialogues would be too much, how can I read once and cache it and query some array/dictionary/something-else every time I have to display the text?
Most of the Cocoa file management routines deal with reading an entire file at once. If you are dealing with less than 20 megabytes of data or so, you might want to just read everything into memory and keep it there. I would only load text and the filenames of the audio, though, not the audio data.
A simple way to do this would be to create an array of NSDictionaries, and then save it to a property list. NSDictionary and NSArray both implement the method writeToFile:atomically: that creates a property list with their contents.
If you have more data than that, or more complex organization than that, you should look at using Core Data. Core data is a full-fledged object database with SQL as it's internal storage (actually, you can use several different formats for storing Core Data, but SQL is almost always the best choice).
You COULD roll your own system for storing records of data, but it would be a lot of work, without clear benefit. For that you'd either need to use NSFileHandle methods, or C file method life fseek()
Actually, I just looked in the Xcode docs, and fseek() only comes up in Mac OS. I'm not sure if Apple provides C-level file methods in iOS. I think so, but I'm not sure.
Regards,
Duncan C WareTo
Animated GIF created with Face Dancer, available for free in the app store.
Most of the Cocoa file management routines deal with reading an entire file at once. If you are dealing with less than 20 megabytes of data or so, you might want to just read everything into memory and keep it there. I would only load text and the filenames of the audio, though, not the audio data.
A simple way to do this would be to create an array of NSDictionaries, and then save it to a property list. NSDictionary and NSArray both implement the method writeToFile:atomically: that creates a property list with their contents.
If you have more data than that, or more complex organization than that, you should look at using Core Data. Core data is a full-fledged object database with SQL as it's internal storage (actually, you can use several different formats for storing Core Data, but SQL is almost always the best choice).
You COULD roll your own system for storing records of data, but it would be a lot of work, without clear benefit. For that you'd either need to use NSFileHandle methods, or C file method life fseek()
Actually, I just looked in the Xcode docs, and fseek() only comes up in Mac OS. I'm not sure if Apple provides C-level file methods in iOS. I think so, but I'm not sure.
Hi Duncan,
I have my dialogue data in following format inside an XML:
<?xml version=\"1.0\" encoding=\"UTF-8\"?> <Pages> <Page Id=\"P1\"> <T>Once upon a time in the deep jungle of sunderbun there lived a lazy and wicked Jackal.Once upon a time in the deep jungle of sunderbun there lived a lazy and wicked Jackal.</T> <A>This is audio file location.This is audio file location.This is audio file location.</A> <Dlg> <Dlg Id=\"C1D1\" P=\"L\" X=\"\" Y=\"\" W=\"\" H=\"\"> <T>This is Character 1 Dialogue 1.This is Character 1 Dialogue 1.</T> <A>This is audio file location.This is audio file location.</A> </Dlg> <Dlg Id=\"C1D2\" P=\"R\" X=\"\" Y=\"\" W=\"\" H=\"\"> <T>This is Character 1 Dialogue 2.This is Character 1 Dialogue 2.</T> <A>This is audio file location.This is audio file location.</A> </Dlg> <Dlg Id=\"C2D1\" P=\"L\" X=\"\" Y=\"\" W=\"\" H=\"\"> <T>This is Character 2 Dialogue 1.This is Character 2 Dialogue 1.</T> <A>This is audio file location.This is audio file location.</A> </Dlg> </Dlg> </Page> <Page Id=\"P2\"> <T>Once upon a time in the deep jungle of sunderbun there lived a lazy and wicked Jackal.Once upon a time in the deep jungle of sunderbun there lived a lazy and wicked Jackal.</T> <A>This is audio file location.This is audio file location.This is audio file location.</A> <Dlg> <Dlg Id=\"C1D1\" P=\"R\" X=\"\" Y=\"\" W=\"\" H=\"\"> <T>This is Character 1 Dialogue 1.This is Character 1 Dialogue 1.</T> <A>This is audio file location.This is audio file location.</A> </Dlg> <Dlg Id=\"C2D1\" P=\"L\" X=\"\" Y=\"\" W=\"\" H=\"\"> <T>This is Character 2 Dialogue 1.This is Character 2 Dialogue 1.</T> <A>This is audio file location.This is audio file location.</A> </Dlg> <Dlg Id=\"C2D2\" P=\"R\" X=\"\" Y=\"\" W=\"\" H=\"\"> <T>This is Character 2 Dialogue 2.This is Character 2 Dialogue 2.</T> <A>This is audio file location.This is audio file location.</A> </Dlg> </Dlg> </Page> </Pages>
As you can see from the XML structure, there would be multiple pages and every page would have multiple characters and each character would have multiple dialogues. Size of this XML might be around 250 KB (not sure if that's too big for iPhone/iPad).
Now, can I create an array of NSDictionaries, and then save it to a property list or use GDataXML to parse this XML?
I would need easy and quick access to dialogues by passing Page ID & Dialogue ID. I would appreciate your suggestions on the approach I should be taking.
Replies
A simple way to do this would be to create an array of NSDictionaries, and then save it to a property list. NSDictionary and NSArray both implement the method writeToFile:atomically: that creates a property list with their contents.
If you have more data than that, or more complex organization than that, you should look at using Core Data. Core data is a full-fledged object database with SQL as it's internal storage (actually, you can use several different formats for storing Core Data, but SQL is almost always the best choice).
You COULD roll your own system for storing records of data, but it would be a lot of work, without clear benefit. For that you'd either need to use NSFileHandle methods, or C file method life fseek()
Actually, I just looked in the Xcode docs, and fseek() only comes up in Mac OS. I'm not sure if Apple provides C-level file methods in iOS. I think so, but I'm not sure.
Duncan C
WareTo
Animated GIF created with Face Dancer, available for free in the app store.
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like AwesomeI have my dialogue data in following format inside an XML:
As you can see from the XML structure, there would be multiple pages and every page would have multiple characters and each character would have multiple dialogues. Size of this XML might be around 250 KB (not sure if that's too big for iPhone/iPad).
Now, can I create an array of NSDictionaries, and then save it to a property list or use GDataXML to parse this XML?
I would need easy and quick access to dialogues by passing Page ID & Dialogue ID. I would appreciate your suggestions on the approach I should be taking.
Thanks.
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like Awesome