Tom
Tom

Reputation: 3627

Using ios-charts in Swift for ios7+

I am trying to use this charting library which is a port of the same library I use for Android:

https://github.com/danielgindi/ios-charts

Since i use Swift targeting ios7+ I decided to follow this guide:

If you want to compile for iOS 7:

Drag the code itself (.swift files) to your project. As sadly, Swift currently does not support compiling Frameworks for iOS 7. Make sure that the files are added to the Target membership.

So I have done basicly placed a copy of the entire ios-charts folder in my project folder next to my own .swift files.

Then removed all units but .swift but keeping the file/directory structure. Interestingly, I can not change/add targets for any of the files in the folder since the option does not show itself when clicking the .swift files in xcode.

I then drop an UIView and change class to e.g. BarChartView.

I create an outlet so I have this in my class definition:

@IBOutlet weak var myStickChart: BarChartView!

However, I when building I am getting error

use of undeclared type "BarChartView

This is probably a simple problem, but this is the first 3rd party library I have to use.

I have experiemented with pods before, but decided against it - I would rather, for now as long as I am targeting ios7, be able to drag in he untts I want to use like descrived in the instructions for ios-charts with swift/ios7

enter image description here

Upvotes: 1

Views: 1200

Answers (3)

TheTiger
TheTiger

Reputation: 13354

Following steps worked for me:

  1. install via cocoapods by using pod 'Charts'
  2. Now if you will try to write anything related to charts it will not read that file or class and you will see the error like use of undeclared type xxxxx. So for this GoTo ⇾ Project Target ⇾ General ⇾ Linked Frameworks and Libraries ⇾ Click on + button and add Charts.framework.
  3. Go to your class where you want to use this. import Charts and now you will be able to use this framework without any error.

Upvotes: 0

Russell
Russell

Reputation: 5554

implementing this library for iOS 7 has it's own special challenges. The instructions advise you to Drag the code itself (.swift files) to your project - and when I did that at first I dragged over the top-level folder (like you would) but I couldn't get it to work.

Then I copied over each group of files individually - I put them all in the same folder Charts, but I guess you could recreate the folder structure.

Now I have a simple project working with Charts, iOS 7, and with no need for import

Just to be clear - here's how the file structure looks in my project - not very elegant, but it works. Chart files

Upvotes: 2

Russell
Russell

Reputation: 5554

@Tom - I use the same classes in one of my projects, and I installed it in exactly the same way as you do. I can generate the same errors that you're seeing - but only if I remove import Charts from my class definition.

Here's what the start of my class definition looks like

import UIKit
import Charts

class SharePriceGraphViewController: UIViewController, ChartViewDelegate
{
    var myStickChart: BarChartView!  // I don't really have this - added for this test :-)

as it stands, this compiles nicely. if I remove the import - I get the same error as you do.

Upvotes: 2

Related Questions