Skip to content

Commit

Permalink
Merge pull request #58 from ra1028/swift5-compatibility
Browse files Browse the repository at this point in the history
Swift5 compatibility
  • Loading branch information
ra1028 authored Mar 27, 2019
2 parents 69f8cf4 + dd7ce68 commit a62a9ed
Show file tree
Hide file tree
Showing 32 changed files with 195 additions and 152 deletions.
73 changes: 45 additions & 28 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,51 @@
env:
global:
- LC_CTYPE=en_US.UTF-8
matrix:
include:
- os: osx
language: objective-c
osx_image: xcode10
script:
- set -o pipefail
- xcodebuild build-for-testing test-without-building -scheme DifferenceKit -configuration Release ENABLE_TESTABILITY=YES | xcpretty -c
- xcodebuild build-for-testing test-without-building -scheme DifferenceKit -configuration Release -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 8' ENABLE_TESTABILITY=YES | xcpretty - c
- xcodebuild build-for-testing test-without-building -scheme DifferenceKit -configuration Release -sdk appletvsimulator -destination 'platform=tvOS Simulator,name=Apple TV' ENABLE_TESTABILITY=YES | xcpretty -c
- xcodebuild build -scheme DifferenceKit -configuration Release -sdk watchsimulator -destination 'platform=watchOS Simulator,name=Apple Watch - 38mm' ENABLE_TESTABILITY=YES | xcpretty -c

- os: osx
language: generic
osx_image: xcode10
script:
- swift build
- swift test
aliases:
- &testing_xcode
os: osx
language: objective-c
script:
- set -o pipefail
- xcodebuild build-for-testing test-without-building -scheme DifferenceKit -configuration Release ENABLE_TESTABILITY=YES | xcpretty -c
- xcodebuild build-for-testing test-without-building -scheme DifferenceKit -configuration Release -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone X' ENABLE_TESTABILITY=YES | xcpretty - c
- xcodebuild build-for-testing test-without-building -scheme DifferenceKit -configuration Release -sdk appletvsimulator -destination 'platform=tvOS Simulator,name=Apple TV' ENABLE_TESTABILITY=YES | xcpretty -c
- xcodebuild build -scheme DifferenceKit -configuration Release -sdk watchsimulator -destination 'platform=watchOS Simulator,name=Apple Watch Series 4 - 40mm' ENABLE_TESTABILITY=YES | xcpretty -c

- os: linux
language: generic
dist: trusty
sudo: required
before_install:
- eval "$(curl -sL https://gist.githubusercontent.com/kylef/5c0475ff02b7c7671d2a/raw/9f442512a46d7a2af7b850d65a7e9bd31edfb09b/swiftenv-install.sh)"
script:
- &testing_spm_darwin
os: osx
language: generic
script:
- swift build
- swift test

- &testing_spm_linux
os: linux
language: generic
dist: trusty
sudo: required
before_install:
- eval "$(curl -sL https://gist.githubusercontent.com/kylef/5c0475ff02b7c7671d2a/raw/9f442512a46d7a2af7b850d65a7e9bd31edfb09b/swiftenv-install.sh)"
script:
- swift build
- swift test

matrix:
include:
- <<: *testing_xcode
osx_image: xcode10.1

- <<: *testing_xcode
osx_image: xcode10.2

- <<: *testing_spm_darwin
osx_image: xcode10.1

- <<: *testing_spm_darwin
osx_image: xcode10.2

- <<: *testing_spm_linux
env: SWIFT_VERSION=4.2

- <<: *testing_spm_linux
env: SWIFT_VERSION=5.0

notifications:
email: false
3 changes: 2 additions & 1 deletion DifferenceKit.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'DifferenceKit'
spec.version = '1.0.0'
spec.version = '1.1.0'
spec.author = { 'ra1028' => '[email protected]' }
spec.homepage = 'https://github.com/ra1028/DifferenceKit'
spec.documentation_url = 'https://ra1028.github.io/DifferenceKit'
Expand All @@ -13,6 +13,7 @@ Pod::Spec.new do |spec|
spec.license = { :type => 'MIT', :file => 'LICENSE' }
spec.requires_arc = true
spec.default_subspecs = 'Core', 'UIKitExtension'
spec.swift_version = "4.2"

spec.ios.deployment_target = '9.0'
spec.tvos.deployment_target = '9.0'
Expand Down
5 changes: 3 additions & 2 deletions DifferenceKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,11 @@
TargetAttributes = {
6B2DF86D210E2C12004D2D40 = {
CreatedOnToolsVersion = 9.3;
LastSwiftMigration = 1000;
LastSwiftMigration = 1020;
};
6B2DF876210E2C12004D2D40 = {
CreatedOnToolsVersion = 9.3;
LastSwiftMigration = 1000;
LastSwiftMigration = 1020;
};
};
};
Expand All @@ -233,6 +233,7 @@
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = 6B2DF864210E2C12004D2D40;
productRefGroup = 6B2DF86F210E2C12004D2D40 /* Products */;
Expand Down
6 changes: 3 additions & 3 deletions Examples/Example-iOS/Example-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
TargetAttributes = {
6B2DF8F9210E4AE1004D2D40 = {
CreatedOnToolsVersion = 9.3;
LastSwiftMigration = 1000;
LastSwiftMigration = 1020;
};
};
};
Expand Down Expand Up @@ -395,7 +395,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.ryo.DifferenceKitExample-iOS";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 1;
};
name = Debug;
Expand All @@ -417,7 +417,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.ryo.DifferenceKitExample-iOS";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 1;
};
name = Release;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
TargetAttributes = {
750C1E6921515AF800034704 = {
CreatedOnToolsVersion = 10.0;
LastSwiftMigration = 1020;
};
};
};
Expand Down Expand Up @@ -372,7 +373,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "org.cindori.Example-macOS";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -395,7 +396,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "org.cindori.Example-macOS";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand Down
6 changes: 3 additions & 3 deletions Examples/Example-tvOS/Example-tvOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
TargetAttributes = {
6B2DF942210F184A004D2D40 = {
CreatedOnToolsVersion = 9.3;
LastSwiftMigration = 1000;
LastSwiftMigration = 1020;
};
};
};
Expand Down Expand Up @@ -359,7 +359,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = "com.ryo.DifferenceKitExample-tvOS";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
Expand All @@ -379,7 +379,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = "com.ryo.DifferenceKitExample-tvOS";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source "https://rubygems.org"

gem 'cocoapods', '1.6.0'
gem 'cocoapods', '1.6.1'
gem 'jazzy', '0.9.3'
34 changes: 17 additions & 17 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ GEM
remote: https://rubygems.org/
specs:
CFPropertyList (3.0.0)
activesupport (4.2.11)
activesupport (4.2.11.1)
i18n (~> 0.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
atomos (0.1.3)
claide (1.0.2)
cocoapods (1.6.0)
cocoapods (1.6.1)
activesupport (>= 4.0.2, < 5)
claide (>= 1.0.2, < 2.0)
cocoapods-core (= 1.6.0)
cocoapods-core (= 1.6.1)
cocoapods-deintegrate (>= 1.0.2, < 2.0)
cocoapods-downloader (>= 1.2.2, < 2.0)
cocoapods-plugins (>= 1.0.0, < 2.0)
Expand All @@ -26,13 +26,13 @@ GEM
gh_inspector (~> 1.0)
molinillo (~> 0.6.6)
nap (~> 1.0)
ruby-macho (~> 1.3, >= 1.3.1)
xcodeproj (>= 1.8.0, < 2.0)
cocoapods-core (1.6.0)
ruby-macho (~> 1.4)
xcodeproj (>= 1.8.1, < 2.0)
cocoapods-core (1.6.1)
activesupport (>= 4.0.2, < 6)
fuzzy_match (~> 2.0.4)
nap (~> 1.0)
cocoapods-deintegrate (1.0.2)
cocoapods-deintegrate (1.0.3)
cocoapods-downloader (1.2.2)
cocoapods-plugins (1.0.0)
nap
Expand All @@ -43,9 +43,9 @@ GEM
netrc (~> 0.11)
cocoapods-try (1.1.0)
colored2 (3.1.2)
concurrent-ruby (1.1.4)
concurrent-ruby (1.1.5)
escape (0.0.4)
ffi (1.9.25)
ffi (1.10.0)
fourflusher (2.2.0)
fuzzy_match (2.0.4)
gh_inspector (1.1.3)
Expand All @@ -69,23 +69,23 @@ GEM
netrc (0.11.0)
open4 (1.3.4)
rb-fsevent (0.10.3)
rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2)
rb-inotify (0.10.0)
ffi (~> 1.0)
redcarpet (3.4.0)
rouge (3.2.1)
ruby-macho (1.3.1)
sass (3.5.7)
rouge (3.3.0)
ruby-macho (1.4.0)
sass (3.7.3)
sass-listen (~> 4.0.0)
sass-listen (4.0.0)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
sqlite3 (1.3.13)
sqlite3 (1.4.0)
thread_safe (0.3.6)
tzinfo (1.2.5)
thread_safe (~> 0.1)
xcinvoke (0.3.0)
liferaft (~> 0.0.6)
xcodeproj (1.8.0)
xcodeproj (1.8.1)
CFPropertyList (>= 2.3.3, < 4.0)
atomos (~> 0.1.3)
claide (>= 1.0.2, < 2.0)
Expand All @@ -96,7 +96,7 @@ PLATFORMS
ruby

DEPENDENCIES
cocoapods (= 1.6.0)
cocoapods (= 1.6.1)
jazzy (= 0.9.3)

BUNDLED WITH
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The algorithm is optimized based on the Paul Heckel's algorithm.
</H4>

<p align="center">
<a href="https://developer.apple.com/swift"><img alt="Swift4" src="https://img.shields.io/badge/language-Swift4-orange.svg"/></a>
<a href="https://developer.apple.com/swift"><img alt="Swift5" src="https://img.shields.io/badge/language-Swift4-orange.svg"/></a>
<a href="https://github.com/ra1028/DifferenceKit/releases/latest"><img alt="Release" src="https://img.shields.io/github/release/ra1028/DifferenceKit.svg"/></a>
<a href="https://cocoapods.org/pods/DifferenceKit"><img alt="CocoaPods" src="https://img.shields.io/cocoapods/v/DifferenceKit.svg"/></a>
<a href="https://github.com/Carthage/Carthage"><img alt="Carthage" src="https://img.shields.io/badge/Carthage-compatible-yellow.svg"/></a>
Expand Down
22 changes: 9 additions & 13 deletions Sources/Algorithm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,7 @@ public extension StagedChangeset where Collection: RangeReplaceableCollection, C

for targetElementIndex in targetElements.indices {
untrackedSourceIndex = untrackedSourceIndex.flatMap { index in
#if swift(>=5.0)
return sourceElementTraces[sourceSectionIndex].suffix(from: index).firstIndex { !$0.isTracked }
#else
return sourceElementTraces[sourceSectionIndex].suffix(from: index).index { !$0.isTracked }
#endif
sourceElementTraces[sourceSectionIndex].suffix(from: index).firstIndex { !$0.isTracked }
}

let targetElementPath = ElementPath(element: targetElementIndex, section: targetSectionIndex)
Expand Down Expand Up @@ -541,11 +537,7 @@ internal func differentiate<E: Differentiable, I>(
// Record the updates/moves/insertions.
for targetIndex in target.indices {
untrackedSourceIndex = untrackedSourceIndex.flatMap { index in
#if swift(>=5.0)
return sourceTraces.suffix(from: index).firstIndex { !$0.isTracked }
#else
return sourceTraces.suffix(from: index).index { !$0.isTracked }
#endif
sourceTraces.suffix(from: index).firstIndex { !$0.isTracked }
}

if let sourceIndex = targetReferences[targetIndex] {
Expand Down Expand Up @@ -661,21 +653,25 @@ internal final class IndicesReference {
/// Dictionary key using UnsafePointer for performance optimization.
@usableFromInline
internal struct TableKey<T: Hashable>: Hashable {
@usableFromInline
internal let pointeeHashValue: Int
@usableFromInline
internal let pointer: UnsafePointer<T>

@inlinable
internal init(pointer: UnsafePointer<T>) {
self.pointeeHashValue = pointer.pointee.hashValue
self.pointer = pointer
}

@inlinable
internal static func == (lhs: TableKey, rhs: TableKey) -> Bool {
return lhs.hashValue == rhs.hashValue
return lhs.pointeeHashValue == rhs.pointeeHashValue
&& (lhs.pointer.distance(to: rhs.pointer) == 0 || lhs.pointer.pointee == rhs.pointer.pointee)
}

public func hash(into hasher: inout Hasher) {

@inlinable
internal func hash(into hasher: inout Hasher) {
hasher.combine(pointer.pointee)
}
}
Expand Down
11 changes: 0 additions & 11 deletions Sources/Extensions/AppKitExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public extension NSTableView {
interrupt: ((Changeset<C>) -> Bool)? = nil,
setData: (C) -> Void
) {
#if swift(>=5.0)
reload(
using: stagedChangeset,
deleteRowsAnimation: animation(),
Expand All @@ -31,16 +30,6 @@ public extension NSTableView {
interrupt: interrupt,
setData: setData
)
#else
reload(
using: stagedChangeset,
deleteRowsAnimation: animation,
insertRowsAnimation: animation,
reloadRowsAnimation: animation,
interrupt: interrupt,
setData: setData
)
#endif
}

/// Applies multiple animated updates in stages using `StagedChangeset`.
Expand Down
Loading

0 comments on commit a62a9ed

Please sign in to comment.