iPhone Core Data Generated Model Files and Custom Code - iphone

After I've generated the interface/implementation files for entities of a model file in XCode, I've not found a way to keep any custom code (validation methods, etc...) I've added to those generated files, given the scenario where I've added an attribute to a model entity and need to re-generate the interface/implementation files. Does anyone know of a way to make this happen? I've just been doing the copy/paste shuffle, but there has to be a better way.

Assuming that you're only talking about adding methods, and not new instance variables, I'd recommend using Objective C categories to add additional behavior to your model classes. Here's a blog post along the same lines.

Use mogenerator, which uses the Generation Gap design pattern to prevent your customizations from being overwritten when the code is re-generated.

Related

Where are class extensions placed in an MVVM pattern?

I am new to this and still trying to get a feel for the best way to do things with MVVM. I can't find an answer with Google.
For convenience, I have created extensions on multiple custom classes, e.g.,
public static AppointmentLabel ToLabel(this textblockPatient tbp)
{
return tbp.appointmentlabel;
}
In my MVVM model, I have placed these extensions in the Model as they seem to convert one source of information into another. However, some of the custom classes are UserControls and live in the View. Doing it this way would require the Model to "know" something about the View, as the above textblockPatient is a UserControl.
How is this done within a MVVM pattern? Are extensions considered to be an exception to the pattern?
Thanks for any help.
In my opinion this is not a mvvm related thing. I would suggest that you put your extension classes near to the classes they extend. By doing it so you reach some level of cohesion. Sometimes it make sense to put the extensions in a seperate project. For example if you know you want need that extensions all the time and you want to have a small codebase or faster compile time.

Is my thinking about mvvm right?

I'm having a little bit of a hard time getting into mvvm. I'm writing a simple app, Notebook. I have one viewmodel, it's name is actually ViewModel. It has an ObservableCollection of Notes inside and methods to save and load those from Isolated Storage. My only Model is Note.cs, it implements INotifyPropertyChanged and I'm of course RaisingPropertyChanged.
I've also got two view, both of them are user controls. One to display list of notes and one to edit the one chosen from the list.
My questions are:
Where do I create an instance of my vievmodel?
How should I implement going from the page with list of notes to the page with detailed view after choosing one Note to edit? At the
moment I'm saving the index of Note in App.xaml.cs, going to the next page and setting
the DetailedView DataContext to the right Note in OnNavigatedTo, but
I don't think it's actually the perfect solution.
Where should I save my Notes? I guess Application_Closing in App.xaml.cs is the right place to do it, but I'd have to have my viewmodel as a global object there, is this the right approach?
Additional question:
I have to add possibility to group notes. I guess that class Group with dictionary (GroupName, howManyNotes) is going to be allright since I don't have to be able to for example write all notes from selected group. Do you think there's a better approach I should think about?
Thanks for respones,
MichaƂ.
I would suggest you take a look at Calibrun.Micro which is a great framework for MVVM. You can get some sample from the CodePlex.
I have used that in a bunch of Project, and will give you flexibility in case if your project grows in size.
Google for Caliburn.Micro sample and you will find a number of sample for all technologies like WPF, Silverlight, Windows Store, Windows Mobile.
Caliburn.Micro CodePlex

T4 template and EF with Code Generator from database schema Application

I am currently in process of putting a process (using a windows application) in place where EF's POCO objects classes can be generated by pointing this app to the database table(s).
I have seen T4 templates and the VS Addin which helps to achieve this in VS. However it requires T4 template file on the VS solution. We do not want to go through this route. What we want is to just copy the classes generated by this app to the solution so it can be used.
The way T4 template works is that as soon as you make a change in the template it applies to the Class file. What I would like to do is to point the new App to the database and say tables A,B,C. The app will read the columns,types,relationships and create corresponding classes to a folder. Developer then Copy these classes and paste into VS solution. Longer terms plan then to extend this app to write repository classes.
I have rough idea but not a clear picture. Does anyone has any pointers about how about can I go to achieve this?
Thanks
Edit: This is purely in mind using EF Code first.
What it seems you are asking is "Can my T4 templates live in a separate solution to my output code?".
Yes. You can do that.

Core Data Recipes Question

This is just a quick question I have about Apple's core data "Recipes" project, so I don't need elaborate answers. When you edit a recipe you can also edit the type. When the type cell is pressed it presents the user with a table view populated by multiple types. How exactly were those types created? I can't seem to find an explanation in the project code or in the .xcdatamodel (I've checked everywhere, and searched it) Also, why does "RecipeType" have to be it's own entity? Why can't it just be part of the "Recipe" entity? Does that have anything do with it?
In this case RecipeType doesn't necessarily have to be its own type, but it is common practice. Using an association like this has many benefits. Say if you wanted to add more metadata per type, you could add it to the RecipeType instead of duplicating a bunch of data throughout your recipes.
It appears that these recipe types are already inserted into the SQLite database Recipes.sqlite. It doesn't appear that they used any of the code in the project to populate this database. It was most likely done using Terminal or some other GUI SQLite editor.

How to prune Zend Framework?

I wouldn't use most of the classes from Zend Framework, that's why I'm looking for the thinnest possible ZF configuration.
Is there a better way of finding what I really need other than deleting the whole library/Zend folder, then putting back files based on the error messages that I receive?
I have not used it myself, but http://blog.fedecarg.com/2009/02/01/zend-framework-automatic-dependency-tracking/ may be what you are looking for.
Hm...
There is a lot of information about Zend Framework on SO and with a little bit of reading you would have found the answers to your question
You would also find the answers to your question by just reading the introduction to Zend Framework on the Zend Framework website.
No, that's not how you'll do it. Zend Framework, unlike most/all other PHP frameworks, is rigidly loosely coupled. You can use every component stand-alone. You can only use the loader, or only Zend_Translate. Or you can just use the MVC modules, or Zend_Db, etc.
Of course if you use Zend_Form and want to validate or filter the input, you'll need Zend_Validate and Zend_Filter. But you'll know that because you'll instantiate objects. So just copy into your empty library folder the modules you need. Or even better, copy everything in! A) you won't regret it. B) disk space is not your problem.
What I would do is set up the plugin loader cache and then purge all files apart from the ones called within the automatically generated include file.
zend.loader.pluginloader.performance
I hope it makes sense... :o)