From 20e04a0b4dd4b070ea84039222761318261cea7a Mon Sep 17 00:00:00 2001 From: Denys Telezhkin Date: Fri, 30 Mar 2018 14:34:38 +0300 Subject: [PATCH] Updates for Xcode 9.3 and Swift 4.1. --- CHANGELOG.md | 2 ++ DTModelStorage.xcodeproj/project.pbxproj | 10 +++++- .../xcshareddata/IDEWorkspaceChecks.plist | 8 +++++ .../xcschemes/DTModelStorage.xcscheme | 8 ++--- Source/Core/BackwardsCompatibility.swift | 36 +++++++++++++++++++ Source/Core/SectionModel.swift | 2 +- Source/Core/SectionProtocols.swift | 2 +- Source/Core/StorageProtocols.swift | 2 +- Source/Core/StorageUpdate.swift | 4 +-- .../MemoryStorageEditSpecs.swift | 2 +- .../MemoryStorageSearchSpec.swift | 15 ++++++-- 11 files changed, 76 insertions(+), 15 deletions(-) create mode 100644 DTModelStorage.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 Source/Core/BackwardsCompatibility.swift diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ab2ba44..53b74bd2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ All notable changes to this project will be documented in this file. # Next +* Updates for Xcode 9.3 and Swift 4.1 + ## [7.0.2](https://github.com/DenHeadless/DTModelStorage/releases/tag/7.0.2) * Properly collect all updates from updateWithoutAnimations block. diff --git a/DTModelStorage.xcodeproj/project.pbxproj b/DTModelStorage.xcodeproj/project.pbxproj index db35041f..e5dd0716 100644 --- a/DTModelStorage.xcodeproj/project.pbxproj +++ b/DTModelStorage.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 3E75031A206E504E004D6EAA /* BackwardsCompatibility.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E750319206E504E004D6EAA /* BackwardsCompatibility.swift */; }; 9A3110931BB8643C00741F90 /* DTModelStorage.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9A2A385B1AEE24340021E97D /* DTModelStorage.framework */; }; 9A41A6321DC8B5B600B9A015 /* SectionProtocols.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A41A6311DC8B5B600B9A015 /* SectionProtocols.swift */; }; 9A5DE78B1FD2F502000FE218 /* MemoryStorageDeferredUpdatesTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A5DE78A1FD2F502000FE218 /* MemoryStorageDeferredUpdatesTestCase.swift */; }; @@ -64,6 +65,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 3E750319206E504E004D6EAA /* BackwardsCompatibility.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = BackwardsCompatibility.swift; path = Source/Core/BackwardsCompatibility.swift; sourceTree = ""; }; 9A2A385B1AEE24340021E97D /* DTModelStorage.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = DTModelStorage.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 9A41A6311DC8B5B600B9A015 /* SectionProtocols.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SectionProtocols.swift; path = Source/Core/SectionProtocols.swift; sourceTree = ""; }; 9A5DE78A1FD2F502000FE218 /* MemoryStorageDeferredUpdatesTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = MemoryStorageDeferredUpdatesTestCase.swift; path = Specs/MemoryStorage/MemoryStorageDeferredUpdatesTestCase.swift; sourceTree = ""; }; @@ -297,6 +299,7 @@ 9A63E5FD1CCCE94B00DC69B1 /* UINib+Existance.swift */, 9A63E5FE1CCCE94B00DC69B1 /* EventReactions.swift */, 9A63E5FF1CCCE94B00DC69B1 /* ViewModelMapping.swift */, + 3E750319206E504E004D6EAA /* BackwardsCompatibility.swift */, ); name = Utitlities; sourceTree = ""; @@ -377,7 +380,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0910; + LastUpgradeCheck = 0930; ORGANIZATIONNAME = "Denys Telezhkin"; TargetAttributes = { 9A2A385A1AEE24340021E97D = { @@ -489,6 +492,7 @@ 9A63E5EC1CCCE91E00DC69B1 /* CoreDataStorage.swift in Sources */, 9A63E6041CCCE94B00DC69B1 /* RuntimeHelper.swift in Sources */, 9A63E6081CCCE94B00DC69B1 /* EventReactions.swift in Sources */, + 3E75031A206E504E004D6EAA /* BackwardsCompatibility.swift in Sources */, 9A63E6021CCCE94B00DC69B1 /* ModelTransfer.swift in Sources */, 9A63E6001CCCE94B00DC69B1 /* MemoryStorage+UpdateWithoutAnimations.swift in Sources */, 9A41A6321DC8B5B600B9A015 /* SectionProtocols.swift in Sources */, @@ -688,11 +692,13 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; @@ -754,11 +760,13 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; diff --git a/DTModelStorage.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/DTModelStorage.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 00000000..18d98100 --- /dev/null +++ b/DTModelStorage.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/DTModelStorage.xcodeproj/xcshareddata/xcschemes/DTModelStorage.xcscheme b/DTModelStorage.xcodeproj/xcshareddata/xcschemes/DTModelStorage.xcscheme index eca4a647..b03255a7 100644 --- a/DTModelStorage.xcodeproj/xcshareddata/xcschemes/DTModelStorage.xcscheme +++ b/DTModelStorage.xcodeproj/xcshareddata/xcschemes/DTModelStorage.xcscheme @@ -1,6 +1,6 @@ + codeCoverageEnabled = "YES" + shouldUseLaunchSchemeArgsEnv = "YES"> @@ -71,7 +70,6 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/Source/Core/BackwardsCompatibility.swift b/Source/Core/BackwardsCompatibility.swift new file mode 100644 index 00000000..2ce23b1b --- /dev/null +++ b/Source/Core/BackwardsCompatibility.swift @@ -0,0 +1,36 @@ +// +// BackwardsCompatibility.swift +// DTModelStorage +// +// Created by Denys Telezhkin on 30.03.2018. +// Copyright © 2018 Denys Telezhkin. All rights reserved. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +import Foundation + +#if swift(>=4.1) +#else +/// Extension for adding Swift 4.1 methods, to support Swift 4.0 and Swift 3.2/3.3 concurrently. +extension Sequence { + func compactMap(_ transform: (Self.Element) throws -> ElementOfResult?) rethrows -> [ElementOfResult] { + return try flatMap(transform) + } +} +#endif diff --git a/Source/Core/SectionModel.swift b/Source/Core/SectionModel.swift index eec32b78..5a1e90ab 100644 --- a/Source/Core/SectionModel.swift +++ b/Source/Core/SectionModel.swift @@ -57,7 +57,7 @@ open class SectionModel: Section, SupplementaryAccessible /// Returns items of `type` in current section open func items(ofType type: T.Type) -> [T] { - return items.flatMap { $0 as? T } + return items.compactMap { $0 as? T } } /// Number of items in current section diff --git a/Source/Core/SectionProtocols.swift b/Source/Core/SectionProtocols.swift index 68a0c148..9b0160ff 100644 --- a/Source/Core/SectionProtocols.swift +++ b/Source/Core/SectionProtocols.swift @@ -38,7 +38,7 @@ public protocol SupplementaryAccessible : class { var currentSectionIndex: Int? { get } /// delegate, that knows about current section index in storage. - weak var sectionLocationDelegate: SectionLocationIdentifyable? { get set } + var sectionLocationDelegate: SectionLocationIdentifyable? { get set } /// Supplementaries dictionary var supplementaries: [String: [Int:Any]] { get set } diff --git a/Source/Core/StorageProtocols.swift b/Source/Core/StorageProtocols.swift index cceb83be..2eb24a6a 100644 --- a/Source/Core/StorageProtocols.swift +++ b/Source/Core/StorageProtocols.swift @@ -36,7 +36,7 @@ public protocol Storage : class func item(at indexPath: IndexPath) -> Any? /// Delegate property used to notify about current data storage changes. - weak var delegate: StorageUpdating? { get set } + var delegate: StorageUpdating? { get set } } /// `SupplementaryStorage` protocol defines interface for storages, that can hold supplementary objects(like header and footer models). diff --git a/Source/Core/StorageUpdate.swift b/Source/Core/StorageUpdate.swift index 336e2ca2..201346cc 100644 --- a/Source/Core/StorageUpdate.swift +++ b/Source/Core/StorageUpdate.swift @@ -101,11 +101,11 @@ public class StorageUpdate: Equatable, CustomStringConvertible /// Description of object changes public var description: String { - let objectChangesString = "Object changes: \n" + objectChanges.flatMap({ (arg) -> String? in + let objectChangesString = "Object changes: \n" + objectChanges.compactMap({ (arg) -> String? in let (change, indexPaths) = arg return change.rawValue.capitalized + " \(indexPaths)" }).reduce("", +) - let sectionChangesString = "Section changes:" + objectChanges.flatMap({ (arg) -> String? in + let sectionChangesString = "Section changes:" + objectChanges.compactMap({ (arg) -> String? in let (change, index) = arg return change.rawValue.capitalized + " \(index))" }).reduce("", +) diff --git a/Tests/Specs/MemoryStorage/MemoryStorageEditSpecs.swift b/Tests/Specs/MemoryStorage/MemoryStorageEditSpecs.swift index 589f26fa..85ea1128 100644 --- a/Tests/Specs/MemoryStorage/MemoryStorageEditSpecs.swift +++ b/Tests/Specs/MemoryStorage/MemoryStorageEditSpecs.swift @@ -278,7 +278,7 @@ class MemoryStorageEditSpecs: XCTestCase { let kind = "foo" storage.setSupplementaries([[0: 1], [0: 2], [0: 3]], forKind: kind) - storage.setSupplementaries([[Int:Int]]().flatMap { $0 }, forKind: kind) + storage.setSupplementaries([[Int:Int]]().compactMap { $0 }, forKind: kind) expect(self.storage.section(atIndex: 0)?.supplementaryModel(ofKind: kind, atIndex: 0) as? Int).to(beNil()) expect(self.storage.section(atIndex: 1)?.supplementaryModel(ofKind: kind, atIndex: 0) as? Int).to(beNil()) diff --git a/Tests/Specs/MemoryStorage/MemoryStorageSearchSpec.swift b/Tests/Specs/MemoryStorage/MemoryStorageSearchSpec.swift index 3173684c..7584310e 100644 --- a/Tests/Specs/MemoryStorage/MemoryStorageSearchSpec.swift +++ b/Tests/Specs/MemoryStorage/MemoryStorageSearchSpec.swift @@ -11,6 +11,16 @@ import XCTest @testable import DTModelStorage import Nimble +#if swift(>=4.1) +#else +/// Extension for adding Swift 4.1 methods, to support Swift 4.0 and Swift 3.2/3.3 concurrently. +extension Sequence { + func compactMap(_ transform: (Self.Element) throws -> ElementOfResult?) rethrows -> [ElementOfResult] { + return try flatMap(transform) + } +} +#endif + class TableCell: UITableViewCell, ModelTransfer { func update(with model: Int) { @@ -96,14 +106,13 @@ class MemoryStorageSearchSpec: XCTestCase { storage.updateWithoutAnimations { storage.addItems([1,2]) } - - expect(self.storage.items(inSection: 0)?.flatMap { $0 as? Int} ?? []) == [1,2] + expect((self.storage.items(inSection: 0) ?? []).compactMap { $0 as? Int } ) == [1,2] storage.updateWithoutAnimations { storage.addItems([3,4]) storage.addItems([5,6]) } - expect(self.storage.items(inSection: 0)?.flatMap { $0 as? Int} ?? []) == [1,2,3,4,5,6] + expect((self.storage.items(inSection: 0) ?? []).compactMap { $0 as? Int }) == [1,2,3,4,5,6] } func testEmptySection()