Search code examples
objective-cimportdirectorymogenerator

Refer to higher directory in #import statement Objective C


I am using Mogenerator to automatically create subclasses for my Entities in Core Data.

I had acted upon a recommendation I read to store the files in subdirectories within my project (since I will have many). Used the following arguments when running the script:

cd Project
mogenerator --template-var arc=true -m Project.xcdatamodeld/Project.xcdatamodel/ -      M CoreData/Machine/ -H CoreData/Human/

I added these to my project as a folder reference, as the script may add files to match my model and I don't want to have to add them to my project manually.

The directory structure for both the created files are like this:

Project/CoreData/Human/Entity.h
Project/CoreData/Machine/_Entity.h

I need to import "_Entity.h" inside of "Entity.h". The problem is, it's not in the same or lower directory and I don't know how to do a relative reference to a higher directory. I'm forced to use an absolute directory all the way from /Users.. which works, but it includes my username etc. so I'd rather not.

Question: How can I import _Entity.h from Entity.h using relative reference?

Bonus question: Is it possible to have mogenerator automatically use the proper reference? I mean, I'm clearly telling it where to put both files and it's doing it, but still only puts the following in Entity.h:

#import "_Entity.h"

...and I get an error.

Thanks in advance,

Pat


Solution

  • ".." (without the quotes) represents the directory that's "one level higher". Use this to go to "CoreData", then to "Machine".

    Try this:

    #import "../Machine/_Entity.h"
    

    I'm not sure if it'll work, but it's worth a try!