First, we'll create an iOS-based playground to build our bar chart. In Chapter 1, Swift Building Blocks, we went through creating a new playground, so return there if you need a refresher.
We will create a custom view that will display information in bar chart form, and use that to test some features of playgrounds. You can either enter the following code into a new iOS-based playground or download the playground named Simple_iOS.playground from this book's GitHub repository:
- Create a Color struct:
import UIKit
struct Color {
let red: Float
let green: Float
let blue: Float
let alpha: Float = 1.0
var displayColor: UIColor {
return UIColor(red: CGFloat(red),
green: CGFloat(green),
blue: CGFloat(blue),
alpha: CGFloat(alpha))
}
}
- Create a Bar struct and BarView:
struct Bar {
var value: Float
var color: Color
}
class BarView: UIView {
init(frame: CGRect,...