Kodeco Forums

Core Graphics on OS X Tutorial

Core Graphics is Apple's 2D drawing engine for OS X. Discover how to build a great disc info app for OS X using Core Graphics to draw charts in this Core Graphics on OS X tutorial.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/1101-core-graphics-on-macos-tutorial

Unfortunately, I am unable to follow this tutorial as the sample code won’t compile on Xcode.
It wants to convert to swift 3.0 and after doing that there are nothing but errors.
If choosing not to convert - there are errors to. If choosing to remain at swift 2.3 syntax IBDesignables are not working. So regardless of what I do, I would need to install an older OS and use an older version of Xcode and I am not going to take this route…

It would be great if you could update your code files so that people would be able to follow along 1 year later.

Thanks for a possibly great tutorial :smiley:

‘1 year later’? This tutorial is three months old, and you’re using a beta of Xcode 8 (which uses Swift 2.3 or 3), not the current release version, Xcode 7.3 (which only supports up to Swift 2.2).

I’ll pass along the message that we should update tutorials like this when Swift 3 is finalised and Xcode 8 is released, though!

Great tutorial, thanks for writing it, Ernesto.

To help any readers who may be stuck as a result of running Xcode 8 - Beta 6, I’ve provided a few details on how to get the starter project for this tutorial working, with minimal changes (4, to be precise!).

1. Migrate to Swift 2.3

When using Xcode 8 - Beta 6 and migrating to Swift 2.3, which will take less than a minute to do.
Once done, the only changes made to the project are:

MountedVolumesDataSource.swift:53

self.outlineView.setDataSource(self)

becomes

self.outlineView.dataSource = self

And

MountedVolumesDelegate.swift:41

self.outlineView.setDelegate(self)

becomes

self.outlineView.delegate = self

2. Fix Interface Builder constraint errors

If you follow along, when you add the GraphView to the Main.storyboard file and configure the constraints to pin it on all sides, you’ll get an unsatisfiable constraints error in Interface Builder.
This can be resolved by simply by deleting the constant value (0) the ContainerView.top Equal HorizontalLine.Bottom constraint, allowing it to use some default value (provided by IB).

Unfortunately, @IBDesignable does not seem to be working properly in Xcode 8 - Beta 6, but as mentioned in the tutorial, you can simply run the application to see your changes.

3. Replace optional CGContextRef with a non-optional CGContextRef.

When following along and adding the Drawing Extension; simply change the
drawRoundedRect method signature to expect a non-optional CGContextRef parameter.

4. Update the call site to ensure a non-optional CGContextRef is passed

When following along and adding the drawBarGraphInContext method to the Drawing Extension; simply add a guard-let to the top of the method - to ensure that you call the drawRoundedRect method (mentioned above) with a valid CGContextRef instance, like so

    func drawBarGraphInContext(context: CGContextRef?) {
        guard let context = context else { return }
        ...
    }

With that, the tutorial source will work as expected.

Hope that helps.

– Mike.

Hi guys

Just letting you know that the tutorial has been updated to work with Xcode 8 and Swift 3.0!

cheers

This tutorial is more than six months old so questions are no longer supported at the moment for it. We will update it as soon as possible. Thank you! :]