Updated on 2013-08-10: thanks to Esteban Torres; updated the script with a test if there’s settings in build file, and if not create the hash.
You know this truth: frameworks are great and easy when your tasks are completely covered by its functionality, but the moment you need to do something out-of-box there are going to be issues there.
CocoaPods is a great tool to manage the dependencies of iOS/OS X projects, here are my posts about it: installing, usage1, usage2, some thoughts, and notes. It’s been working fine in my project, and when one time I updated the Pods project, it brought the updated version of JSONKit 1.5pre.
That new version generated a bunch of warnings:
123
warning: values of type 'NSUInteger' should not be used as format arguments; add an explicit cast to 'unsigned long' instead [-Wformat]
warning: direct access to objective-c's isa is deprecated in favor of object_setClass() and object_getClass() [-Wdeprecated-objc-isa-usage]
So a more suitable solution is to apply the flags on my side. Podfile provides two hooks: pre_install and post_install for that purpose. I couldn’t find any serious examples of using them, so I had to figure it out myself (also note that I have almost no knowledge of Ruby). Here’s my Podfile with a post_install hook example:
platform:iospod'JSONKit','1.5pre'# The post install hook add certain compiler flags for JSONKit files so that# they won't generate warnings. This had been done in the podspec before, but# was removed later for some reason.post_installdo|installer|# Adds the specified compiler flags to the given file in the project.## @param [Xcodeproj::Project] project# The Xcode project instance.## @param [String] filename# The name of the file to work with.## @param [String] new_compiler_flags# The compiler flags to add.## @example Disable some warning switches for JSONKit:# add_compiler_flags(installer.project,# "JSONKit.m",# "-Wno-deprecated-objc-isa-usage -Wno-format")#defadd_compiler_flags(project,filename,new_compiler_flags)# find all PBXFileReference objects of the given filefiles=project.files().select{|file|file.display_name()==filename}# get the PBXBuildFile references of the found files# PBXBuildFile actually contains flags for building the filebuild_files=files.map{|file|file.build_files()}.compact.flatten# compiler flags key in settingscompiler_flags_key="COMPILER_FLAGS"ifbuild_files.length>0build_files.each{|build_file|settings=build_file.settingsifsettings.nil?# If we don't have settings for the file we create a new hashsettings=Hash[compiler_flags_key,new_compiler_flags]elsecompiler_flags=settings[compiler_flags_key]compiler_flags=(compiler_flags.nil?)?new_compiler_flags:(compiler_flags+" "+new_compiler_flags)settings[compiler_flags_key]=compiler_flagsendbuild_file.settings=settings}elseputs"No build file refs found for #{filename}!"endend# compiler flags that turn off the JSONKit's warningsJSONKIT_FLAGS="-Wno-deprecated-objc-isa-usage -Wno-format"add_compiler_flags(installer.project,"JSONKit.m",JSONKIT_FLAGS)end
It adds the -Wno-deprecated-objc-isa-usage -Wno-format compiler flags to JSONKit.m file. Leave a comment if you’ve found this post useful (for any reason) :)