Code generator for Objective C
I have been using CodeSmith for .NET code generation from DB. Is there any similar code generation tool for SQLite DB which generates cod开发者_如何转开发e for objective-c?
This Objective-C based repository for SQLite has a simple bash script that will read an SQLite database and generate the appropriate ORM models for you. The URL is https://github.com/ziminji/objective-c-sql-query-builder
All you need to do is configure a small properties file that will tell the bash script where the SQLite database is on your hard-drive.
Yes. Core Data. It is built in, very fast, extremely well documented, and there are tons of examples of how to use it.
It, however, doesn't generate code. Code generation is generally awful; machine generated code is often overly verbose, poorly formatted, and difficult to debug. Worse, once you edit the code, you can't re-generate without risk of conflict (at best).
Core Data, like Interface Builder, take the approach that you should be able to model a bit of functionality in something that is archived during compilation and unarchived at runtime. Better yet, the modeling aspects of both IB and Core Data do nothing that can't be done in code, if you really wanted. That is, there is no magic.
If you are doing code-first or model-first style development, the Core Data is by far the best way to go on OS X/iOS. However, Core Data is not an ORM and so is not the right solution for working with a DB with an existing (non-Core Data) schema. If this is your situation, Objective-C's dynamic nature means that code generation is rarely necessary. Implementing an Active Record pattern is pretty straight forward. Take a look at this project for an example.
I agree with what Barry and bbum have said about Core Data. It's very useful. However, it's not a panacea. There may be times when you need to access a pre-existing SQLite database, and migrating it to Core Data would be total overkill. In these cases, you should use the Flying Meat Database wrapper, aka "FMDB". It's clean and easy to use.
精彩评论