I'm writing a database project on the iPhone and I'd like to store some big SQL queries in a separate, project-included file.
Then, I'd like to read this query into an NSString * (or, well, const char * is also ok) reference, and then perform it with an sqlite3.
I'm a newbie to iPhone developing, and I have never worked with files, neither I know any de开发者_运维技巧tails of their storage.
Could you please give me a hint on:
- The appropriate file format to store the strings.
- How do I store it into the iPhone;
- How do I read from it.
Thanks a lot!
You can use:
- Any simple character based (text) file would be more than enough
- Just put it in a folder in your project, it will get deployed with your Application
- Use
NSString
class.
For issue #3 you can use:
NSString *sqlString =
[NSString
stringWithContentsOfFile:@"yourqueryfile.sql"
encoding:NSUTF8StringEncoding
errors:nil //unless yuo are interested in errors.
];
精彩评论