Skip to content

Instantly share code, notes, and snippets.

@capttaco
capttaco / Protocol-Immutability.swift
Last active August 29, 2015 14:28
This was created to show an immutability error with swift properties declared in a protocol and access in a protocol extension
protocol Generator
{
typealias ObjectType: Generatable
var objects: [ObjectType] { get set }
mutating func objectForDeltaTime(seconds: CFTimeInterval) -> ObjectType?
}
extension Generator
{
@capttaco
capttaco / Fetchable.swift
Last active October 14, 2024 15:20
A utility protocol for custom NSManagedObjects that makes querying contexts simpler and more convenient. Requires Swift 2.
import CoreData
protocol Fetchable
{
typealias FetchableType: NSManagedObject
static func entityName() -> String
static func objectsInContext(context: NSManagedObjectContext, predicate: NSPredicate?, sortedBy: String?, ascending: Bool) throws -> [FetchableType]
static func singleObjectInContext(context: NSManagedObjectContext, predicate: NSPredicate?, sortedBy: String?, ascending: Bool) throws -> FetchableType?
static func objectCountInContext(context: NSManagedObjectContext, predicate: NSPredicate?) -> Int