Skip to content

Commit

Permalink
Add Swift 5.7 support
Browse files Browse the repository at this point in the history
  • Loading branch information
ffried committed Sep 14, 2022
1 parent 9cb98c6 commit 6ed5dd2
Show file tree
Hide file tree
Showing 19 changed files with 176 additions and 80 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- uses: swift-actions/[email protected]
id: swift-setup
with:
swift-version: '5.6'
swift-version: '5.7'
- name: Read OS Version
uses: sersoft-gmbh/[email protected]
id: os-version
Expand All @@ -59,15 +59,15 @@ jobs:
needs:
- release-context
- spm-context
runs-on: macos-latest
runs-on: macos-12
strategy:
matrix:
target: ${{fromJson(needs.spm-context.outputs.package-dump).products.*.targets.*}}
steps:
- uses: swift-actions/[email protected]
id: swift-setup
with:
swift-version: '5.6'
swift-version: '5.7'
- name: Read OS Version
uses: sersoft-gmbh/[email protected]
id: os-version
Expand Down
46 changes: 27 additions & 19 deletions .github/workflows/swift-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,33 @@ jobs:
test-spm:
strategy:
matrix:
os: [ macos-latest ]
swift-version: [ 5.5, 5.6 ]
os: [ macos-11 ]
swift-version: [ '' ]
xcode-version: [ '^13.0' ]
include:
- os: macos-12
swift-version: ''
xcode-version: '^14.0'
# - os: ubuntu-20.04
# swift-version: 5.5
# xcode-version: ''
# - os: ubuntu-20.04
# swift-version: 5.6
# xcode-version: ''
# - os: ubuntu-20.04
# swift-version: 5.7
# xcode-version: ''
# - os: ubuntu-22.04
# swift-version: 5.7
# xcode-version: ''

runs-on: ${{matrix.os}}

steps:
- if: runner.os == 'macOS'
uses: maxim-lobanov/[email protected]
with:
xcode-version: ^13.0
xcode-version: ${{matrix.xcode-version}}
- name: Install Swift
if: runner.os == 'Linux'
uses: sersoft-gmbh/[email protected]
Expand Down Expand Up @@ -55,44 +72,35 @@ jobs:
fail_ci_if_error: true

test-xcode:
runs-on: macos-latest
runs-on: macos-12
strategy:
matrix:
action: [ test ]
destination:
- platform=macOS
- platform=iOS Simulator,OS=latest,name=iPhone 12 Pro
- platform=iOS Simulator,OS=latest,name=iPad Pro (11-inch) (2nd generation)
- platform=tvOS Simulator,OS=latest,name=Apple TV 4K
# Watch currently doesn't work because there's no XCTest on watchOS
# include:
# - action: build
# destination: platform=watchOS Simulator,OS=latest,name=Apple Watch Series 6 - 44mm
- platform=iOS Simulator,OS=latest,name=iPhone 13 Pro
- platform=iOS Simulator,OS=latest,name=iPad Pro (11-inch) (3rd generation)
- platform=tvOS Simulator,OS=latest,name=Apple TV 4K (2nd generation)
- platform=watchOS Simulator,OS=latest,name=Apple Watch Series 7 (45mm)
steps:
- uses: maxim-lobanov/[email protected]
with:
xcode-version: ^13.0
xcode-version: ^14.0
- name: Read Swift Version
uses: sersoft-gmbh/[email protected]
id: swift-version
- uses: actions/checkout@v3
- name: Workaround Package.resolved format issues
if: ${{ startsWith(steps.swift-version.outputs.version, '5.5') }}
run: rm -rf Package.resolved
- uses: sersoft-gmbh/[email protected]
with:
spm-package: './'
scheme: FFCoreData
destination: ${{matrix.destination}}
action: ${{matrix.action}}
action: test
parallel-testing-enabled: true
enable-code-coverage: true
- uses: sersoft-gmbh/[email protected]
id: coverage-files
if: matrix.action == 'test'
- uses: codecov/codecov-action@v3
with:
token: ${{secrets.CODECOV_TOKEN}}
files: ${{join(fromJSON(steps.coverage-files.outputs.files), ',')}}
fail_ci_if_error: true
if: matrix.action == 'test'
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/ffried/FFFoundation.git",
"state" : {
"revision" : "f01c25f484ed31220ae0dbb9972d93a07db8e763",
"version" : "9.4.0"
"revision" : "ccc1998e5bfb75d20eb51d120765d334459baba4",
"version" : "9.5.0"
}
}
],
Expand Down
11 changes: 6 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.6
// swift-tools-version:5.7
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand All @@ -7,14 +7,15 @@ import Foundation
let package = Package(
name: "FFCoreData",
platforms: [
.iOS(.v10),
.macOS(.v10_12),
.iOS(.v11),
.macOS(.v10_13),
.watchOS(.v4),
.tvOS(.v10),
.tvOS(.v11),
],
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(name: "FFCoreData", targets: ["FFCoreData"]),
.library(name: "FFCoreData",
targets: ["FFCoreData"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
Expand Down
40 changes: 40 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// swift-tools-version:5.6
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
import Foundation

let package = Package(
name: "FFCoreData",
platforms: [
.iOS(.v10),
.macOS(.v10_12),
.watchOS(.v4),
.tvOS(.v10),
],
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(name: "FFCoreData", targets: ["FFCoreData"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/ffried/FFFoundation.git", from: "9.0.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "FFCoreData",
dependencies: [
.product(name: "FFFoundation", package: "FFFoundation"),
]),
.testTarget(
name: "FFCoreDataTests",
dependencies: ["FFCoreData"],
resources: [.process("Models/TestModel.xcdatamodeld")]),
]
)

if ProcessInfo.processInfo.environment["ENABLE_DOCC_SUPPORT"] == "1" {
package.dependencies.append(.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"))
}
11 changes: 4 additions & 7 deletions Sources/FFCoreData/CoreDataManager/CoreDataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,10 @@ public enum CoreDataStack {

extension CoreDataStack {
public struct Configuration {
private static let infoDictionarySQLiteNameKey = "FFCDDataManagerSQLiteName"
private static let infoDictionaryModelNameKey = "FFCDDataManagerModelName"

fileprivate static let legacyConfiguration: Configuration = {
let bundle = Bundle.main
let modelName = bundle.infoDictionary?[Configuration.infoDictionaryModelNameKey] as? String
let sqliteName = bundle.infoDictionary?[Configuration.infoDictionarySQLiteNameKey] as? String
let modelName = bundle.infoDictionary?["FFCDDataManagerModelName"] as? String
let sqliteName = bundle.infoDictionary?["FFCDDataManagerSQLiteName"] as? String
return Configuration(bundle: bundle, modelName: modelName, sqliteName: sqliteName)
}()

Expand Down Expand Up @@ -367,6 +364,6 @@ extension CoreDataStack {
extension CoreDataStack.Configuration.Options {
public static var `default`: CoreDataStack.Configuration.Options { .removeNamespacesFromEntityNames }

public static let removeNamespacesFromEntityNames: CoreDataStack.Configuration.Options = .init(rawValue: 1 << 0)
public static let clearDataStoreOnSetupFailure: CoreDataStack.Configuration.Options = .init(rawValue: 1 << 1)
public static let removeNamespacesFromEntityNames = CoreDataStack.Configuration.Options(rawValue: 1 << 0)
public static let clearDataStoreOnSetupFailure = CoreDataStack.Configuration.Options(rawValue: 1 << 1)
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ public final class MOCBlockObserver<Filter: MOCObserverFilter> {
notificationCenter.addObserver(forName: .NSManagedObjectContextObjectsDidChange, object: $0, queue: workerQueue, using: observerBlock)
}
} else {
observers = [notificationCenter.addObserver(forName: .NSManagedObjectContextObjectsDidChange, object: nil, queue: workerQueue, using: observerBlock)]
observers = [
notificationCenter.addObserver(forName: .NSManagedObjectContextObjectsDidChange, object: nil, queue: workerQueue, using: observerBlock)
]
}
if fireInitially {
fire(with: .init())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ import class CoreData.NSManagedObject
import class CoreData.NSManagedObjectContext

public struct MOCEntitiesFilter: MOCObserverFilter {
public var entityNames: [String]
public var entityNames: Array<String>

public init(entityNames: [String]) {
public init(entityNames: Array<String>) {
self.entityNames = entityNames
}

public init(entities: [NSEntityDescription]) {
public init(entities: Array<NSEntityDescription>) {
self.init(entityNames: entities.map { $0.name ?? $0.managedObjectClassName })
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,18 @@ import func FFFoundation.os_log
#endif

public struct MOCObjectsFilter: MOCObserverFilter {
var objectIDs: [NSManagedObjectID] {
var objectIDs: Array<NSManagedObjectID> {
didSet {
precondition(!objectIDs.contains(where: \.isTemporaryID),
"FFCoreData: ERROR: Temporary NSManagedObjectIDs set on MOCObjectsObserver! Be sure to only use non-temporary IDs for MOCObservers!")
}
}

private var objectIDURIs: [URL] { objectIDs.map { $0.uriRepresentation() } }
private var objectIDURIs: Array<URL> {
objectIDs.map { $0.uriRepresentation() }
}

public init(objectIDs: [NSManagedObjectID]) {
public init(objectIDs: Array<NSManagedObjectID>) {
self.objectIDs = objectIDs
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ public enum MOCObservationMode {
}

public struct MOCObservedChanges {
public private(set) var inserted: [NSManagedObjectID] = []
public private(set) var updated: [NSManagedObjectID] = []
public private(set) var deleted: [NSManagedObjectID] = []
public private(set) var inserted: Array<NSManagedObjectID> = []
public private(set) var updated: Array<NSManagedObjectID> = []
public private(set) var deleted: Array<NSManagedObjectID> = []
}

extension MOCObservedChanges {
fileprivate init(readingFrom changes: [AnyHashable: Any], filteringWith filter: (NSManagedObject) throws -> Bool) rethrows {
fileprivate init(readingFrom changes: Dictionary<AnyHashable, Any>, filteringWith filter: (NSManagedObject) throws -> Bool) rethrows {
try changes.map(keysToKeyPaths: [(NSInsertedObjectsKey, \.inserted), (NSUpdatedObjectsKey, \.updated), (NSDeletedObjectsKey, \.deleted)],
to: &self,
transformingValuesTo: Set<NSManagedObject>.self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import func FFFoundation.os_log
@objc public protocol FetchedResultsControllerManagerDelegate: NSFetchedResultsControllerDelegate {}

public class FetchedResultsControllerManager<Result: NSFetchRequestResult>: NSObject, NSFetchedResultsControllerDelegate {

public typealias Controller = NSFetchedResultsController<Result>
public typealias Delegate = FetchedResultsControllerManagerDelegate

Expand Down Expand Up @@ -81,7 +80,11 @@ public class FetchedResultsControllerManager<Result: NSFetchRequestResult>: NSOb
}

@objc(controller:didChangeObject:atIndexPath:forChangeType:newIndexPath:)
public dynamic func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange anObject: Any, at indexPath: IndexPath?, for type: NSFetchedResultsChangeType, newIndexPath: IndexPath?) {
public dynamic func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>,
didChange anObject: Any,
at indexPath: IndexPath?,
for type: NSFetchedResultsChangeType,
newIndexPath: IndexPath?) {
switch type {
case .insert: insertSubobject(at: newIndexPath!)
case .update: updateSubobject(at: indexPath!)
Expand All @@ -97,7 +100,8 @@ public class FetchedResultsControllerManager<Result: NSFetchRequestResult>: NSOb
delegate?.controllerDidChangeContent?(controller)
}

@objc public dynamic func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, sectionIndexTitleForSectionName sectionName: String) -> String? {
@objc public dynamic func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>,
sectionIndexTitleForSectionName sectionName: String) -> String? {
delegate?.controller?(controller, sectionIndexTitleForSectionName: sectionName) ?? controller.sectionIndexTitle(forSectionName: sectionName)
}
}
14 changes: 14 additions & 0 deletions Sources/FFCoreData/NSManagedObject/CoreDataDecodable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@

import CoreData

#if compiler(>=5.7)
public protocol CoreDataDecodable<DTO>: Decodable {
associatedtype DTO: Decodable

@discardableResult
static func findOrCreate(for dto: DTO, in context: NSManagedObjectContext) throws -> Self

init(with dto: DTO, in context: NSManagedObjectContext) throws

mutating func update(from dto: DTO) throws
}
#else
public protocol CoreDataDecodable: Decodable {
associatedtype DTO: Decodable

Expand All @@ -30,6 +42,7 @@ public protocol CoreDataDecodable: Decodable {

mutating func update(from dto: DTO) throws
}
#endif

extension CoreDataDecodable {
public init(from decoder: Decoder) throws {
Expand Down Expand Up @@ -76,6 +89,7 @@ public enum CoreDataDecodingError: Error, CustomStringConvertible {

extension Thread {
private static let decodingContextThreadKey = "net.ffried.FFCoreData.DecodingContext"

fileprivate var decodingContext: Unmanaged<NSManagedObjectContext>? {
get { threadDictionary[Thread.decodingContextThreadKey] as? Unmanaged<NSManagedObjectContext> }
set { threadDictionary[Thread.decodingContextThreadKey] = newValue }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public struct FetchableFilterExpression<Model: Fetchable> {
let predicate: NSPredicate

@usableFromInline
init(predicate: NSPredicate) { self.predicate = predicate }
init(predicate: NSPredicate) {
self.predicate = predicate
}
}

// MARK: - Equatable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public struct FetchableSortExpression<Model: Fetchable> {
let sortDescriptor: NSSortDescriptor

@usableFromInline
init(sortDescriptor: NSSortDescriptor) { self.sortDescriptor = sortDescriptor }
init(sortDescriptor: NSSortDescriptor) {
self.sortDescriptor = sortDescriptor
}
}

public prefix func ^ <Model, Value: Comparable>(rhs: KeyPath<Model, Value>) -> FetchableSortExpression<Model> {
Expand Down
4 changes: 3 additions & 1 deletion Sources/FFCoreData/NSManagedObject/KeyObjectDictionary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ public struct KeyObjectDictionaryExpression<Model: Entity> {
let dict: KeyObjectDictionary

@usableFromInline
init(dict: KeyObjectDictionary) { self.dict = dict }
init(dict: KeyObjectDictionary) {
self.dict = dict
}
}

extension KeyObjectDictionaryExpression where Model: Fetchable {
Expand Down
Loading

0 comments on commit 6ed5dd2

Please sign in to comment.