Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View niczyja's full-sized avatar

Maciej Sienkiewicz niczyja

View GitHub Profile
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
@niczyja
niczyja / CGMutablePath+Shapes.swift
Last active May 25, 2021 14:49
Drawing shapes (arrow, point) using CGMutablePath. Based on: https://gist.github.com/mwermuth/07825df27ea28f5fc89a
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),
@niczyja
niczyja / UIButton+BackgroundColor.swift
Created September 1, 2021 07:25
UIKit extensions with additional @IBInspectable properties
import UIKit
extension UIButton {
@IBInspectable var disabledBackgroundColor: UIColor? {
get {
guard let image = image(for: .disabled) else { return nil }
return UIColor(patternImage: image)
}
set { setBackgroundColor(newValue, for: .disabled) }