Skip to content

Commit

Permalink
Update for Swift 5.0 (#55)
Browse files Browse the repository at this point in the history
* Update for Swift 5.0
  • Loading branch information
keith authored Mar 28, 2019
1 parent fd57b4f commit 57418a0
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ matrix:
env: ACTION=tvOS

language: objective-c
osx_image: xcode10
osx_image: xcode10.2

script:
- make install-$ACTION && make test-$ACTION
44 changes: 31 additions & 13 deletions Kronos.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 47;
objectVersion = 51;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -193,19 +193,20 @@
TargetAttributes = {
C20174821BD5509D00E4FE18 = {
CreatedOnToolsVersion = 7.0;
LastSwiftMigration = 1000;
LastSwiftMigration = 1020;
};
C201748C1BD5509D00E4FE18 = {
CreatedOnToolsVersion = 7.0;
LastSwiftMigration = 1000;
LastSwiftMigration = 1020;
};
};
};
buildConfigurationList = C201747D1BD5509D00E4FE18 /* Build configuration list for PBXProject "Kronos" */;
compatibilityVersion = "Xcode 6.3";
compatibilityVersion = "Xcode 10.0";
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
);
mainGroup = C20174791BD5509D00E4FE18;
Expand Down Expand Up @@ -354,7 +355,8 @@
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = NO;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -376,12 +378,16 @@
INFOPLIST_FILE = "$(SRCROOT)/Resources/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.Lyft.Kronos;
PRODUCT_NAME = Kronos;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
name = Debug;
Expand All @@ -400,11 +406,15 @@
INFOPLIST_FILE = "$(SRCROOT)/Resources/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.Lyft.Kronos;
PRODUCT_NAME = Kronos;
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
name = Release;
Expand All @@ -415,11 +425,15 @@
buildSettings = {
CLANG_ENABLE_MODULES = YES;
COMBINE_HIDPI_IMAGES = YES;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.Lyft.KronosTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -429,10 +443,14 @@
buildSettings = {
CLANG_ENABLE_MODULES = YES;
COMBINE_HIDPI_IMAGES = YES;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.Lyft.KronosTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ test-tvOS:
xcodebuild \
-project Kronos.xcodeproj \
-scheme Kronos \
-destination "platform=tvOS Simulator,name=Apple TV,OS=12.0" \
-destination "platform=tvOS Simulator,name=Apple TV,OS=12.2" \
test \
| xcpretty -ct
5 changes: 2 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:4.2
// swift-tools-version:5.0
import PackageDescription

let package = Package(
Expand All @@ -9,6 +9,5 @@ let package = Package(
targets: [
.target(name: "Kronos", path: "Sources"),
.testTarget(name: "KronosTests", dependencies: ["Kronos"]),
],
swiftLanguageVersions: [.v4, .v4_2]
]
)
5 changes: 3 additions & 2 deletions Sources/DNSResolver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ final class DNSResolver {
let IPs = (addresses.takeUnretainedValue() as NSArray)
.compactMap { $0 as? Data }
.compactMap { data -> InternetAddress? in
return data.withUnsafeBytes { (pointer: UnsafePointer<sockaddr_storage>) in
return InternetAddress(storage: pointer)
return data.withUnsafeBytes { rawPointer in
let pointer = rawPointer.bindMemory(to: sockaddr_storage.self).baseAddress
return InternetAddress(storage: pointer!)
}
}

Expand Down
15 changes: 12 additions & 3 deletions Sources/Data+Bytes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ extension Data {
///
/// - returns: The byte located at position `index`.
func getByte(at index: Int) -> Int8 {
let data: Int8 = self.subdata(in: index ..< (index + 1)).withUnsafeBytes { $0.pointee }
let data: Int8 = self.subdata(in: index ..< (index + 1)).withUnsafeBytes { rawPointer in
rawPointer.bindMemory(to: Int8.self).baseAddress!.pointee
}

return data
}

Expand All @@ -41,7 +44,10 @@ extension Data {
///
/// - returns: The unsigned int located at position `index`.
func getUnsignedInteger(at index: Int, bigEndian: Bool = true) -> UInt32 {
let data: UInt32 = self.subdata(in: index ..< (index + 4)).withUnsafeBytes { $0.pointee }
let data: UInt32 = self.subdata(in: index ..< (index + 4)).withUnsafeBytes { rawPointer in
rawPointer.bindMemory(to: UInt32.self).baseAddress!.pointee
}

return bigEndian ? data.bigEndian : data.littleEndian
}

Expand All @@ -52,7 +58,10 @@ extension Data {
///
/// - returns: The unsigned long integer located at position `index`.
func getUnsignedLong(at index: Int, bigEndian: Bool = true) -> UInt64 {
let data: UInt64 = self.subdata(in: index ..< (index + 8)).withUnsafeBytes { $0.pointee }
let data: UInt64 = self.subdata(in: index ..< (index + 8)).withUnsafeBytes { rawPointer in
rawPointer.bindMemory(to: UInt64.self).baseAddress!.pointee
}

return bigEndian ? data.bigEndian : data.littleEndian
}

Expand Down

0 comments on commit 57418a0

Please sign in to comment.