Skip to content
This repository has been archived by the owner on Mar 1, 2020. It is now read-only.

Add Swift 5 support #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
/.build/
/Packages/
.DS_Store
/querykit.xcodeproj/project.pbxproj
/querykit.xcodeproj/project.xcworkspace/contents.xcworkspacedata
/querykit.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
/querykit.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings
/querykit.xcodeproj/project.xcworkspace/xcuserdata/enzo.xcuserdatad/UserInterfaceState.xcuserstate
/querykit.xcodeproj/xcshareddata/xcschemes/querykit-Package.xcscheme
/querykit.xcodeproj/xcshareddata/xcschemes/querykitPackageDescription.xcscheme
/querykit.xcodeproj/xcuserdata/enzo.xcuserdatad/xcschemes/xcschememanagement.plist
43 changes: 43 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"object": {
"pins": [
{
"package": "Commander",
"repositoryURL": "https://github.com/kylef/Commander.git",
"state": {
"branch": null,
"revision": "e5b50ad7b2e91eeb828393e89b03577b16be7db9",
"version": "0.8.0"
}
},
{
"package": "PathKit",
"repositoryURL": "https://github.com/kylef/PathKit.git",
"state": {
"branch": null,
"revision": "e2f5be30e4c8f531c9c1e8765aa7b71c0a45d7a0",
"version": "0.9.2"
}
},
{
"package": "Spectre",
"repositoryURL": "https://github.com/kylef/Spectre.git",
"state": {
"branch": null,
"revision": "f14ff47f45642aa5703900980b014c2e9394b6e5",
"version": "0.9.0"
}
},
{
"package": "Stencil",
"repositoryURL": "https://github.com/kylef/Stencil.git",
"state": {
"branch": null,
"revision": "0e9a78d6584e3812cd9c09494d5c7b483e8f533c",
"version": "0.13.1"
}
}
]
},
"version": 1
}
19 changes: 13 additions & 6 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
// swift-tools-version:5.0
import PackageDescription


let package = Package(
name: "querykit",
dependencies: [
.Package(url: "https://github.com/kylef/Stencil.git", majorVersion: 0, minor: 9),
.Package(url: "https://github.com/kylef/Commander.git", majorVersion: 0, minor: 6),
]
name: "querykit",
dependencies: [
.package(url: "https://github.com/kylef/Stencil.git",from: "0.13.0"),
.package(url: "https://github.com/kylef/Commander.git", from: "0.8.0")
],
targets: [
.target(
name: "QueryKit",
dependencies: ["Stencil", "Commander"],
path: "Sources"
)
]
)
5 changes: 3 additions & 2 deletions Sources/QueryKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func compileCoreDataModel(_ source: Path) -> Path {
return destination
}

class AttributeDescription : NSObject {
struct AttributeDescription {
let name: String
let type: String

Expand Down Expand Up @@ -121,7 +121,7 @@ class CommandError : Error {
}

func render(entity: NSEntityDescription, destination: Path, template: Template) throws {
let attributes = entity.properties.flatMap { property -> AttributeDescription? in
let attributes = entity.properties.compactMap { property -> AttributeDescription? in
if entity.qk_hasSuperProperty(property.name) {
return nil
}
Expand All @@ -137,6 +137,7 @@ func render(entity: NSEntityDescription, destination: Path, template: Template)

let context: [String: Any] = [
"className": entity.qk_className,
"isAbstract": entity.isAbstract,
"attributes": attributes,
"entityName": entity.name ?? "Unknown",
]
Expand Down
4 changes: 3 additions & 1 deletion share/querykit/template.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import QueryKit
extension {{ className }} {{ "{" }}{% for attribute in attributes %}
static var {{ attribute.name }}:Attribute<{{ attribute.type }}> { return Attribute("{{ attribute.name }}") }{% endfor %}

class func queryset(context:NSManagedObjectContext) -> QuerySet<{{ className }}> {
{% if not isAbstract %}
@objc class func queryset(context:NSManagedObjectContext) -> QuerySet<{{ className }}> {
return QuerySet(context, "{{ entityName }}")
}
{% endif %}
}

extension Attribute where AttributeType: {{ className }} {{ "{" }}{% for attribute in attributes %}
Expand Down