Search code examples
xcodehamcrest

How to add Hamcrest to XCODE?


I cannot find the actual hamcrest.framework - only the source code. What steps are to take to actually include into xcode ? I tried to compile the source code but do not get it connected to a new project I want to create.


Solution

  • It's actually quite easy. And there is a really great tutorial at Ray Wenderlich's web page ! So check out: http://www.raywenderlich.com/97014/use-cocoapods-with-swift

    1) Create an XCode Project (where you want to use Hamcrest)

    2) close Xcode

    3) Open Terminal-Window and goto path of Xcode Project File

    4) (if not already installed) install cocoapods: (this takes quite a while, so don't panic)

    sudo gem install cocoapods
    pod setup --verbose // for verbose output 
    pod init  // if it fails with error message you might not be in the correct path)
    

    5) Open Pod-File

    open -a Xcode Podfile
    

    6) Edit Pod-File

    platform :ios, "8.0"
    use_frameworks!
    

    7) integrate hamcrest as described in github (swifthamcrest)

    target 'HamcrestDemoTests' do  // name of your File
      pod 'SwiftHamcrest'
    end
    

    8) Safe File and start installation

    pod install
    

    9) Open your Project using the .xcworkspace file

    10) import Hamcrest in your TestSuite

    import XCTest
    import Hamcrest
    
    @testable import test
    
    class testTests: XCTestCase {
    

    Don't worry about initial errors that it cannot find the module. They will go away after first building the project.