Cocoapods: Adding xcdatamodeld to CocoaPod doesn't get compiled

Created on 17 Jan 2017  Â·  17Comments  Â·  Source: CocoaPods/CocoaPods

Report

What did you do?

Created a pod with a Core Data xcdatamodeld

What did you expect to happen?

Model would be available in projects that included the pod

What happened instead?

The model was included, and checked off as having target membership of the example project, but it did not get compiled. I had to uncheck and recheck the target membership to get it to work. When I compared the xcodeproj files before and after checking the box again, I saw this difference:

< ./Pods/Pods.xcodeproj/project.pbxproj:        FD2B428016F471AE85421F463212D494 /* NavaidDBModel.xcdatamodeld in Resources */ = {isa = PBXBuildFile; fileRef = 3F02E72A1BECE8F5F640CFCDD8D58EB0 /* NavaidDBModel.xcdatamodeld */; };
---
> ./Pods/Pods.xcodeproj/project.pbxproj:        3166738A1E2E793A00B162FA /* NavaidDBModel.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 3F02E72A1BECE8F5F640CFCDD8D58EB0 /* NavaidDBModel.xcdatamodeld */; };
5c5
< ./Pods/Pods.xcodeproj/project.pbxproj:                FD2B428016F471AE85421F463212D494 /* NavaidDBModel.xcdatamodeld in Resources */,
---
> ./Pods/Pods.xcodeproj/project.pbxproj:                3166738A1E2E793A00B162FA /* NavaidDBModel.xcdatamodeld in Sources */,

CocoaPods Environment

Stack

   CocoaPods : 1.2.0.beta.1
        Ruby : ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin16]
    RubyGems : 2.0.14.1
        Host : Mac OS X 10.12.1 (16B2555)
       Xcode : 8.2 (8C38)
         Git : git version 2.10.1 (Apple Git-78)
Ruby lib dir : /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib
Repositories : master - https://github.com/CocoaPods/Specs.git @ b55940b4a6bf7565c1f527af3826198975cca6bc
               theweathercompany -  @ fatal: Not a git repository (or any of the parent directories): .git
               theweathercompany-1 - [email protected]:TheWeatherCompany/twcios-podspecs.git @ 130fa44d79b9c66f6318e4e3663f12696b5b8328

Installation Source

Executable Path: /usr/local/bin/pod

Plugins

cocoapods-deintegrate : 1.0.1
cocoapods-plugins     : 1.0.0
cocoapods-search      : 1.0.0
cocoapods-stats       : 1.0.0
cocoapods-trunk       : 1.1.1
cocoapods-try         : 1.1.0
awaiting input

Most helpful comment

Although this is was closed, I think I miss some very basic understanding

  1. When you add a CoreData model to your Pod-Spec, is it intended for use by the Pod you're creating, or by the client depending on the Pod? (arguments can be made for both cases - and I want to understand what needs to be done in the podSpec for each).
  2. When client expects a pod to provide/expose its CoreData model - should the pod make available the ORIGINAL model, or the COMPILED version?
  3. When a framework pod exposes a Resource (in general) to the client - is the resource exposed in the Pod's code-bundle (framework), or directly in the Client's bundle? (I'd prefer it confined to the Pod framework, but I can't find any coherent definitions on this.

I really need answers here... since I'm providing an SDK to clients, and I need clear definitions. THANKS!

All 17 comments

Hi @blackbear! Thanks for reporting this! Can you please show your podspec? Thanks!

#
# Be sure to run `pod lib lint NavigationDataSource.podspec' to ensure this is a
# valid spec before submitting.
#
# Any lines starting with a # are optional, but their use is encouraged
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#

Pod::Spec.new do |s|
  s.name             = 'NavigationDataSource'
  s.version          = '0.1.0'
  s.summary          = 'A short description of NavigationDataSource.'

# This description is used to generate tags and improve search results.
#   * Think: What does it do? Why did you write it? What is the focus?
#   * Try to keep it short, snappy and to the point.
#   * Write the description between the DESC delimiters below.
#   * Finally, don't worry about the indent, CocoaPods strips it!

  s.description      = <<-DESC
TODO: Add long description of the pod here.
                       DESC

  s.homepage         = 'https://github.com/<GITHUB_USERNAME>/NavigationDataSource'
  # s.screenshots     = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
  # s.license          = { :type => 'MIT', :file => 'LICENSE' }
  s.author           = { 'James Turner' => '[email protected]' }
  s.source           = { :git => 'https://github.com/<GITHUB_USERNAME>/NavigationDataSource.git', :tag => s.version.to_s }
  # s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'

  s.ios.deployment_target = '10.0'

  s.source_files = 'NavigationDataSource/Classes/*'
  s.resources = 'NavigationDataSource/Classes/NavaidDBModel.xcdatamodeld'

  # s.public_header_files = 'Pod/Classes/**/*.h'
  # s.frameworks = 'UIKit', 'MapKit'
  # s.dependency 'AFNetworking', '~> 2.3'
end

Ah. Can you try moving NavigationDataSource/Classes/NavaidDBModel.xcdatamodeld to s.source_Files? Based on your diff, Xcode seems to prefer it there.

If I do that, it doesn't show up at all in the project.

Hm yeah your podspec actually looks fine to me. Can you show me the error output? Thanks!

This is pretty confusing. There are a few other Core Data related issues out right now, and they all seem to be kind of related. I'll dig in some more over the next few days.

@blackbear

could you try a podspec like this:

  s.source_files  = 'NavigationDataSource/Classes/NavaidDBModel.xcdatamodeld', 'NavigationDataSource/Classes/NavaidDBModel.xcdatamodeld/*.xcdatamodel'
  s.resources = [ 'NavigationDataSource/Classes/NavaidDBModel.xcdatamodeld','NavigationDataSource/Classes/NavaidDBModel.xcdatamodeld/*.xcdatamodel']
  s.preserve_paths = 'NavigationDataSource/Classes/NavaidDBModel.xcdatamodeld'

s.resources might not be neccesary considering what you said about it not appearing at all.

This very old sample project still works for me, even though the xcdatamodeld isn't in Compile Sources
https://github.com/Ashton-W/CoreDataPodSample

Ashton-W, that didn't change the behavior, alas. Still need to click twice to make it work.

@Ashton-W @blackbear there does seem to be an issue with adding .xcdatamodeld files to source_files, which I think is a bug (or maybe old intentional feature?). I'm going to look at fixing that first, since that seem to be a requirement for fixing #6259.

Any progress on this, or a workaround?

Sorry I haven't been able to make progress on this, but it's still at the top of my list. I did look into adding support for xcdatamodeld in source_files, but that's unlikely to happen without making source_files behave oddly because of how source_files handles directories (just adds the contents of directories, whereas Xcode expects to add the xcdatamodeld folder as a build file…).

I did find that CocoaPods manually compiles xcdatamodelds in the [CP] copy resources build phase (hadn't really dug into this behavior until this issue cropped up, so I'm learning here too :) ). I'm not entirely sure fixing the other issue I mentioned will necessarily solve this one like I hoped. I'm still a bit confused why this case doesn't work in this instance. Would you mind posting the output from that build phase I mentioned? Maybe that'll help demystify this. Thanks, and I apologize for the delay!

Hi @blackbear! I'm using the sample pod in #6259, but I've modified it to be more like yours, so I have the data model add as a resource instead of as a source file. When I do this, I do see it getting compiled. You are right that the new Xcode default seems to be to add these files to the compile build phase instead of the copy resources build phase, but the newer default has more to do with build order, since in either case the model is compiled (working on updating CocoaPods for this as part of #6259). Here's a screenshot from my sample app:

screen shot 2017-03-03 at 7 35 27 am

If you can check your build log to verify that you don't see anything like this, that'd be great. Otherwise, I think I'll need some kind of sample pod/app on GitHub (or uploaded here as a zip) to help debug. Thanks and apologies again for the large delay!

Closing via #6560

Although this is was closed, I think I miss some very basic understanding

  1. When you add a CoreData model to your Pod-Spec, is it intended for use by the Pod you're creating, or by the client depending on the Pod? (arguments can be made for both cases - and I want to understand what needs to be done in the podSpec for each).
  2. When client expects a pod to provide/expose its CoreData model - should the pod make available the ORIGINAL model, or the COMPILED version?
  3. When a framework pod exposes a Resource (in general) to the client - is the resource exposed in the Pod's code-bundle (framework), or directly in the Client's bundle? (I'd prefer it confined to the Pod framework, but I can't find any coherent definitions on this.

I really need answers here... since I'm providing an SDK to clients, and I need clear definitions. THANKS!

I would love answers to the above questions too.

I still experience this on CocoaPods 1.7.0.beta.3. 😕

Was this page helpful?
0 / 5 - 0 ratings