Skip to content

Instantly share code, notes, and snippets.

@alloy
Forked from epologee/TwelveTwentyToolkit.podspec
Created September 30, 2012 15:54
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alloy/38a3400bffc0837af5f3 to your computer and use it in GitHub Desktop.
Save alloy/38a3400bffc0837af5f3 to your computer and use it in GitHub Desktop.
How do I get the .xcdatamodel as a compiled resource into my pod?
Pod::Spec.new do |s|
s.name = 'TwelveTwentyToolkit'
s.version = '0.0.1'
s.summary = 'The Twelve Twenty Toolkit of reusable Objective-C classes.'
s.homepage = 'http://twelvetwenty.nl'
s.license = 'MIT'
s.author = { 'Eric-Paul Lecluse' => 'epologee@gmail.com', 'Jankees van Woezik' => 'jankeesvw@gmail.com' }
s.source = { :git => 'https://github.com/TwelveTwenty/TwelveTwentyToolkit-ObjC.git', :commit => :head }
s.platform = :ios, '5.0'
s.source_files = 'TwelveTwentyToolkit/TwelveTwentyToolkit.h'
s.requires_arc = true
s.preferred_dependency = 'CoreGraphics'
s.subspec 'CoreGraphics' do |cg|
cg.frameworks = 'UIKit','QuartzCore'
cg.source_files = 'TwelveTwentyToolkit/CoreGraphics/*'
end
s.subspec 'CoreData' do |cd|
cd.frameworks = 'CoreData'
cd.source_files = 'TwelveTwentyToolkit/CoreData/*'
end
s.subspec 'AddressBook' do |uab|
uab.frameworks = 'AddressBook'
uab.dependency 'TwelveTwentyToolkit/CoreData'
uab.source_files = 'TwelveTwentyToolkit/AddressBook','TwelveTwentyToolkit/AddressBook/Entities','TwelveTwentyToolkit/AddressBook/Entities/Abstract'
uab.preserve_path = 'TwelveTwentyToolkit/AddressBook/TTUnifiedAddressBook.xcdatamodeld'
def uab.post_install(target_installer)
momd_relative = 'TwelveTwentyToolkit/AddressBook/TTUnifiedAddressBook.momd'
momd_full = config.project_pods_root + momd_relative
unless momd_full.exist?
puts "\nCompiling TwelveTwentyToolkit/AddressBook Core Data model\n".yellow if config.verbose?
model = config.project_pods_root + 'TwelveTwentyToolkit/AddressBook/TTUnifiedAddressBook.xcdatamodeld'
command = "xcrun momc '#{model}' '#{momd_full}'"
command << " 2>&1 > /dev/null" unless config.verbose?
unless system(command)
raise ::Pod::Informative, "Failed to compile TwelveTwentyToolkit/AddressBook Core Data model"
end
end
File.open(File.join(config.project_pods_root, target_installer.target_definition.copy_resources_script_name), 'a') do |file|
file.puts "install_resource '#{momd_relative}'"
end
end
end
end
@alloy
Copy link
Author

alloy commented Sep 30, 2012

This is untested code. The idea is to preserve the path, compile it after installation has finished and manually add it to the install resources script. It's less than ideal, but this is (afaik) the first time someone needed a compiled Xcode Core Data model in a lib.

Note that the model is not added to the Xcode project from where it could be edited. Was that actually the intention?

Based on:

@epologee
Copy link

Having it added to the Xcode project was indeed my original intent, sorry for the confusing title. Would that be 'easier' to do?

@epologee
Copy link

This would do however, if the code would run.
undefined local variable or method moms_full' for #<Pod::Specification for TwelveTwentyToolkit/AddressBook (0.0.1)> ~/.cocoapods/twelvetwenty/TwelveTwentyToolkit/0.0.1/TwelveTwentyToolkit.podspec:33:inpost_install'

@alloy
Copy link
Author

alloy commented Sep 30, 2012

No, making it available to the user in Xcode would make it harder. I’ve fixed the spelling error: moms_full -> momd_full

@epologee
Copy link

Right, now the compile hangs at Xcode I think, [...]/Pods/TwelveTwentyToolkit/AddressBook/TTUnifiedAddressBook.xcdatamodeld:0: error: Could not create bundle folder for versioned model at '[...]/Pods/TwelveTwentyToolkit/AddressBook/TTUnifiedAddressBook.momd'. Sorry for all this...

@horseshoe7
Copy link

Did anyone figure this out? I'm still hacking away the ruby script above and it's just becoming a pandora's box... I'm thinking I might just implement the data model in code, using this resource: http://www.cocoanetics.com/2012/04/creating-a-coredata-model-in-code/

@designatednerd
Copy link

I was able to get a core data model integrated with the Pod I've been developing by using the podspec settings in this bug - basically it's:

s.resources = '[path_to_data_model_enclosing_folder]/*.{xcdatamodeld,xcdatamodel}' s.preserve_paths = [path_to_data_model_enclosing_folder]/*'

There's about zero documentation on this functionality, though, so your mileage may vary.

@lemonkey
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment