Skip to content

Commit 2a835f5

Browse files
gregstephencelis
authored andcommitted
Swift 4.2: Rename Random to SystemRandomNumberGenerator (#6)
* Rename Random to SystemRandomNumberGenerator for Swift 4.2 * Update Swift version * Set swift version to development snapshot * Set swift version to development snapshot * Set swift version to development snapshot * Remove Swift 4.2 check since the Random change was apparently backported * Optimistically update to latest Swift 4.2 snapshot * try Swift version 4.2 * will this kind of version string work? * ok fine convergence it is * try compiling without the +Random extension * temporarily remove RandomAccessCollection conformance * update +Random.swift to 4.2 APIs * build on macOS instead
1 parent 6cb3612 commit 2a835f5

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

.swift-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.1
1+
swift-4.2-CONVERGENCE

.travis.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
os:
2-
- linux
2+
- osx
3+
osx_image: xcode10
34
env:
45
language: generic
5-
sudo: required
6-
dist: trusty
76
install:
87
- if [ $TRAVIS_OS_NAME = linux ]; then
98
eval "$(curl -sL https://swiftenv.fuller.li/install.sh)";

NonEmpty.xcodeproj/project.pbxproj

+13-5
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
80CD742220D58E11004E5F60 /* NonEmpty+Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NonEmpty+Array.swift"; sourceTree = "<group>"; };
7676
80EFFA6020D5A1BE00B265AE /* NonEmpty+Random.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NonEmpty+Random.swift"; sourceTree = "<group>"; };
7777
"NonEmpty::NonEmpty::Product" /* NonEmpty.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = NonEmpty.framework; sourceTree = BUILT_PRODUCTS_DIR; };
78-
"NonEmpty::NonEmptyTests::Product" /* NonEmptyTests.xctest */ = {isa = PBXFileReference; lastKnownFileType = file; path = NonEmptyTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
78+
"NonEmpty::NonEmptyTests::Product" /* NonEmptyTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; path = NonEmptyTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
7979
OBJ_14 /* NonEmptyTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonEmptyTests.swift; sourceTree = "<group>"; };
8080
OBJ_16 /* NonEmpty.xcworkspace */ = {isa = PBXFileReference; lastKnownFileType = wrapper.workspace; path = NonEmpty.xcworkspace; sourceTree = SOURCE_ROOT; };
8181
OBJ_6 /* Package.swift */ = {isa = PBXFileReference; explicitFileType = sourcecode.swift; path = Package.swift; sourceTree = "<group>"; };
@@ -235,6 +235,14 @@
235235
isa = PBXProject;
236236
attributes = {
237237
LastUpgradeCheck = 9999;
238+
TargetAttributes = {
239+
"NonEmpty::NonEmpty" = {
240+
LastSwiftMigration = 1000;
241+
};
242+
"NonEmpty::NonEmptyTests" = {
243+
LastSwiftMigration = 1000;
244+
};
245+
};
238246
};
239247
buildConfigurationList = OBJ_2 /* Build configuration list for PBXProject "NonEmpty" */;
240248
compatibilityVersion = "Xcode 3.2";
@@ -331,7 +339,7 @@
331339
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
332340
SKIP_INSTALL = YES;
333341
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited)";
334-
SWIFT_VERSION = 4.0;
342+
SWIFT_VERSION = 4.2;
335343
TARGET_NAME = NonEmpty;
336344
};
337345
name = Debug;
@@ -356,7 +364,7 @@
356364
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
357365
SKIP_INSTALL = YES;
358366
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited)";
359-
SWIFT_VERSION = 4.0;
367+
SWIFT_VERSION = 4.2;
360368
TARGET_NAME = NonEmpty;
361369
};
362370
name = Release;
@@ -453,7 +461,7 @@
453461
OTHER_LDFLAGS = "$(inherited)";
454462
OTHER_SWIFT_FLAGS = "$(inherited)";
455463
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited)";
456-
SWIFT_VERSION = 4.0;
464+
SWIFT_VERSION = 4.2;
457465
TARGET_NAME = NonEmptyTests;
458466
};
459467
name = Debug;
@@ -474,7 +482,7 @@
474482
OTHER_LDFLAGS = "$(inherited)";
475483
OTHER_SWIFT_FLAGS = "$(inherited)";
476484
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited)";
477-
SWIFT_VERSION = 4.0;
485+
SWIFT_VERSION = 4.2;
478486
TARGET_NAME = NonEmptyTests;
479487
};
480488
name = Release;

Sources/NonEmpty/NonEmpty+Random.swift

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
#if swift(>=4.1.5)
1+
#if swift(>=4.2)
22
extension NonEmpty {
33
public func randomElement<T: RandomNumberGenerator>(using generator: inout T) -> Element {
44
return ContiguousArray(self).randomElement(using: &generator) ?? self.head
55
}
66

77
public func randomElement() -> Element {
8-
return self.randomElement(using: &Random.default)
8+
var generator = SystemRandomNumberGenerator()
9+
return self.randomElement(using: &generator)
910
}
1011
}
1112

@@ -17,7 +18,8 @@ extension NonEmpty where C: RangeReplaceableCollection {
1718
}
1819

1920
public mutating func shuffle() {
20-
self.shuffle(using: &Random.default)
21+
var generator = SystemRandomNumberGenerator()
22+
self.shuffle(using: &generator)
2123
}
2224

2325
public func shuffled<T: RandomNumberGenerator>(using generator: inout T) -> NonEmpty {
@@ -27,7 +29,8 @@ extension NonEmpty where C: RangeReplaceableCollection {
2729
}
2830

2931
public func shuffled() -> NonEmpty {
30-
return self.shuffled(using: &Random.default)
32+
var generator = SystemRandomNumberGenerator()
33+
return self.shuffled(using: &generator)
3134
}
3235
}
3336
#endif

0 commit comments

Comments
 (0)