2

Recently I got up in a discussion with someone about whenether or not to include NSManagedObjects into the iOS Prefix file (.pch)

I did that because it will speed up development time (e.g syntax completion works for all model names etc, build times are a bit faster)

Currently we have ~70 different tables (and thus ~70 different NSManagedObject classes) I made a shell script that will list these files and create a header called AllModels.h that will import those tables. Then I include that as a #import in the pch file. So now, we can use all of the tables in our entire project.

He said that we cannot have that anymore because it's a bad practice and I disagree. I do not know if I am right or wrong actually. In my mind yes I feel am right, but I try to get a bigger view over here about this situation, so I would like to hear from you guys, what's better? Including the NSManagedObject you need in the header of the file you are working in, or include them at once in the pch file?

Thanks for your time! :)

Peter Willemsen
  • 735
  • 1
  • 7
  • 13

1 Answers1

1

read http://qualitycoding.org/precompiled-headers/

in general it isnt wrong to include MOM headers there I'd say..

I'd wrap the stuff in my own "PROJECT_MOMs.h" and include it in the pcm + in the files that really need the MOMs, that way you get the speed but don't rely too heavy on the pch

Daij-Djan
  • 49,552
  • 17
  • 113
  • 135
  • 1
    Interesting article, but the conclusion seems to be *not* to use the pch file for all your import files. – Martin R Apr 10 '13 at 07:59
  • Yeah I read it as well, but they also say in "3. Dependencies are buried" that you could use .pch to omit many #imports, which is definetly the case over here. – Peter Willemsen Apr 10 '13 at 08:01
  • And if we are going to reuse to code to another project we need to remove the core-data related code anyway, because that's related to the project we are working on. – Peter Willemsen Apr 10 '13 at 08:14
  • edited my answer with what I would do :D – Daij-Djan Apr 10 '13 at 08:15
  • Ok thanks ;) It's really appreciated. I never really understood why to import it twice, I am trying to read the article again ;) So I have a better understanding – Peter Willemsen Apr 10 '13 at 08:17
  • I saw from this answer: http://stackoverflow.com/questions/6462288/why-do-xcode-templates-have-imports-that-duplicate-prefix-pch that they say "Better safe than sorry. Precompiled headers can be disabled, and since #import won't import anything twice, the overhead is negligible." but why do I want to disable prefix file? – Peter Willemsen Apr 10 '13 at 08:20
  • you don't IMO but each file should remain correct and compilably even without it – Daij-Djan Apr 10 '13 at 08:37
  • e.g. when you copy a file to another project – Daij-Djan Apr 10 '13 at 08:37
  • Ok thanks for explaining. Yeah it does make sense then. It still precompiles from the prefix but if we do move it to another project it compiles from the header of the file we just moved. Nice! Thanks! If I could upvote again I would have done that :) – Peter Willemsen Apr 10 '13 at 08:46