diff --git a/FastEasyMapping.xcodeproj/project.pbxproj b/FastEasyMapping.xcodeproj/project.pbxproj index 1ee86eb..1ca260a 100644 --- a/FastEasyMapping.xcodeproj/project.pbxproj +++ b/FastEasyMapping.xcodeproj/project.pbxproj @@ -1054,7 +1054,6 @@ 2CF8098518C3AD5700C07899 /* Frameworks */, 2CF8098618C3AD5700C07899 /* Resources */, 9A4D03A520C0CDEF78D03380 /* [CP] Embed Pods Frameworks */, - CEC0F575EF1C0D8DCDD9F021 /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -1093,7 +1092,6 @@ ADCD431E1E963AB3006C8106 /* Frameworks */, ADCD431F1E963AB3006C8106 /* Resources */, 497F98792715F5940C9D3DA3 /* [CP] Embed Pods Frameworks */, - 6C2C92317907F6AE1B45AE45 /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -1150,7 +1148,6 @@ ADE1F36D1E9A793100F457E9 /* Frameworks */, ADE1F36E1E9A793100F457E9 /* Resources */, D0180ABB27EC728691758F21 /* [CP] Embed Pods Frameworks */, - 125CDA32C3FFF7FBA2D21B70 /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -1190,7 +1187,7 @@ ORGANIZATIONNAME = Yalantis; TargetAttributes = { 2CF8098718C3AD5700C07899 = { - LastSwiftMigration = 0830; + LastSwiftMigration = 0920; TestTargetID = 2CF8097718C3AD5700C07899; }; ADCD43181E963AB3006C8106 = { @@ -1370,28 +1367,16 @@ files = ( ); inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", ); name = "[CP] Check Pods Manifest.lock"; outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-Tests-FastEasyMapping macOS Tests-checkManifestLockResult.txt", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; - showEnvVarsInLog = 0; - }; - 125CDA32C3FFF7FBA2D21B70 /* [CP] Copy Pods Resources */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "[CP] Copy Pods Resources"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Benchmark/Pods-Benchmark-resources.sh\"\n"; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; 497F98792715F5940C9D3DA3 /* [CP] Embed Pods Frameworks */ = { @@ -1400,43 +1385,48 @@ files = ( ); inputPaths = ( + "${SRCROOT}/Pods/Target Support Files/Pods-Tests-FastEasyMapping macOS Tests/Pods-Tests-FastEasyMapping macOS Tests-frameworks.sh", + "${BUILT_PRODUCTS_DIR}/MagicalRecord-macOS/MagicalRecord.framework", + "${BUILT_PRODUCTS_DIR}/CMFactory-macOS/CMFactory.framework", + "${BUILT_PRODUCTS_DIR}/Kiwi-macOS/Kiwi.framework", + "${BUILT_PRODUCTS_DIR}/Mantle-macOS/Mantle.framework", + "${BUILT_PRODUCTS_DIR}/Nimble-macOS/Nimble.framework", + "${BUILT_PRODUCTS_DIR}/OCMock-macOS/OCMock.framework", + "${BUILT_PRODUCTS_DIR}/Quick-macOS/Quick.framework", + "${BUILT_PRODUCTS_DIR}/libextobjc-macOS/libextobjc.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MagicalRecord.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CMFactory.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Kiwi.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Mantle.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Nimble.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/OCMock.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Quick.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/libextobjc.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Tests-FastEasyMapping macOS Tests/Pods-Tests-FastEasyMapping macOS Tests-frameworks.sh\"\n"; showEnvVarsInLog = 0; }; - 6C2C92317907F6AE1B45AE45 /* [CP] Copy Pods Resources */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "[CP] Copy Pods Resources"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Tests-FastEasyMapping macOS Tests/Pods-Tests-FastEasyMapping macOS Tests-resources.sh\"\n"; - showEnvVarsInLog = 0; - }; 907179569F44FB43C93D4DEE /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", ); name = "[CP] Check Pods Manifest.lock"; outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-Tests-FastEasyMapping iOS Tests-checkManifestLockResult.txt", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; 9A4D03A520C0CDEF78D03380 /* [CP] Embed Pods Frameworks */ = { @@ -1445,9 +1435,26 @@ files = ( ); inputPaths = ( + "${SRCROOT}/Pods/Target Support Files/Pods-Tests-FastEasyMapping iOS Tests/Pods-Tests-FastEasyMapping iOS Tests-frameworks.sh", + "${BUILT_PRODUCTS_DIR}/MagicalRecord-iOS/MagicalRecord.framework", + "${BUILT_PRODUCTS_DIR}/CMFactory-iOS/CMFactory.framework", + "${BUILT_PRODUCTS_DIR}/Kiwi-iOS/Kiwi.framework", + "${BUILT_PRODUCTS_DIR}/Mantle-iOS/Mantle.framework", + "${BUILT_PRODUCTS_DIR}/Nimble-iOS/Nimble.framework", + "${BUILT_PRODUCTS_DIR}/OCMock-iOS/OCMock.framework", + "${BUILT_PRODUCTS_DIR}/Quick-iOS/Quick.framework", + "${BUILT_PRODUCTS_DIR}/libextobjc-iOS/libextobjc.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MagicalRecord.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CMFactory.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Kiwi.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Mantle.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Nimble.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/OCMock.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Quick.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/libextobjc.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; @@ -1474,28 +1481,16 @@ files = ( ); inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", ); name = "[CP] Check Pods Manifest.lock"; outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-Benchmark-checkManifestLockResult.txt", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; - showEnvVarsInLog = 0; - }; - CEC0F575EF1C0D8DCDD9F021 /* [CP] Copy Pods Resources */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "[CP] Copy Pods Resources"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Tests-FastEasyMapping iOS Tests/Pods-Tests-FastEasyMapping iOS Tests-resources.sh\"\n"; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; D0180ABB27EC728691758F21 /* [CP] Embed Pods Frameworks */ = { @@ -1504,9 +1499,12 @@ files = ( ); inputPaths = ( + "${SRCROOT}/Pods/Target Support Files/Pods-Benchmark/Pods-Benchmark-frameworks.sh", + "${BUILT_PRODUCTS_DIR}/MagicalRecord-macOS/MagicalRecord.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MagicalRecord.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; @@ -1784,6 +1782,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.FastEasyMapping.Core; PRODUCT_NAME = "$(PROJECT_NAME)"; SDKROOT = iphoneos; + SWIFT_VERSION = 4.0; TVOS_DEPLOYMENT_TARGET = 9.0; VERSIONING_SYSTEM = "apple-generic"; WATCHOS_DEPLOYMENT_TARGET = 2.0; @@ -1829,6 +1828,7 @@ PRODUCT_NAME = "$(PROJECT_NAME)"; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 4.0; TVOS_DEPLOYMENT_TARGET = 9.0; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -1855,7 +1855,8 @@ PRODUCT_NAME = "FastEasyMapping iOS Tests"; SWIFT_OBJC_BRIDGING_HEADER = "FastEasyMappingTests/FastEasyMappingTests-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -1873,7 +1874,8 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.fastEasyMapping.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "FastEasyMapping iOS Tests"; SWIFT_OBJC_BRIDGING_HEADER = "FastEasyMappingTests/FastEasyMappingTests-Bridging-Header.h"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; }; name = Release; }; @@ -1947,7 +1949,7 @@ SDKROOT = macosx; SWIFT_OBJC_BRIDGING_HEADER = "FastEasyMappingTests/FastEasyMappingTests-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -1972,7 +1974,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; SWIFT_OBJC_BRIDGING_HEADER = "FastEasyMappingTests/FastEasyMappingTests-Bridging-Header.h"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Release; }; diff --git a/FastEasyMapping/Source/Deserializer/FEMDeserializer.m b/FastEasyMapping/Source/Deserializer/FEMDeserializer.m index c945cdb..5ccb937 100644 --- a/FastEasyMapping/Source/Deserializer/FEMDeserializer.m +++ b/FastEasyMapping/Source/Deserializer/FEMDeserializer.m @@ -113,17 +113,21 @@ - (void)applyRelationshipsToObject:(id)object representation:(NSDictionary *)rep - (id)_objectFromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping allocateIfNeeded:(BOOL)allocateIfNeeded { id object = nil; id primaryKey = nil; + + BOOL allocationAllowed = allocateIfNeeded; FEMAttribute *primaryKeyAttribute = mapping.primaryKeyAttribute; if (primaryKeyAttribute) { primaryKey = FEMRepresentationValueForAttribute(representation, primaryKeyAttribute); if (primaryKey != nil && primaryKey != [NSNull null]) { object = [self.store objectForPrimaryKey:primaryKey mapping:mapping]; + } else if (mapping.primaryKeyRequired) { + allocationAllowed = NO; } } BOOL allocated = NO; - if (!object && allocateIfNeeded) { + if (!object && allocationAllowed) { object = [self.store newObjectForMapping:mapping]; allocated = YES; } diff --git a/FastEasyMapping/Source/Mapping/FEMMapping.h b/FastEasyMapping/Source/Mapping/FEMMapping.h index 7786479..127a4e1 100644 --- a/FastEasyMapping/Source/Mapping/FEMMapping.h +++ b/FastEasyMapping/Source/Mapping/FEMMapping.h @@ -129,6 +129,8 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic, strong, readonly, nullable) FEMAttribute *primaryKeyAttribute; +@property (nonatomic) BOOL primaryKeyRequired; + /** @brief Returns all known attributes. Order is not saved. */ diff --git "a/FastEasyMappingTests/Specs/ManagedObjectMappingSpe\321\201.swift" "b/FastEasyMappingTests/Specs/ManagedObjectMappingSpe\321\201.swift" index 96a6efa..ab542e9 100644 --- "a/FastEasyMappingTests/Specs/ManagedObjectMappingSpe\321\201.swift" +++ "b/FastEasyMappingTests/Specs/ManagedObjectMappingSpe\321\201.swift" @@ -97,7 +97,7 @@ class ManagedObjectMappingSpec: QuickSpec { } it("should map children") { - expect(object.children) != nil + expect(object.children).toNot(beNil()) expect(object.children!).to(haveCount(2)) expect(object.children!.flatMap({ $0.string })).to(contain(["1", "2"])) diff --git a/FastEasyMappingTests/Specs/ObjectMappingSpec.swift b/FastEasyMappingTests/Specs/ObjectMappingSpec.swift index b0badc6..7e615bc 100644 --- a/FastEasyMappingTests/Specs/ObjectMappingSpec.swift +++ b/FastEasyMappingTests/Specs/ObjectMappingSpec.swift @@ -102,7 +102,7 @@ class ObjectMappingSpeс: QuickSpec { } it("should map children") { - expect(object.children) != nil + expect(object.children).toNot(beNil()) expect(object.children!).to(haveCount(2)) expect(object.children!.flatMap({ $0.string })).to(contain(["1", "2"])) diff --git a/Podfile b/Podfile index aed95bc..d8baf93 100644 --- a/Podfile +++ b/Podfile @@ -7,7 +7,7 @@ abstract_target 'Tests' do pod 'MagicalRecord', '~> 2.3' pod 'OCMock', '~> 3.4' - pod 'Nimble', '6.0.1' + pod 'Nimble', '~> 7.0.3' pod 'Quick', '~> 1.0' target 'FastEasyMapping iOS Tests' do diff --git a/Podfile.lock b/Podfile.lock index 0d8f726..72dbbdb 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -13,28 +13,39 @@ PODS: - Mantle (1.0): - libextobjc/EXTKeyPathCoding - libextobjc/EXTScope - - Nimble (6.0.1) - - OCMock (3.4) - - Quick (1.1.0) + - Nimble (7.0.3) + - OCMock (3.4.1) + - Quick (1.2.0) DEPENDENCIES: - CMFactory (~> 1.4.0) - Kiwi (~> 2.4.0) - MagicalRecord (~> 2.3) - - Nimble (= 6.0.1) + - Nimble (~> 7.0.3) - OCMock (~> 3.4) - Quick (~> 1.0) +SPEC REPOS: + https://github.com/cocoapods/specs.git: + - CMFactory + - Kiwi + - libextobjc + - MagicalRecord + - Mantle + - Nimble + - OCMock + - Quick + SPEC CHECKSUMS: CMFactory: 535c1473e91f4d0d13cb290de2144faa75a882a3 Kiwi: f49c9d54b28917df5928fe44968a39ed198cb8a8 libextobjc: a650fc1bf489a3d3a9bc2e621efa3e1006fc5471 MagicalRecord: 53bed74b4323b930992a725be713e53b37d19755 Mantle: 3fbcca07bdfe76c54a08c241689a60d34d08e783 - Nimble: 1527fd1bd2b4cf0636251a36bc8ab37e81da8347 - OCMock: 35ae71d6a8fcc1b59434d561d1520b9dd4f15765 - Quick: dafc587e21eed9f4cab3249b9f9015b0b7a7f71d + Nimble: 7f5a9c447a33002645a071bddafbfb24ea70e0ac + OCMock: 2cd0716969bab32a2283ff3a46fd26a8c8b4c5e3 + Quick: 58d203b1c5e27fff7229c4c1ae445ad7069a7a08 -PODFILE CHECKSUM: 8b335f3c7d304d60ddcaa7c6d5d07502ac52ed28 +PODFILE CHECKSUM: aaca2b498077e54e9c4a387d50a365b3169c53a5 -COCOAPODS: 1.2.0 +COCOAPODS: 1.5.3