Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I use this library from another project? #24

Closed
mbifulco opened this issue Jan 24, 2015 · 11 comments
Closed

How can I use this library from another project? #24

mbifulco opened this issue Jan 24, 2015 · 11 comments

Comments

@mbifulco
Copy link

A bit of a noob question, but I'm looking to use the PNChart-Swift library in a swift project I'm working on. Is there a trick to using is as a framework, or referencing it from an external project?

@vlafiser
Copy link

vlafiser commented Mar 6, 2015

Yop, I have the same question. Is it possible without Pod install?

@mbifulco
Copy link
Author

mbifulco commented Mar 6, 2015

In the end I went with the Pod install, plus a bridging header. It seems to work okay for me so far!

@vlafiser
Copy link

vlafiser commented Mar 6, 2015

Can you share it for me please? (of course, some example) Thank you so much man! :)

@mbifulco
Copy link
Author

mbifulco commented Mar 6, 2015

Ah man I'm sorry, my reply was slightly incorrect - so I ended up using a Podfile that references the original PNChart repo, not the swift one. As far as I can tell, there's no Pod available for the swift library, which might actually be because CocoaPods don't yet allow you to add Swift projects to your workspace. I'm not sure.

Anyway, what I did was add the non swift library - this is what I had to do:

There's not much to it, really - two major things are getting the podfile right and installing pods, and then setting up the Bridging header to the Objective-C libaries.

Your podfile should look something like this (for IOS8, of course)

image

Once you've got the PNChart project added to your workspace from installing the pods, you'll need a bridging header in your project. This lets Swift interact with the Objective-C classes in the PNChart project.

You can read more about bridging headers here: https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html (look for subsection Importing Objective-C into Swift)

Enable your bridging header in your project settings:
image

To get the charts to work, your bridging header should have these lines in it:

image

Basically, from there, your project should have access to anything you want in PNCharts. On the ViewControllers where you use charts, you'll need to import a reference to the PNCharts library:

image

From there, everything should be according to the documentation in the PNCharts repo's readme (And their sample projects).

@vlafiser
Copy link

vlafiser commented Mar 6, 2015

Wau, THANK YOU for help! I will try it to do this evening. :)

Thank you Mike!!

@vlafiser
Copy link

vlafiser commented Mar 6, 2015

Still not working for me. :/

I mean I wrote something bad. If I paste the Obj-C code from example to viewDidLoad function, will work? For me not working. (I know, is it Obj-C, but the bridging know work with it...?)

@mbifulco
Copy link
Author

mbifulco commented Mar 7, 2015

Hi @vlafiser - so you're not going to be able to write Obj-C code. You'll need to translate it to Swift, essentially, which can be a bit of a pain, but is a great learning experience.

For example, my ViewDidLoad() code looks like this for the ViewController in question:

image

image

@m-t-space
Copy link

@mbifulco are these directions for JBCharts (https://github.com/Jawbone/JBChartView) or PNCharts?
your examples seem to all reference the JBCharts names...
Or are they that related that the code would be identical?
I'm attempting to set up a new Swift project with this library but am finding it frustrating and confusing. Could anyone lay this out a bit more clearly?

@mbifulco
Copy link
Author

Wow, yeah, I'm all over the map. Sorry... disregard me completely. I did switch to JB at some point. Sorry @m-t-space and @vlafiser

@mbifulco
Copy link
Author

Went back and tried to put together an example using PNChart earlier, and even with a blank Swift project, I'm having trouble getting the cocoapod to connect to my project through the bridging header and compile happily. I'll play with it a bit more this weekend and let you know if I can get it going (and share my code).

@iamprem
Copy link

iamprem commented Apr 13, 2015

Hey @mbifulco , Any good?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants