In the preceding example, and for most of this book, we focused on iOS-based playgrounds. However, macOS-based playgrounds are just as useful for the macOS platform and can also be used for UI testing and experimentation.
You will find a macOS-based playground called Simple_macOS.playground that also creates a simple bar chart view in this book's GitHub repository at https://github.com/PacktPublishing/Swift-Cookbook-Second-Edition/tree/master/Chapter07/01_Using_Swift_Playgrounds_for_UI
Alternatively, you can create a new macOS-based playground and enter the following code:
- Create a Color struct:
import PlaygroundSupport
import Cocoa
struct Color {
let red: CGFloat
let green: CGFloat
let blue: CGFloat
let alpha: CGFloat = 1.0
var displayColor: NSColor {
return NSColor(calibratedRed: red,
green: green,
blue: blue,
alpha: alpha)
}
}
- Create a ...