![]() WRONG! The isAdmin attribute is an NSNumber, so this will evaluate to true for all cases where isAdmin isn’t nil! I ran into this so many times I even contemplated scrapping Core Data to erase the emotional pain. Maybe I’m alone, but early on one of the mistakes I made over and over again was to forget that my numeric entity attributes were wrapped in NSNumber. Add all you want, now! The clean coding gods will thank you!įrom here on out, whenever you change your model, regenerate the classes, rinse and repeat. Yes, that’s right, gone are the days where you avoided adding methods to your concrete classes knowing that once you did you wouldn’t be able to generate them anymore. The Event.* files are generated only if they don’t exist and you can feel free to add any methods and properties you like. The _Event.* files are generated and you should never touch them. It’s also been used for years and shame on Apple that they don’t do this out of the box. If you’re not familiar with this pattern, it’s amazing. ![]() You’ll notice that there are two sets of files, _Event.* and Event.*. You won’t have to do this on future regenerations, but for new entities, yes. At this point, since you generated new files, you’ll need to add them to your project. ) All I know is it’s much easier now.Ĭhange your build target to “Mogenerator” (or whatever you called it) and hit ⌘B to build. I think they made it a little easier recently, but it was crazy and I use Mogen now so I don’t care anymore. It seems to involve selecting the right entities in the model, adding a new file, and changing some check- look, I don’t know. I’ve been programming iPhone apps for almost 3 years now and, I’ll be honest, I still can’t tell you the exact steps to generate Core Data classes. Now, we’re all ready to go, but what did we win? I’ll outline that next. (You can name it whatever you want, actually, but that would be mighty stupid to do.) When you create entities in your data model, be sure to populate the “Class” field with the same name as the entity.Mogenerator -m M圜oreDataApp/MyModel.xcdatamodeld/MyModel.xcdatamodel -O M圜oreDataApp/Model -swift -template-var arc=true ![]() Mogenerator -m M圜oreDataApp/MyModel.xcdatamodeld/MyModel.xcdatamodel -O M圜oreDataApp/Model -template-var arc=true In that case, you’ll need to be more explicit with the model name. If you don’t have versions, or your project is brand new, this may fail. Do note that we take advantage of mogen’s ability to automatically find your current model version. Remove the ARC option if, for some reason, you’re not using ARC. You’re passing in your Core Data model path and directory you want the generated files to live (the directory will be created if it doesn’t exist), so feel free to change the names to match your project. Mogenerator -m M圜oreDataApp/MyModel.xcdatamodeld -O M圜oreDataApp/Model -swift -template-var arc=true Mogenerator -m M圜oreDataApp/MyModel.xcdatamodeld -O M圜oreDataApp/Model -template-var arc=true Open the Run Script group that just appeared, keep the Shell at /bin/sh, and then enter the following script if you’re using Objective-C:.Now select the new target you just created, select the “Build Phases” tab, tap “+” to add a build phase then select “New Run Script Build Phase”.Add an “Aggregate” target (you’ll find it in the iOS/Other grouping).In your project, open your project properties and tap the “+” button at the bottom of the Targets list.After this one-time step, we’ll now configure your project to use it: It’s simple, you install Mogen from a DMG. The first thing you’ll need to do is install Mogen. I can’t wait to get into it all, but first you need to install Mogen and set up your project! Installation Handy wrapper methods for insertion/entity identification.Handy setter methods for manipulating sets easily.Alleviates the need to wrap numeric attributes in NSNumber objects.A proper two-class treatment in that generation.Faster and easier generation of concrete classes for your model.What you *will* get, however, is a Core Data that will be far, far easier to use. There’s so much to know, and you’re not going to get any new functionality from Mogen either. So let’s get to it! I know Core Data already, so why do I need Mogen?Ĭore Data is a huge beast of a thing. If you don’t, well don’t worry, I’m not only going to tell you why you need it, I’m including a tutorial on how to use it! I mean, really, you *should* be using it. If you’re an iOS developer using Core Data in your app, whether a n00b or expert, you should be using Mogenerator.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |