Skip to content

Commit

Permalink
Update project
Browse files Browse the repository at this point in the history
  • Loading branch information
3lvis committed Oct 4, 2020
1 parent 9aa7bf1 commit f5ef190
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@import CoreData;

#import "PropertyMapper.h"
#import <Sync/PropertyMapper.h>

/**
Internal helpers, not meant to be included in the public APIs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,7 @@ - (id)valueForAttributeDescription:(NSAttributeDescription *)attributeDescriptio
} else if (stringValueAndURIAttribute) {
value = [[NSURL alloc] initWithString:remoteValue];
} else if (dataAttribute) {
if (@available(iOS 11.0, tvOS 11.0, watchOS 4.0, *)) {
value = [NSKeyedArchiver archivedDataWithRootObject:remoteValue requiringSecureCoding:false error:nil];
} else {
value = [NSKeyedArchiver archivedDataWithRootObject:remoteValue];
}
value = [NSKeyedArchiver archivedDataWithRootObject:remoteValue requiringSecureCoding:false error:nil];
} else if (numberValueAndDecimalAttribute) {
NSNumber *number = (NSNumber *)remoteValue;
value = [NSDecimalNumber decimalNumberWithDecimal:[number decimalValue]];
Expand Down
6 changes: 3 additions & 3 deletions Source/PropertyMapper/PropertyMapper.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
@import CoreData;
@import Foundation;

#import "NSDate+PropertyMapper.h"
#import "NSEntityDescription+PrimaryKey.h"
#import "Inflections.h"
#import <Sync/NSDate+PropertyMapper.h>
#import <Sync/NSEntityDescription+PrimaryKey.h>
#import <Sync/Inflections.h>

FOUNDATION_EXPORT double PropertyMapperVersionNumber;
FOUNDATION_EXPORT const unsigned char PropertyMapperVersionString[];
Expand Down
8 changes: 4 additions & 4 deletions Source/Sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ FOUNDATION_EXPORT double SyncVersionNumber;

FOUNDATION_EXPORT const unsigned char SyncVersionString[];

#import "PropertyMapper.h"
#import "NSEntityDescription+PrimaryKey.h"
#import "NSManagedObject+PropertyMapperHelpers.h"
#import "NSPropertyDescription+Sync.h"
#import <Sync/PropertyMapper.h>
#import <Sync/NSEntityDescription+PrimaryKey.h>
#import <Sync/NSManagedObject+PropertyMapperHelpers.h>
#import <Sync/NSPropertyDescription+Sync.h>
9 changes: 0 additions & 9 deletions Source/Sync/Sync+NSPersistentContainer.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import CoreData

@available(iOS 10, watchOS 3, tvOS 10, OSX 10.12, *)
public extension NSPersistentContainer {
/**
Syncs the entity using the received array of dictionaries, maps one-to-many, many-to-many and one-to-one relationships.
Expand All @@ -11,7 +10,6 @@ public extension NSPersistentContainer {
- parameter entityName: The name of the entity to be synced.
- parameter completion: The completion block, it returns an error if something in the Sync process goes wrong.
*/
@available(iOS 10, watchOS 3, tvOS 10, OSX 10.12, *)
func sync(_ changes: [[String: Any]], inEntityNamed entityName: String, completion: ((_ error: NSError?) -> Void)?) {
self.sync(changes, inEntityNamed: entityName, predicate: nil, parent: nil, parentRelationship: nil, operations: .all, completion: completion)
}
Expand All @@ -27,7 +25,6 @@ public extension NSPersistentContainer {
account in the Sync process, you just need to provide this predicate.
- parameter completion: The completion block, it returns an error if something in the Sync process goes wrong.
*/
@available(iOS 10, watchOS 3, tvOS 10, OSX 10.12, *)
func sync(_ changes: [[String: Any]], inEntityNamed entityName: String, predicate: NSPredicate?, completion: ((_ error: NSError?) -> Void)?) {
Sync.changes(changes, inEntityNamed: entityName, predicate: predicate, persistentContainer: self, operations: .all, completion: completion)
}
Expand All @@ -44,7 +41,6 @@ public extension NSPersistentContainer {
- parameter operations: The type of operations to be applied to the data, Insert, Update, Delete or any possible combination.
- parameter completion: The completion block, it returns an error if something in the Sync process goes wrong.
*/
@available(iOS 10, watchOS 3, tvOS 10, OSX 10.12, *)
func sync(_ changes: [[String: Any]], inEntityNamed entityName: String, predicate: NSPredicate?, parent: NSManagedObject?, parentRelationship: NSRelationshipDescription?, operations: Sync.OperationOptions, completion: ((_ error: NSError?) -> Void)?) {
self.performBackgroundTask { backgroundContext in
Sync.changes(changes, inEntityNamed: entityName, predicate: predicate, parent: parent, parentRelationship: parentRelationship, inContext: backgroundContext, operations: operations, completion: completion)
Expand All @@ -58,7 +54,6 @@ public extension NSPersistentContainer {
/// - entityName: The name of the entity.
/// - id: The primary key.
/// - completion: The completion block.
@available(iOS 10, watchOS 3, tvOS 10, OSX 10.12, *)
func insertOrUpdate(_ changes: [String: Any], inEntityNamed entityName: String, completion: @escaping (_ result: SyncResult<Any>) -> Void) {
self.performBackgroundTask { backgroundContext in
do {
Expand All @@ -83,7 +78,6 @@ public extension NSPersistentContainer {
/// - changes: The dictionary to be used to update the object.
/// - entityName: The name of the entity.
/// - completion: The completion block.
@available(iOS 10, watchOS 3, tvOS 10, OSX 10.12, *)
func update(_ id: Any, with changes: [String: Any], inEntityNamed entityName: String, completion: @escaping (_ result: SyncResult<Any>) -> Void) {
self.performBackgroundTask { backgroundContext in
do {
Expand All @@ -109,7 +103,6 @@ public extension NSPersistentContainer {
/// - id: The primary key.
/// - entityName: The name of the entity.
/// - completion: The completion block.
@available(iOS 10, watchOS 3, tvOS 10, OSX 10.12, *)
func delete(_ id: Any, inEntityNamed entityName: String, completion: @escaping (_ error: NSError?) -> Void) {
self.performBackgroundTask { backgroundContext in
do {
Expand Down Expand Up @@ -194,7 +187,6 @@ public extension Sync {
- parameter persistentContainer: The NSPersistentContainer instance.
- parameter completion: The completion block, it returns an error if something in the Sync process goes wrong.
*/
@available(iOS 10, watchOS 3, tvOS 10, OSX 10.12, *)
class func changes(_ changes: [[String: Any]], inEntityNamed entityName: String, predicate: NSPredicate?, persistentContainer: NSPersistentContainer, completion: ((_ error: NSError?) -> Void)?) {
self.changes(changes, inEntityNamed: entityName, predicate: predicate, persistentContainer: persistentContainer, operations: .all, completion: completion)
}
Expand All @@ -212,7 +204,6 @@ public extension Sync {
- parameter operations: The type of operations to be applied to the data, Insert, Update, Delete or any possible combination.
- parameter completion: The completion block, it returns an error if something in the Sync process goes wrong.
*/
@available(iOS 10, watchOS 3, tvOS 10, OSX 10.12, *)
class func changes(_ changes: [[String: Any]], inEntityNamed entityName: String, predicate: NSPredicate?, persistentContainer: NSPersistentContainer, operations: Sync.OperationOptions, completion: ((_ error: NSError?) -> Void)?) {
persistentContainer.performBackgroundTask { backgroundContext in
self.changes(changes, inEntityNamed: entityName, predicate: predicate, parent: nil, parentRelationship: nil, inContext: backgroundContext, operations: operations, completion: completion)
Expand Down
6 changes: 3 additions & 3 deletions Tests/PropertyMapper/DictionaryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class DictionaryTests: XCTestCase {
let user = NSEntityDescription.insertNewObject(forEntityName: "InflectionUser", into: dataStack.mainContext)
user.hyp_fill(with: self.sampleSnakeCaseJSON)
try! dataStack.mainContext.save()

let compared = [
"description": "reserved",
"inflection_binary_data": NSKeyedArchiver.archivedData(withRootObject: ["one", "two"]) as NSData,
"inflection_binary_data": try! NSKeyedArchiver.archivedData(withRootObject: ["one", "two"], requiringSecureCoding: false) as NSData,
"inflection_date": "1970-01-01",
"randomRemoteKey": "randomRemoteKey",
"inflection_id": 1,
Expand Down Expand Up @@ -60,7 +60,7 @@ class DictionaryTests: XCTestCase {

let compared = [
"description": "reserved",
"inflectionBinaryData": NSKeyedArchiver.archivedData(withRootObject: ["one", "two"]) as NSData,
"inflectionBinaryData": try! NSKeyedArchiver.archivedData(withRootObject: ["one", "two"], requiringSecureCoding: false) as NSData,
"inflectionDate": "1970-01-01",
"randomRemoteKey": "randomRemoteKey",
"inflectionID": 1,
Expand Down
4 changes: 2 additions & 2 deletions Tests/PropertyMapper/ExportTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ExportTests: XCTestCase {

let compared = [
"description": "reserved",
"inflection_binary_data": NSKeyedArchiver.archivedData(withRootObject: ["one", "two"]) as NSData,
"inflection_binary_data": try! NSKeyedArchiver.archivedData(withRootObject: ["one", "two"], requiringSecureCoding: false) as NSData,
"inflection_date": "1970-01-01",
"randomRemoteKey": "randomRemoteKey",
"inflection_id": 1,
Expand Down Expand Up @@ -62,7 +62,7 @@ class ExportTests: XCTestCase {

let compared = [
"description": "reserved",
"inflectionBinaryData": NSKeyedArchiver.archivedData(withRootObject: ["one", "two"]) as NSData,
"inflectionBinaryData": try! NSKeyedArchiver.archivedData(withRootObject: ["one", "two"], requiringSecureCoding: false) as NSData,
"inflectionDate": "1970-01-01",
"randomRemoteKey": "randomRemoteKey",
"inflectionID": 1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="14135" systemVersion="17F77" minimumToolsVersion="Automatic" sourceLanguage="Objective-C" userDefinedModelVersionIdentifier="">
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="17192" systemVersion="19G2021" minimumToolsVersion="Automatic" sourceLanguage="Objective-C" userDefinedModelVersionIdentifier="">
<entity name="InflectionCompany" representedClassName="" syncable="YES">
<attribute name="inflectionID" optional="YES" attributeType="Integer 32" usesScalarValueType="NO" syncable="YES"/>
<relationship name="camelCaseUser" optional="YES" toMany="YES" deletionRule="Cascade" destinationEntity="InflectionUser" inverseName="camelCaseCompany" inverseEntity="InflectionUser" syncable="YES">
<attribute name="inflectionID" optional="YES" attributeType="Integer 32" usesScalarValueType="NO"/>
<relationship name="camelCaseUser" optional="YES" toMany="YES" deletionRule="Cascade" destinationEntity="InflectionUser" inverseName="camelCaseCompany" inverseEntity="InflectionUser">
<userInfo>
<entry key="sync.nonExportable" value="value"/>
</userInfo>
</relationship>
</entity>
<entity name="InflectionUser" representedClassName="" syncable="YES">
<attribute name="customRemoteKey" optional="YES" attributeType="String" syncable="YES">
<attribute name="customRemoteKey" optional="YES" attributeType="String">
<userInfo>
<entry key="sync.remoteKey" value="randomRemoteKey"/>
</userInfo>
</attribute>
<attribute name="ignoredParameter" optional="YES" attributeType="String" syncable="YES">
<attribute name="ignoredParameter" optional="YES" attributeType="String">
<userInfo>
<entry key="sync.nonExportable" value="true"/>
</userInfo>
</attribute>
<attribute name="ignoreTransformable" optional="YES" attributeType="Transformable" syncable="YES"/>
<attribute name="inflectionBinaryData" optional="YES" attributeType="Binary" syncable="YES"/>
<attribute name="inflectionDate" optional="YES" attributeType="Date" usesScalarValueType="NO" syncable="YES"/>
<attribute name="inflectionID" optional="YES" attributeType="Integer 32" usesScalarValueType="NO" syncable="YES"/>
<attribute name="inflectionInteger" optional="YES" attributeType="Integer 16" usesScalarValueType="NO" syncable="YES"/>
<attribute name="inflectionString" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="inflectionURI" optional="YES" attributeType="URI" syncable="YES"/>
<attribute name="inflectionUserDescription" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="inflectionUUID" optional="YES" attributeType="UUID" usesScalarValueType="NO" syncable="YES"/>
<relationship name="camelCaseCompany" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="InflectionCompany" inverseName="camelCaseUser" inverseEntity="InflectionCompany" syncable="YES"/>
<attribute name="ignoreTransformable" optional="YES" attributeType="Transformable" valueTransformerName="BadAPIValueTransformer"/>
<attribute name="inflectionBinaryData" optional="YES" attributeType="Binary"/>
<attribute name="inflectionDate" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="inflectionID" optional="YES" attributeType="Integer 32" usesScalarValueType="NO"/>
<attribute name="inflectionInteger" optional="YES" attributeType="Integer 16" usesScalarValueType="NO"/>
<attribute name="inflectionString" optional="YES" attributeType="String"/>
<attribute name="inflectionURI" optional="YES" attributeType="URI"/>
<attribute name="inflectionUserDescription" optional="YES" attributeType="String"/>
<attribute name="inflectionUUID" optional="YES" attributeType="UUID" usesScalarValueType="NO"/>
<relationship name="camelCaseCompany" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="InflectionCompany" inverseName="camelCaseUser" inverseEntity="InflectionCompany"/>
</entity>
<elements>
<element name="InflectionCompany" positionX="-54" positionY="126" width="128" height="73"/>
<element name="InflectionUser" positionX="-263" positionY="36" width="128" height="225"/>
<element name="InflectionUser" positionX="-263" positionY="36" width="128" height="223"/>
</elements>
</model>
1 change: 0 additions & 1 deletion Tests/Sync/Helpers/Helper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import Sync
return dataStack
}

@available(iOS 10, watchOS 3, tvOS 10, OSX 10.12, *)
class func persistentStoreWithModelName(_ modelName: String) -> NSPersistentContainer {
let momdModelURL = Bundle(for: NSPersistentContainerTests.self).url(forResource: modelName, withExtension: "momd")!
let model = NSManagedObjectModel(contentsOf: momdModelURL)!
Expand Down

0 comments on commit f5ef190

Please sign in to comment.