1

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

5
  • maybe a silly question - but you have include ios-charts in your class definition? Commented Mar 3, 2016 at 17:41
  • I have expanded my question now - if that was no wha you meant, could you post an example? (I have included all the .swift files in my ios7+ swift project and associated them to all my targets) Commented Mar 3, 2016 at 22:56
  • according to the github link you provide, you need to include @import Charts in your swift class file Commented Mar 3, 2016 at 23:12
  • When installed that way yes, but I use the ios7 compatible mehod "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." Commented Mar 3, 2016 at 23:18
  • well, I managed to get it working for iOS 7 - but it's a bit tedious. I will add a new answer to demonstrate ... Commented Mar 4, 2016 at 17:59

3 Answers 3

2

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

Sign up to request clarification or add additional context in comments.

Comments

2

@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.

3 Comments

If I add "import Charts" I get "No such module 'Charts' - but I also read the iso-charts instructions such as if installing for iso7/swift (as opposed to ios8+) ignore the normal install instructions and drag in the .swift the files like I described in my original post. Hence I have not dragged in / added any "charts" project since that's not the ios-charts instructions? But maybe I am wrong, if so, I find it quite confusing... (Good for SO then)
Did you as me also only add the .swift files or did you start with "Drag the Charts.xcodeproj to your project. Go to your target's settings, hit the "+" under the "Embedded Binaries" section, and select the Charts.framework" - if so, does your project work with ios7?
I'm not sure if it will work on ios7. When I try, it fails, but because of the other frameworks I have in that project. I will try to create a simple version, but it will be later tonight (UK time)
0

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.

1 Comment

Yes, but frameworks don't work in iOS 7 the way Charts uses them, so that method doesn't work in iOS 7. See github.com/danielgindi/Charts/tree/v2.2.5#usage ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.