Skip to content

Commit 83c24bc

Browse files
committed
Swift 5 Fixes
1 parent 7b3bf5d commit 83c24bc

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

Sources/SwiftPriorityQueue/SwiftPriorityQueue.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SwiftPriorityQueue.swift
33
// SwiftPriorityQueue
44
//
5-
// Copyright (c) 2015-2017 David Kopec
5+
// Copyright (c) 2015-2019 David Kopec
66
//
77
// Permission is hereby granted, free of charge, to any person obtaining a copy
88
// of this software and associated documentation files (the "Software"), to deal
@@ -90,7 +90,7 @@ public struct PriorityQueue<T: Comparable> {
9090
///
9191
/// - parameter item: The item to remove the first occurrence of.
9292
public mutating func remove(_ item: T) {
93-
if let index = heap.index(of: item) {
93+
if let index = heap.firstIndex(of: item) {
9494
heap.swapAt(index, heap.count - 1)
9595
heap.removeLast()
9696
if index < heap.count { // if we removed the last item, nothing to swim

SwiftPriorityQueue.xcodeproj/project.pbxproj

+13-17
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
553948251AC6495600666559 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 553948241AC6495600666559 /* AppDelegate.swift */; };
1313
553948271AC6495600666559 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 553948261AC6495600666559 /* Images.xcassets */; };
1414
5539482A1AC6495600666559 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 553948281AC6495600666559 /* MainMenu.xib */; };
15-
553948361AC6495600666559 /* SwiftPriorityQueueTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 553948351AC6495600666559 /* SwiftPriorityQueueTests.swift */; };
1615
5564AFFB1AD509E8008CF6EF /* astar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5564AFFA1AD509E8008CF6EF /* astar.swift */; };
16+
5565CDFB2249BE24002664E3 /* SwiftPriorityQueueTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5565CDFA2249BE24002664E3 /* SwiftPriorityQueueTests.swift */; };
1717
/* End PBXBuildFile section */
1818

1919
/* Begin PBXContainerItemProxy section */
@@ -34,9 +34,9 @@
3434
553948261AC6495600666559 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
3535
553948291AC6495600666559 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = "<group>"; };
3636
5539482F1AC6495600666559 /* SwiftPriorityQueueTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftPriorityQueueTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
37-
553948341AC6495600666559 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = Info.plist; path = ../Tests/Info.plist; sourceTree = "<group>"; };
38-
553948351AC6495600666559 /* SwiftPriorityQueueTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SwiftPriorityQueueTests.swift; path = ../Tests/SwiftPriorityQueueTests/SwiftPriorityQueueTests.swift; sourceTree = "<group>"; };
37+
553948341AC6495600666559 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; name = Info.plist; path = Tests/Info.plist; sourceTree = "<group>"; };
3938
5564AFFA1AD509E8008CF6EF /* astar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = astar.swift; sourceTree = "<group>"; };
39+
5565CDFA2249BE24002664E3 /* SwiftPriorityQueueTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SwiftPriorityQueueTests.swift; path = Tests/SwiftPriorityQueueTests/SwiftPriorityQueueTests.swift; sourceTree = SOURCE_ROOT; };
4040
/* End PBXFileReference section */
4141

4242
/* Begin PBXFrameworksBuildPhase section */
@@ -99,7 +99,7 @@
9999
553948321AC6495600666559 /* SwiftPriorityQueueTests */ = {
100100
isa = PBXGroup;
101101
children = (
102-
553948351AC6495600666559 /* SwiftPriorityQueueTests.swift */,
102+
5565CDFA2249BE24002664E3 /* SwiftPriorityQueueTests.swift */,
103103
553948331AC6495600666559 /* Supporting Files */,
104104
);
105105
path = SwiftPriorityQueueTests;
@@ -159,22 +159,22 @@
159159
attributes = {
160160
LastSwiftMigration = 0710;
161161
LastSwiftUpdateCheck = 0710;
162-
LastUpgradeCheck = 1000;
162+
LastUpgradeCheck = 1020;
163163
ORGANIZATIONNAME = "Oak Snow Consulting";
164164
TargetAttributes = {
165165
5539481E1AC6495600666559 = {
166166
CreatedOnToolsVersion = 6.2;
167-
LastSwiftMigration = 0900;
167+
LastSwiftMigration = 1020;
168168
};
169169
5539482E1AC6495600666559 = {
170170
CreatedOnToolsVersion = 6.2;
171-
LastSwiftMigration = 0900;
171+
LastSwiftMigration = 1020;
172172
};
173173
};
174174
};
175175
buildConfigurationList = 5539481A1AC6495600666559 /* Build configuration list for PBXProject "SwiftPriorityQueue" */;
176176
compatibilityVersion = "Xcode 3.2";
177-
developmentRegion = English;
177+
developmentRegion = en;
178178
hasScannedForEncodings = 0;
179179
knownRegions = (
180180
en,
@@ -225,8 +225,8 @@
225225
isa = PBXSourcesBuildPhase;
226226
buildActionMask = 2147483647;
227227
files = (
228-
553948361AC6495600666559 /* SwiftPriorityQueueTests.swift in Sources */,
229228
551E58BC1F770583007073B0 /* SwiftPriorityQueue.swift in Sources */,
229+
5565CDFB2249BE24002664E3 /* SwiftPriorityQueueTests.swift in Sources */,
230230
);
231231
runOnlyForDeploymentPostprocessing = 0;
232232
};
@@ -361,8 +361,7 @@
361361
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
362362
PRODUCT_BUNDLE_IDENTIFIER = "com.oaksnow.$(PRODUCT_NAME:rfc1034identifier)";
363363
PRODUCT_NAME = "$(TARGET_NAME)";
364-
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
365-
SWIFT_VERSION = 4.0;
364+
SWIFT_VERSION = 5.0;
366365
};
367366
name = Debug;
368367
};
@@ -376,8 +375,7 @@
376375
PRODUCT_BUNDLE_IDENTIFIER = "com.oaksnow.$(PRODUCT_NAME:rfc1034identifier)";
377376
PRODUCT_NAME = "$(TARGET_NAME)";
378377
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
379-
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
380-
SWIFT_VERSION = 4.0;
378+
SWIFT_VERSION = 5.0;
381379
};
382380
name = Release;
383381
};
@@ -397,8 +395,7 @@
397395
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
398396
PRODUCT_BUNDLE_IDENTIFIER = "com.oaksnow.$(PRODUCT_NAME:rfc1034identifier)";
399397
PRODUCT_NAME = "$(TARGET_NAME)";
400-
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
401-
SWIFT_VERSION = 4.0;
398+
SWIFT_VERSION = 5.0;
402399
};
403400
name = Debug;
404401
};
@@ -415,8 +412,7 @@
415412
PRODUCT_BUNDLE_IDENTIFIER = "com.oaksnow.$(PRODUCT_NAME:rfc1034identifier)";
416413
PRODUCT_NAME = "$(TARGET_NAME)";
417414
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
418-
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
419-
SWIFT_VERSION = 4.0;
415+
SWIFT_VERSION = 5.0;
420416
};
421417
name = Release;
422418
};

SwiftPriorityQueue/AppDelegate.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// AppDelegate.swift
33
// SwiftPriorityQueue
44
//
5-
// Copyright (c) 2015-2017 David Kopec
5+
// Copyright (c) 2015-2019 David Kopec
66
//
77
// Permission is hereby granted, free of charge, to any person obtaining a copy
88
// of this software and associated documentation files (the "Software"), to deal
@@ -48,7 +48,6 @@ enum Cell {
4848
struct Point: Hashable {
4949
let x: Int
5050
let y: Int
51-
var hashValue: Int { return (Int) (x.hashValue * 31 + y.hashValue) }
5251
}
5352

5453
func == (lhs: Point, rhs: Point) -> Bool {

SwiftPriorityQueue/astar.swift

+8-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// astar.swift
33
// SwiftPriorityQueue
44
//
5-
// Copyright (c) 2015-2017 David Kopec
5+
// Copyright (c) 2015-2019 David Kopec
66
//
77
// Permission is hereby granted, free of charge, to any person obtaining a copy
88
// of this software and associated documentation files (the "Software"), to deal
@@ -24,7 +24,7 @@
2424

2525
// This is an example of astar that uses SwiftPriorityQueue
2626

27-
class Node<T>: Comparable, Hashable {
27+
class Node<T: Hashable>: Comparable, Hashable {
2828
let state: T
2929
let parent: Node?
3030
let cost: Float
@@ -36,7 +36,12 @@ class Node<T>: Comparable, Hashable {
3636
self.heuristic = heuristic
3737
}
3838

39-
var hashValue: Int { return (Int) (cost + heuristic) }
39+
func hash(into hasher: inout Hasher) {
40+
hasher.combine(state)
41+
hasher.combine(parent)
42+
hasher.combine(cost)
43+
hasher.combine(heuristic)
44+
}
4045
}
4146

4247
func < <T>(lhs: Node<T>, rhs: Node<T>) -> Bool {

0 commit comments

Comments
 (0)