Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
anconaesselmann committed Feb 29, 2024
0 parents commit 6cfcb20
Show file tree
Hide file tree
Showing 13 changed files with 1,465 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
/.build
/Packages
xcuserdata/
DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
24 changes: 24 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "ProgrammaticCoreData",
platforms: [
.macOS(.v14),
.iOS(.v17)
],
products: [
.library(
name: "ProgrammaticCoreData",
targets: ["ProgrammaticCoreData"]),
],
targets: [
.target(
name: "ProgrammaticCoreData"),
.testTarget(
name: "ProgrammaticCoreDataTests",
dependencies: ["ProgrammaticCoreData"]),
]
)
8 changes: 8 additions & 0 deletions Sources/ProgrammaticCoreData/CoreDataCreationError.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Created by Axel Ancona Esselmann on 2/24/24.
//

import Foundation

public enum CoreDataCreationError: Error {
case storeDescriptionMissing
}
91 changes: 91 additions & 0 deletions Sources/ProgrammaticCoreData/EntityDescriptionAttribute.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Created by Axel Ancona Esselmann on 2/24/24.
//

import CoreData

public enum EntityDescriptionAttribute<CoreDataEntity, T> {
case undefined(KeyPath<CoreDataEntity, T>)
case integer16(KeyPath<CoreDataEntity, T>)
case integer32(KeyPath<CoreDataEntity, T>)
case integer64(KeyPath<CoreDataEntity, T>)
case decimal(KeyPath<CoreDataEntity, T>)
case double(KeyPath<CoreDataEntity, T>)
case float(KeyPath<CoreDataEntity, T>)
case string(KeyPath<CoreDataEntity, T>)
case boolean(KeyPath<CoreDataEntity, T>)
case date(KeyPath<CoreDataEntity, T>)
case binaryData(KeyPath<CoreDataEntity, T>)
case uuid(KeyPath<CoreDataEntity, T>)
case uri(KeyPath<CoreDataEntity, T>)
case transformable(KeyPath<CoreDataEntity, T>)
case objectID(KeyPath<CoreDataEntity, T>)
case composite(KeyPath<CoreDataEntity, T>)

public var attributeType: NSAttributeType {
switch self {
case .undefined:
return .undefinedAttributeType
case .integer16:
return .integer16AttributeType
case .integer32:
return .integer32AttributeType
case .integer64:
return .integer64AttributeType
case .decimal:
return .decimalAttributeType
case .double:
return .doubleAttributeType
case .float:
return .floatAttributeType
case .string:
return .stringAttributeType
case .boolean:
return .booleanAttributeType
case .date:
return .dateAttributeType
case .binaryData:
return .binaryDataAttributeType
case .uuid:
return .UUIDAttributeType
case .uri:
return .URIAttributeType
case .transformable:
return .transformableAttributeType
case .objectID:
return .objectIDAttributeType
case .composite:
return .compositeAttributeType
}
}

public var keyPath: KeyPath<CoreDataEntity, T> {
switch self {
case
.undefined(let keyPath),
.integer16(let keyPath),
.integer32(let keyPath),
.integer64(let keyPath),
.decimal(let keyPath),
.double(let keyPath),
.float(let keyPath),
.string(let keyPath),
.boolean(let keyPath),
.date(let keyPath),
.binaryData(let keyPath),
.uuid(let keyPath),
.uri(let keyPath),
.transformable(let keyPath),
.objectID(let keyPath),
.composite(let keyPath):
return keyPath
}
}

public var nsAttributeType: NSAttributeDescription {
NSAttributeDescription(
name: NSExpression(forKeyPath: keyPath).keyPath,
type: attributeType,
defaultValue: nil
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Created by Axel Ancona Esselmann on 2/24/24.
//

import CoreData

public extension NSAttributeDescription {
convenience init(name: String, type: NSAttributeType, defaultValue: Any? = nil) {
self.init()
self.name = name
self.attributeType = type
self.defaultValue = defaultValue
}
}
Loading

0 comments on commit 6cfcb20

Please sign in to comment.