Skip to content

Instantly share code, notes, and snippets.

View CGPath+Arrow.swift
extension CGMutablePath {
func addArrow(to point: CGPoint, tailWidth: CGFloat = 4.0, headWidth: CGFloat = 10.0, headLength: CGFloat = 14.0) {
let length = hypot(point.x - currentPoint.x, point.y - currentPoint.y)
let tailLength = length - headLength
let points: [CGPoint] = [
CGPoint(x: 0.0, y: tailWidth / 2),
CGPoint(x: tailLength, y: tailWidth / 2),
CGPoint(x: tailLength, y: headWidth / 2),
View StoreMigration.swift
lazy var persistentContainer: NSPersistentContainer = {
let container = NSPersistentContainer(name: "app container name")
guard let fileContainer = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "your group.app.identifier") else {
fatalError("Shared file container could not be created.")
}
let groupStoreUrl = fileContainer.appendingPathComponent("app container name.sqlite")
let hasOldStore = FileManager.default.fileExists(atPath: container.persistentStoreDescriptions.first?.url?.path ?? "")
let needsMigration = hasOldStore && container.persistentStoreDescriptions.first?.url?.absoluteString != groupStoreUrl.absoluteString