Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Xcode core data code generated files to be public accessed

I am a bit confused with new codegen functionality.

While developing, you could lookup all files that exist in projects. But not with codegen.

However, it worked well. But it doesn't fit new framework-oriented programming paradigm.

Scenario: I have completely separate framework Database. It could be embedded in application or could not. It depends. But it is completely separated.

Now I would like to use codegen feature. It describes automagic. It spawns in DerivedData all Core Data headers and it switch core data models development to categories-oriented paradigm ( hello, swift! )

Ok, everything works fine and compile until I want to expose all files with public access. It is obvious that all model files ( nearly all except, for example, hidden entities or abstract entities if necessary ) have public access level.

However, Xcode doesn't find template for codegen files.

It doesn't work, for example, in case of missing Map.modulemap file. Ok.

In this scenario it looks like:

framework module DBDatabaseBeaver {  
  umbrella header "DBDatabaseBeaver.h"  
  export *  
  module * { export * }  
}

But if I am right, this modulemap file doesn't lookup in correct Xcode CodeGen CoreData directory ( DerivedData ).

Also, it is hard to know which access level do these codegen headers have.

I have only one setting that could change something: Module setting in codegen.

But if I change it to something different from Global Namespace, it makes tricks with me and codegen file like:

// $(DatabaseModelName).h  
#import ".DBDatabaseEntity+CoreDataClass.h"  
#import ".DBDatabaseEntity2+CoreDataClass.h"  
...

Take a look at this file.

  1. It somehow put dots at the beginning of filename.

  2. It relies on $(DatabaseModelName), not on $(DatabaseModuleName).

  3. See 2. ModelName is xcodemodel filename. ModuleName is a framework target module name. It uses first, not second.

Could anybody explain a solution for scenario and add comments/(documentation links?) about all codegen features?

I thought that this scenario could be solved by fixing modulemap file and by adding correct Module name for entities in Model ( codegen setting ).

However, I don't know which paths should I add to modulemap to point to codegen files.

like image 902
gaussblurinc Avatar asked Oct 30 '22 10:10

gaussblurinc


1 Answers

You should be able to make the automatically generated header files be publicly accessible by copying them from the derived sources folder to the public headers folder of your framework.

You can do this by adding an extra Run Script step to the target of your framework. Copy the following script into the script editor and replace Your_Framework with the name of your frameworks executable.

#set -o xtrace
find "${DERIVED_SOURCES_DIR}/CoreDataGenerated/Your_Framework" -type f -name "*.h" -exec cp {} "${BUILT_PRODUCTS_DIR}/${PUBLIC_HEADERS_FOLDER_PATH}" \;

All this script does is list every header file in the derived sources directory (find $SOURCEPATH -type f -name "*.h") and then calls copy on each one in turn -exec cp {} $DESTPATH \;

If you have any problems uncommenting the first line (i.e. removing the #) and then looking at the build log should make it easier to diagnose.

like image 127
tdbit Avatar answered Nov 15 '22 09:11

tdbit