Friday 17 October 2014

RestKit install - RKValueTransformers file not found


Adding the RestKit framework to an Xcode project manually, i.e. without using CocoaPods, results in project build errors similar to these:

Compile RKEntityMapping.m
'RKValueTransformers.h' file not found
  In file included from /.../RestKit-0.23.3/Code/CoreData/RKEntityMapping.m:21
  In file included from /.../RestKit-0.23.3/Code/CoreData/RKEntityMapping.h:22

Compile RKManagedObjectImporter.m
'RKValueTransformers.h' file not found
  In file included from /.../RestKit-0.23.3/Code/CoreData/RKManagedObjectImporter.m:26
0.23.3/Code/CoreData/RKMapperOperation.h:22

Up to and including version 0.20.3, adding the RestKit framework downloaded as a source zip file from GitHub required a few simple steps (todo: link) and worked easily on several projects.

Following the same procedure to add version 0.23.3 resulted in the errors shown above. 

Both files, i.e. RKValueTransformers.h and RKValueTransformers.m, are still referenced from the RestKit.xcodeproj but are not bundled into the zipped source.

It turns out that beginning with version 0.22.0, these 2 files were extracted from RestKit project into its own project on GitHub: https://github.com/RestKit/RKValueTransformers
The project needs to be downloaded separately (i.e. when not using CocoaPods for installation).
The two files can be simply copied into this directory under the RestKit:

RestKit-0.23.3/Vendor/RKValueTransformers

Unfortunately, that does not solve the whole problem. Apparently, packaging of the source code was changed and no longer includes dependencies such as AFNetworking, SOCKit and others.
So, if you persist in your stubbornness (as does this author) and still prefer to integrate RestKit into your project without CocoaPods, you're facing a very daunting option: download all dependencies manually and add them to the sub-directories inside the RestKit-0.23.3/Vendor.

Luckily, there is a faster way (only takes few minutes): the trick is to use CocoaPods to bring all dependencies into a helper project and then simply copy files into the target .

  • create a new simple project in Xcode. The template does not matter, Single View Application is fine. Project name just for example: RestKitPodsInstall
  • install CocoaPods (if the Mac does not have the package already):
    sudo gem install cocoapods
  • cd into the project directory, i.e. the directory that contains the Xcode project file (e.g. RestKitPodInstall.xcodeproj)
  • create a Podfile:
vi Podfile

platform :ios, '5.0'
pod 'RestKit', '~> 0.23.3'

(change the version to the latest available or whatever is needed)

  • install RestKit into the helper project by running:
pod --verbose install

It should finish with something like this:

Integrating client project

[!] From now on use `RestKitPodInstall.xcworkspace`.

Integrating target `Pods` (`RestKitPodInstall.xcodeproj` project)
  • copy, one by one, content of sub-directories in the Pods directory of the helper project to the target project. Keep in mind that the RestKit source already has placeholder directories for dependencies under the Vendor subfolder. The example below assumes that a manually downloaded RestKit-0.23.3 source code was placed under the Library directory in the target project named Algonquin. The current directory is the project directory of the helper project. (Also note the / at the end of the copied source directory)
mac:RestKitPodInstall vit$ cp -R Pods/AFNetworking/ /Users/vit/iOS-Projects/Algonquin/Algonquin/Library/RestKit-0.23.3/Vendor/AFNetworking

mac:RestKitPodInstall vit$ cp -R Pods/ISO8601DateFormatterValueTransformer/ /Users/vit/iOS-Projects/Algonquin/Algonquin/Library/RestKit-0.23.3/Vendor/ISO8601DateFormatterValueTransformer

mac:RestKitPodInstall vit$ cp -R Pods/RKValueTransformers/ /Users/vit/iOS-Projects/Algonquin/Algonquin/Library/RestKit-0.23.3/Vendor/RKValueTransformers

mac:RestKitPodInstall vit$ cp -R Pods/SOCKit/ /Users/vit/iOS-Projects/Algonquin/Algonquin/Library/RestKit-0.23.3/Vendor/SOCKit

mac:RestKitPodInstall vit$ cp -R Pods/TransitionKit/ /Users/vit/iOS-Projects/Algonquin/Algonquin/Library/RestKit-0.23.3/Vendor/TransitionKit

After all copying is done, the target project should have the structure similar to this:

Algonquin (it's the target project)
| Algonquin
| | main.m
| | VTAppDelegate.h
| | (other source files)
| | Library
| | | RestKit-0.23.3
| | | | RestKit.xcodeproj
| | | | Code
| | | | Resources
| | | | (other files)
| | | | Vendor
| | | | | AFNetworking
| | | | | | AFNetworking
| | | | | | | AFHTTPClient.h
| | | | | | | AFHTTPClient.m
| | | | | | | (other source files)
| | | | | | LICENCE
| | | | | | README.md
| | | | | RKValueTransformers
| | | | | | Code
| | | | | | | RKValueTransformers.h
| | | | | | | RKValueTransformers.m
| | | | | | LICENSE
| | | | | | README.md
| | | | | (rest of dependencies)
| | | (other libraries)
| Algonquin.xcodeproj
| AlgonquinTests


The target project should not be opened in Xcode during this procedure. When the copying complete, open the target project in Xcode. The project should compile without failures (assuming of course that RestKit was already previously configured and that is just a replacement to a newer version).