Saturday, 3 January 2015

learn swift cocoapods step by step ..


1. run: sudo gem install cocoapods





2. create a  xcode project, with swift, then close xcode

3. open command line and redirect to the folder of your new project, then run this:

1
2
3
4
5
6
7
8
9
10
11
$ cd /Users/xxx/Documents/xcode/chartdemo
$ pod init

4. add a library into your dependencies file by run this in command line:

1
2
3
4
5
6
7
8
9
10
11
$ echo "pod 'JBChartView'" >> Podfile


5. usually you can run this:

1
2
3
4
5
6
7
8
9
10
11
$ pod install


However, because this is your first time to use pod, you should setup pod first, otherwise you will have error:

/Library/Ruby/Gems/2.0.0/gems/cocoapods-0.35.0/lib/cocoapods/user_interface/error_report.rb:103: warning: Insecure world writable dir /usr/local in PATH, mode 040777
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/pathname.rb:422:in `open': No such file or directory - /Users/CravenJM/.cocoapods/repos (Errno::ENOENT)
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/pathname.rb:422:in `foreach'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/pathname.rb:422:in `children'
    from /Library/Ruby/Gems/2.0.0/gems/cocoapods-0.35.0/lib/cocoapods/sources_manager.rb:63:in `all'
    from /Library/Ruby/Gems/2.0.0/gems/cocoapods-0.35.0/lib/cocoapods/user_interface/error_report.rb:130:in `repo_information'
    from /Library/Ruby/Gems/2.0.0/gems/cocoapods-0.35.0/lib/cocoapods/user_interface/error_report.rb:34:in `report'
    from /Library/Ruby/Gems/2.0.0/gems/cocoapods-0.35.0/lib/cocoapods/command.rb:58:in `report_error'
    from /Library/Ruby/Gems/2.0.0/gems/claide-0.7.0/lib/claide/command.rb:300:in `handle_exception'
    from /Library/Ruby/Gems/2.0.0/gems/claide-0.7.0/lib/claide/command.rb:274:in `rescue in run'
    from /Library/Ruby/Gems/2.0.0/gems/claide-0.7.0/lib/claide/command.rb:264:in `run'
    from /Library/Ruby/Gems/2.0.0/gems/cocoapods-0.35.0/lib/cocoapods/command.rb:45:in `run'
    from /Library/Ruby/Gems/2.0.0/gems/cocoapods-0.35.0/bin/pod:43:in `<top (required)>'
    from /usr/bin/pod:23:in `load'
    from /usr/bin/pod:23:in `<main>'



The solution is running this command  "pod setup"

6. open the .xcworkspace file by double click the file.

7. add a bridge header file.  about bridge header file : https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html#//apple_ref/doc/uid/TP40014216-CH10-XID_77

 I spent whole day to fix this issue because i was following http://www.digistarters.com/swift-charting-library-jbchartview/. this post ask me to manually create a header file.

I finally found this : https://www.youtube.com/watch?v=yfkX-p5kW4U, the bridge file will be created automatically and we don't need change any settings.

























No comments:

Post a comment