-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6cfcb20
Showing
13 changed files
with
1,465 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
8 changes: 8 additions & 0 deletions
8
.swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]), | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
91
Sources/ProgrammaticCoreData/EntityDescriptionAttribute.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
Sources/ProgrammaticCoreData/NSAttributeDescription+Extensions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
Oops, something went wrong.