Skip to content

Commit

Permalink
Updates for Xcode 9.3 and Swift 4.1.
Browse files Browse the repository at this point in the history
  • Loading branch information
DenTelezhkin committed Mar 30, 2018
1 parent 21783a1 commit 20e04a0
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 9 additions & 1 deletion DTModelStorage.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -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 = "<group>"; };
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 = "<group>"; };
9A5DE78A1FD2F502000FE218 /* MemoryStorageDeferredUpdatesTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = MemoryStorageDeferredUpdatesTestCase.swift; path = Specs/MemoryStorage/MemoryStorageDeferredUpdatesTestCase.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -297,6 +299,7 @@
9A63E5FD1CCCE94B00DC69B1 /* UINib+Existance.swift */,
9A63E5FE1CCCE94B00DC69B1 /* EventReactions.swift */,
9A63E5FF1CCCE94B00DC69B1 /* ViewModelMapping.swift */,
3E750319206E504E004D6EAA /* BackwardsCompatibility.swift */,
);
name = Utitlities;
sourceTree = "<group>";
Expand Down Expand Up @@ -377,7 +380,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0910;
LastUpgradeCheck = 0930;
ORGANIZATIONNAME = "Denys Telezhkin";
TargetAttributes = {
9A2A385A1AEE24340021E97D = {
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0910"
LastUpgradeVersion = "0930"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -40,9 +40,8 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
codeCoverageEnabled = "YES"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
Expand Down Expand Up @@ -71,7 +70,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
36 changes: 36 additions & 0 deletions Source/Core/BackwardsCompatibility.swift
Original file line number Diff line number Diff line change
@@ -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<ElementOfResult>(_ transform: (Self.Element) throws -> ElementOfResult?) rethrows -> [ElementOfResult] {
return try flatMap(transform)
}
}
#endif
2 changes: 1 addition & 1 deletion Source/Core/SectionModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ open class SectionModel: Section, SupplementaryAccessible
/// Returns items of `type` in current section
open func items<T>(ofType type: T.Type) -> [T]
{
return items.flatMap { $0 as? T }
return items.compactMap { $0 as? T }
}

/// Number of items in current section
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/SectionProtocols.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/StorageProtocols.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/StorageUpdate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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("", +)
Expand Down
2 changes: 1 addition & 1 deletion Tests/Specs/MemoryStorage/MemoryStorageEditSpecs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
15 changes: 12 additions & 3 deletions Tests/Specs/MemoryStorage/MemoryStorageSearchSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<ElementOfResult>(_ transform: (Self.Element) throws -> ElementOfResult?) rethrows -> [ElementOfResult] {
return try flatMap(transform)
}
}
#endif

class TableCell: UITableViewCell, ModelTransfer
{
func update(with model: Int) {
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 20e04a0

Please sign in to comment.