Skip to content

Commit 6cfcb20

Browse files
Initial commit
0 parents  commit 6cfcb20

13 files changed

Lines changed: 1465 additions & 0 deletions

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.DS_Store
2+
/.build
3+
/Packages
4+
xcuserdata/
5+
DerivedData/
6+
.swiftpm/configuration/registries.json
7+
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
8+
.netrc
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

Package.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// swift-tools-version: 5.9
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "ProgrammaticCoreData",
8+
platforms: [
9+
.macOS(.v14),
10+
.iOS(.v17)
11+
],
12+
products: [
13+
.library(
14+
name: "ProgrammaticCoreData",
15+
targets: ["ProgrammaticCoreData"]),
16+
],
17+
targets: [
18+
.target(
19+
name: "ProgrammaticCoreData"),
20+
.testTarget(
21+
name: "ProgrammaticCoreDataTests",
22+
dependencies: ["ProgrammaticCoreData"]),
23+
]
24+
)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Created by Axel Ancona Esselmann on 2/24/24.
2+
//
3+
4+
import Foundation
5+
6+
public enum CoreDataCreationError: Error {
7+
case storeDescriptionMissing
8+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// Created by Axel Ancona Esselmann on 2/24/24.
2+
//
3+
4+
import CoreData
5+
6+
public enum EntityDescriptionAttribute<CoreDataEntity, T> {
7+
case undefined(KeyPath<CoreDataEntity, T>)
8+
case integer16(KeyPath<CoreDataEntity, T>)
9+
case integer32(KeyPath<CoreDataEntity, T>)
10+
case integer64(KeyPath<CoreDataEntity, T>)
11+
case decimal(KeyPath<CoreDataEntity, T>)
12+
case double(KeyPath<CoreDataEntity, T>)
13+
case float(KeyPath<CoreDataEntity, T>)
14+
case string(KeyPath<CoreDataEntity, T>)
15+
case boolean(KeyPath<CoreDataEntity, T>)
16+
case date(KeyPath<CoreDataEntity, T>)
17+
case binaryData(KeyPath<CoreDataEntity, T>)
18+
case uuid(KeyPath<CoreDataEntity, T>)
19+
case uri(KeyPath<CoreDataEntity, T>)
20+
case transformable(KeyPath<CoreDataEntity, T>)
21+
case objectID(KeyPath<CoreDataEntity, T>)
22+
case composite(KeyPath<CoreDataEntity, T>)
23+
24+
public var attributeType: NSAttributeType {
25+
switch self {
26+
case .undefined:
27+
return .undefinedAttributeType
28+
case .integer16:
29+
return .integer16AttributeType
30+
case .integer32:
31+
return .integer32AttributeType
32+
case .integer64:
33+
return .integer64AttributeType
34+
case .decimal:
35+
return .decimalAttributeType
36+
case .double:
37+
return .doubleAttributeType
38+
case .float:
39+
return .floatAttributeType
40+
case .string:
41+
return .stringAttributeType
42+
case .boolean:
43+
return .booleanAttributeType
44+
case .date:
45+
return .dateAttributeType
46+
case .binaryData:
47+
return .binaryDataAttributeType
48+
case .uuid:
49+
return .UUIDAttributeType
50+
case .uri:
51+
return .URIAttributeType
52+
case .transformable:
53+
return .transformableAttributeType
54+
case .objectID:
55+
return .objectIDAttributeType
56+
case .composite:
57+
return .compositeAttributeType
58+
}
59+
}
60+
61+
public var keyPath: KeyPath<CoreDataEntity, T> {
62+
switch self {
63+
case
64+
.undefined(let keyPath),
65+
.integer16(let keyPath),
66+
.integer32(let keyPath),
67+
.integer64(let keyPath),
68+
.decimal(let keyPath),
69+
.double(let keyPath),
70+
.float(let keyPath),
71+
.string(let keyPath),
72+
.boolean(let keyPath),
73+
.date(let keyPath),
74+
.binaryData(let keyPath),
75+
.uuid(let keyPath),
76+
.uri(let keyPath),
77+
.transformable(let keyPath),
78+
.objectID(let keyPath),
79+
.composite(let keyPath):
80+
return keyPath
81+
}
82+
}
83+
84+
public var nsAttributeType: NSAttributeDescription {
85+
NSAttributeDescription(
86+
name: NSExpression(forKeyPath: keyPath).keyPath,
87+
type: attributeType,
88+
defaultValue: nil
89+
)
90+
}
91+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Created by Axel Ancona Esselmann on 2/24/24.
2+
//
3+
4+
import CoreData
5+
6+
public extension NSAttributeDescription {
7+
convenience init(name: String, type: NSAttributeType, defaultValue: Any? = nil) {
8+
self.init()
9+
self.name = name
10+
self.attributeType = type
11+
self.defaultValue = defaultValue
12+
}
13+
}

0 commit comments

Comments
 (0)