Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-19740] xcdatamodel file not included when building application

GitHub Issuen/a
TypeImprovement
PriorityCritical
StatusOpen
ResolutionUnresolved
Affected Version/sRelease 4.1.1
Fix Version/sn/a
ComponentsiOS
LabelsCommunity, engArch
ReporterJim Villa
AssigneeUnknown
Created2015-10-14T12:38:00.000+0000
Updated2019-12-13T17:28:28.000+0000

Description

I am having an issue with a module I built. The iOS native module contains a xcdatamodel file which is a database for storing data, this file is not being built with app but if I copy the file to the app after it is built in xcode everything works and file is recognized in app. The problem is when I rebuild it removes the file again, or when I submit to apple store. I know you dont support core data but I just need to know how to include this file in the build process. Provide me with an email address and I can share my dropbox account with the app and module if needed.

Comments

  1. Motiur Rahman 2015-10-16

    Hi [~jamesavilla] Could you please show me a simple sample code that reproduces the issue? Not your full application.
  2. Jim Villa 2015-10-16

    Please create a new project in appcelerator studio. When you run that new app I need the Xcode project that is built when ran to include the .xcdatamodel file that I sent you previously in the root of the Xcode project.
  3. Jim Villa 2015-11-06

    Could you please provide a full update on the status of the issue, I haven't received any feedback for a few weeks now.
  4. Pedro Enrique 2015-11-09

    [~jamesavilla], take a look at [this guide](http://docs.appcelerator.com/platform/latest/#!/guide/iOS_Module_Project-section-43288810_iOSModuleProject-BundleModuleAssets)
  5. Jim Villa 2015-11-10

    @Pedro Enrique I have already tried that. The xcdatamodel file does not get carried over to the built application. Please add the file to your assets folder then build your application and you will see the file does not get built with the application.
  6. Chris Barber 2015-12-02

    [~jamesavilla] We don't have support for adding files to the Xcode project yet. I can see Titanium supporting this someday. In the meantime, you'll need to make a CLI hook. Start by creating a directory in your module project called "hooks". Create a .js file in that hooks folder and add the following:
       'use strict';
       
       /** The plugin's identifier */
       exports.id = 'com.example.hook';
       
       /** The Titanium CLI version that this hook is compatible with */
       exports.cliVersion = '>=3.2';
       
       /**
        * Initialize the hook.
        *
        * @param {Object} logger - The logger instance
        * @param {Object} config - The CLI config object
        * @param {CLI} cli - The CLI instance
        * @param {Object} appc - The node-appc library
        */
       exports.init = function init(logger, config, cli, appc) {
       	cli.on('build.ios.xcodeproject', function (data, callback) {
       		console.log(data.args[0]);
       		callback();
       	});
       };
       
    data.args\[0\] will be a JavaScript object containing the Xcode project. You can add file references, groups, and files to build phases to this object. When you're done, call callback() and the Xcode project will be written to disk. I should point out that we don't support this. You can get it to work, but it's not for the faint of heart. You will need to understand the Xcode project file format and the Xcode NPM module (https://www.npmjs.com/package/xcode). This is not straight forward. Just to add a single file, you'll need to add 2-5 entries in various sections of the Xcode project. If you miss one, it won't work. Hope this helps.
  7. Diego Freniche 2018-02-22

    Just had to fix this.

    Problem was:

    - I have an Alloy project, with an extension. - Inside the extension there's a Core Data Model "file" xcmodeld - That xcmodeld is correctly copied to the generated Xcode project - The xcmodeld is NOT added to the Compile Sources Build Phase of the Share Extension target. Instead you'll see an empty row

    Fix for the problem

    - adding the xcmodeld to the target

    How I did this

    1. Add a plugin definition to your tiapp.xml
       <!-- Plugins -->
           <plugins>
               <plugin version="1.0">ti.alloy</plugin>
       
               <plugin version="0.1">core-data-fix</plugin>
             
           </plugins>
       
    2. the idea is that using that plugin we're going to manually add the missing reference to our target 3. create a plugin in your project with this structure: {noformat} plugins/core-data-fix └── 0.1 └── hooks ├── fix-core-data.js └── fix-core-data.rb {noformat} You should have the plugins directory with alloy inside. 4. Your fix-core-data.js file is a hook that will launch before the Xcode project starts building. Should contain something like:
       
       // This hooks to the event "build.ios.xcodeproject". When building the generated Xcode project we need to add a reference
       // to the Core Data model file inside the Share extension. This is done inside the Ruby script:
       // plugins/core-data-fix/0.1/hooks/fix-core-data.rb
       
       exports.init = function (logger, config, cli, nodeappc) {
           cli.on("build.ios.xcodeproject", function (data, callback) {
               var child_process = require('child_process');
       
               // exec: spawns a shell.
               child_process.exec('plugins/core-data-fix/0.1/hooks/fix-core-data.rb', function(error, stdout, stderr){
                   console.log(stdout);
                   console.log(error);
               });
       
               callback();
           });
       };
       
    5. To fix our target I'll use xcodeproj, which is part of CocoaPods. So install CocoaPods if you don't have them already.
       
       #!/usr/bin/env ruby
       
       

    Problem: the extension Projects-Share contains a Core Data Model file that's not correctly added

    to the generated project's extension target.

    The Model Core Data file is correctly copied inside the generated Alloy Xcode project

    This ruby script adds the Model file to the extension target

    Dependencies: xcodeproj gem, which comes bundled with Cocoapods

    require 'pathname' require 'xcodeproj' class String # colorization def colorize(color_code) "\e[#{color_code}m#{self}\e[0m" end def red colorize(31) end def green colorize(32) end def yellow colorize(33) end def blue colorize(34) end def pink colorize(35) end def light_blue colorize(36) end end path_to_core_data_model = "extensions/Projects-Share/Projects-Share/Categories/Core\ Data/Model.xcdatamodeld/" puts "************************ BEGIN SCRIPT **********************************".light_blue puts path_to_core_data_model.blue puts "************************* END SCRIPT ***********************************".light_blue path_to_project = 'build/iphone/Projects.xcodeproj/' puts path_to_project project = Xcodeproj::Project.open(path_to_project) puts project target = project.targets.first project.targets.each do |t| if t.name == "Projects-Share" target = t break end end puts target group = project["Extensions"]["Projects-Share"]["Projects-Share"]["Categories"]["Core Data"] puts group model = group.new_reference('Model.xcdatamodeld') target.add_file_references([model]) project.save
    That's all!

    Environment:

    - SDK 7.0.2.GA - Xcode 9.2 - macOS 10.13.3 High Sierra - cocoa pods 1.4.0

JSON Source