Error and Warning Free Pure Swift 4

This commit is contained in:
Kilian Hofmann 2018-05-06 23:06:21 +02:00
parent 7fc78049d2
commit 6be85c4a95
11 changed files with 39 additions and 35 deletions

View File

@ -577,7 +577,7 @@
isa = PBXProject; isa = PBXProject;
attributes = { attributes = {
LastSwiftUpdateCheck = 0830; LastSwiftUpdateCheck = 0830;
LastUpgradeCheck = 0900; LastUpgradeCheck = 0930;
ORGANIZATIONNAME = "Kilian Hofmann"; ORGANIZATIONNAME = "Kilian Hofmann";
TargetAttributes = { TargetAttributes = {
E220BF9B1EFB22D400DF5A97 = { E220BF9B1EFB22D400DF5A97 = {
@ -793,6 +793,7 @@
CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES; CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_EMPTY_BODY = YES;
@ -800,6 +801,7 @@
CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
@ -851,6 +853,7 @@
CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES; CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_EMPTY_BODY = YES;
@ -858,6 +861,7 @@
CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;

View File

@ -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>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<Scheme <Scheme
LastUpgradeVersion = "0900" LastUpgradeVersion = "0930"
version = "1.3"> version = "1.3">
<BuildAction <BuildAction
parallelizeBuildables = "YES" parallelizeBuildables = "YES"
@ -54,7 +54,6 @@
buildConfiguration = "Debug" buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES"> shouldUseLaunchSchemeArgsEnv = "YES">
<Testables> <Testables>
</Testables> </Testables>
@ -74,7 +73,6 @@
buildConfiguration = "Debug" buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0" launchStyle = "0"
useCustomWorkingDirectory = "NO" useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO" ignoresPersistentStateOnLaunch = "NO"

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<Scheme <Scheme
LastUpgradeVersion = "0900" LastUpgradeVersion = "0930"
version = "1.3"> version = "1.3">
<BuildAction <BuildAction
parallelizeBuildables = "YES" parallelizeBuildables = "YES"
@ -26,7 +26,6 @@
buildConfiguration = "Debug" buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES"> shouldUseLaunchSchemeArgsEnv = "YES">
<Testables> <Testables>
</Testables> </Testables>
@ -46,7 +45,6 @@
buildConfiguration = "Debug" buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0" launchStyle = "0"
useCustomWorkingDirectory = "NO" useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO" ignoresPersistentStateOnLaunch = "NO"

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<Scheme <Scheme
LastUpgradeVersion = "0900" LastUpgradeVersion = "0930"
version = "1.3"> version = "1.3">
<BuildAction <BuildAction
parallelizeBuildables = "YES" parallelizeBuildables = "YES"
@ -26,7 +26,6 @@
buildConfiguration = "Debug" buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES"> shouldUseLaunchSchemeArgsEnv = "YES">
<Testables> <Testables>
</Testables> </Testables>
@ -46,7 +45,6 @@
buildConfiguration = "Debug" buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0" launchStyle = "0"
useCustomWorkingDirectory = "NO" useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO" ignoresPersistentStateOnLaunch = "NO"

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<Scheme <Scheme
LastUpgradeVersion = "0900" LastUpgradeVersion = "0930"
version = "1.3"> version = "1.3">
<BuildAction <BuildAction
parallelizeBuildables = "YES" parallelizeBuildables = "YES"
@ -26,7 +26,6 @@
buildConfiguration = "Debug" buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES"> shouldUseLaunchSchemeArgsEnv = "YES">
<Testables> <Testables>
</Testables> </Testables>
@ -46,7 +45,6 @@
buildConfiguration = "Debug" buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0" launchStyle = "0"
useCustomWorkingDirectory = "NO" useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO" ignoresPersistentStateOnLaunch = "NO"

View File

@ -37,7 +37,7 @@ class FileOperations: NSObject {
static func log(data: String, toLog path: String) { static func log(data: String, toLog path: String) {
let dataToWrite = encodeTimeStamp(stamp: data, threshold: "") let dataToWrite = encodeTimeStamp(stamp: data, threshold: "")
let file: UnsafeMutableRawPointer = UnsafeMutableRawPointer.allocate(bytes: 3, alignedTo: 1) let file: UnsafeMutableRawPointer = UnsafeMutableRawPointer.allocate(byteCount: 3, alignment: 1)
file.storeBytes(of: dataToWrite, as: UInt32.self) file.storeBytes(of: dataToWrite, as: UInt32.self)
do { do {
let fileData: NSMutableData = try NSMutableData(contentsOf: URL(fileURLWithPath: path)) let fileData: NSMutableData = try NSMutableData(contentsOf: URL(fileURLWithPath: path))
@ -48,27 +48,27 @@ class FileOperations: NSObject {
fileData.append(file, length: 3) fileData.append(file, length: 3)
fileData.write(to: URL(fileURLWithPath: path), atomically: true) fileData.write(to: URL(fileURLWithPath: path), atomically: true)
} }
file.deallocate(bytes: 3, alignedTo: 1) file.deallocate()
} }
static func log(data: String, toData out: inout Data) { static func log(data: String, toData out: inout Data) {
let dataToWrite = encodeTimeStamp(stamp: data, threshold: "") let dataToWrite = encodeTimeStamp(stamp: data, threshold: "")
let file: UnsafeMutableRawPointer = UnsafeMutableRawPointer.allocate(bytes: 3, alignedTo: 1) let file: UnsafeMutableRawPointer = UnsafeMutableRawPointer.allocate(byteCount: 3, alignment: 1)
file.storeBytes(of: dataToWrite, as: UInt32.self) file.storeBytes(of: dataToWrite, as: UInt32.self)
let fileData: NSMutableData = NSMutableData() let fileData: NSMutableData = NSMutableData()
fileData.append(file, length: 3) fileData.append(file, length: 3)
out.append(fileData as Data) out.append(fileData as Data)
file.deallocate(bytes: 3, alignedTo: 1) file.deallocate()
} }
static func load(log Data: NSData) -> [String]? { static func load(log Data: NSData) -> [String]? {
var returnString: [String] = [] var returnString: [String] = []
var i: Int = 0 var i: Int = 0
while i < Data.length { while i < Data.length {
let data: UnsafeMutableRawPointer = UnsafeMutableRawPointer.allocate(bytes: 3, alignedTo: 1) let data: UnsafeMutableRawPointer = UnsafeMutableRawPointer.allocate(byteCount: 3, alignment: 1)
Data.getBytes(data, range: NSRange(location: i, length: 3)) Data.getBytes(data, range: NSRange(location: i, length: 3))
returnString.append("\(decodeTimestamp(stamp: data.load(as: UInt32.self)).0)\n") returnString.append("\(decodeTimestamp(stamp: data.load(as: UInt32.self)).0)\n")
data.deallocate(bytes: 3, alignedTo: 1) data.deallocate()
i += 3 i += 3
} }
if returnString.count > 0 { if returnString.count > 0 {
@ -181,29 +181,29 @@ class FileOperations: NSObject {
let decodedSize: UInt8 = data.bytes.load(fromByteOffset: variableAdjust, as: UInt8.self) let decodedSize: UInt8 = data.bytes.load(fromByteOffset: variableAdjust, as: UInt8.self)
variableAdjust += 1 variableAdjust += 1
let retTimePtr: UnsafeMutableRawPointer = UnsafeMutableRawPointer.allocate(bytes: 3, alignedTo: 1) let retTimePtr: UnsafeMutableRawPointer = UnsafeMutableRawPointer.allocate(byteCount: 3, alignment: 1)
data.getBytes(retTimePtr, range: NSRange(location: variableAdjust, length: 3)) data.getBytes(retTimePtr, range: NSRange(location: variableAdjust, length: 3))
variableAdjust += 3 variableAdjust += 3
let encodedTime: UInt32 = retTimePtr.load(as: UInt32.self) let encodedTime: UInt32 = retTimePtr.load(as: UInt32.self)
retTimePtr.deallocate(bytes: 3, alignedTo: 1) retTimePtr.deallocate()
let decodedTimeStamp = decodeTimestamp(stamp: encodedTime).0 let decodedTimeStamp = decodeTimestamp(stamp: encodedTime).0
let decodedThreshold = decodeTimestamp(stamp: encodedTime).1 let decodedThreshold = decodeTimestamp(stamp: encodedTime).1
let retPwrPtr: UnsafeMutableRawPointer = UnsafeMutableRawPointer.allocate(bytes: 4, alignedTo: 1) let retPwrPtr: UnsafeMutableRawPointer = UnsafeMutableRawPointer.allocate(byteCount: 4, alignment: 1)
data.getBytes(retPwrPtr, range: NSRange(location: variableAdjust, length: 4)) data.getBytes(retPwrPtr, range: NSRange(location: variableAdjust, length: 4))
var decodedPower: Any = retPwrPtr.load(as: Int32.self) var decodedPower: Any = retPwrPtr.load(as: Int32.self)
retPwrPtr.deallocate(bytes: 4, alignedTo: 1) retPwrPtr.deallocate()
if decodedPower as! Int32 == Int32.min { if decodedPower as! Int32 == Int32.min {
decodedPower = "-" decodedPower = "-"
} }
variableAdjust += 4 variableAdjust += 4
let retStringPtr: UnsafeMutableRawPointer = UnsafeMutableRawPointer.allocate(bytes: Int(decodedSize), alignedTo: 1) let retStringPtr: UnsafeMutableRawPointer = UnsafeMutableRawPointer.allocate(byteCount: Int(decodedSize), alignment: 1)
data.getBytes(retStringPtr, range: NSRange(location: variableAdjust, length: Int(decodedSize))) data.getBytes(retStringPtr, range: NSRange(location: variableAdjust, length: Int(decodedSize)))
var retString: String = String(cString: retStringPtr.assumingMemoryBound(to: UInt8.self)) var retString: String = String(cString: retStringPtr.assumingMemoryBound(to: UInt8.self))
retStringPtr.deallocate(bytes: Int(decodedSize), alignedTo: 1) retStringPtr.deallocate()
retString = retString.substring(to: retString.index(retString.startIndex, offsetBy: Int(decodedSize))) retString = String(retString[..<retString.index(retString.startIndex, offsetBy: Int(decodedSize))])
variableAdjust += Int(decodedSize) variableAdjust += Int(decodedSize)
guard decodedPower is Int32 else { guard decodedPower is Int32 else {
@ -227,17 +227,17 @@ class FileOperations: NSObject {
// 4 for Power // 4 for Power
// 1 for SNR // 1 for SNR
let retTimePtr: UnsafeMutableRawPointer = UnsafeMutableRawPointer.allocate(bytes: 3, alignedTo: 1) let retTimePtr: UnsafeMutableRawPointer = UnsafeMutableRawPointer.allocate(byteCount: 3, alignment: 1)
data.getBytes(retTimePtr, range: NSRange(location: variableAdjust, length: 3)) data.getBytes(retTimePtr, range: NSRange(location: variableAdjust, length: 3))
variableAdjust += 3 variableAdjust += 3
let encodedTime: UInt32 = retTimePtr.load(as: UInt32.self) let encodedTime: UInt32 = retTimePtr.load(as: UInt32.self)
let decodedTimeStamp = decodeTimestamp(stamp: encodedTime).0 let decodedTimeStamp = decodeTimestamp(stamp: encodedTime).0
let retPwrPtr: UnsafeMutableRawPointer = UnsafeMutableRawPointer.allocate(bytes: 4, alignedTo: 1) let retPwrPtr: UnsafeMutableRawPointer = UnsafeMutableRawPointer.allocate(byteCount: 4, alignment: 1)
data.getBytes(retPwrPtr, range: NSRange(location: variableAdjust, length: 4)) data.getBytes(retPwrPtr, range: NSRange(location: variableAdjust, length: 4))
var decodedPower: Any = retPwrPtr.load(as: Int32.self) var decodedPower: Any = retPwrPtr.load(as: Int32.self)
retPwrPtr.deallocate(bytes: 4, alignedTo: 1) retPwrPtr.deallocate()
if decodedPower as! Int32 == Int32.min { if decodedPower as! Int32 == Int32.min {
decodedPower = "-" decodedPower = "-"
} }

View File

@ -119,7 +119,7 @@ class FrequencyGraph: NSView {
// Get offset // Get offset
offset = 0 offset = 0
let time: String = data[point].components(separatedBy: ";")[0] let time: String = data[point].components(separatedBy: ";")[0]
let hour: Int = Int(time.substring(to: time.index(time.startIndex, offsetBy: 2)))! let hour: Int = Int(time[..<time.index(time.startIndex, offsetBy: 2)])!
let tensSeconds: Int = Int((time as NSString).substring(with: NSMakeRange(6, 1)))! let tensSeconds: Int = Int((time as NSString).substring(with: NSMakeRange(6, 1)))!
offset = ((hour*60 + Int((time as NSString).substring(with: NSMakeRange(3, 2)))!) * 6 + tensSeconds) * 2 offset = ((hour*60 + Int((time as NSString).substring(with: NSMakeRange(3, 2)))!) * 6 + tensSeconds) * 2
// Set offset // Set offset
@ -144,10 +144,10 @@ class FrequencyGraph: NSView {
// Set connection loss zones // Set connection loss zones
for loss in lastLossIndex..<dataLoss.count { for loss in lastLossIndex..<dataLoss.count {
let time1: String = data[point].components(separatedBy: ";")[0] let time1: String = data[point].components(separatedBy: ";")[0]
let hour1: Int = Int(time1.substring(to: time1.index(time1.startIndex, offsetBy: 2)))! let hour1: Int = Int(time1[..<time1.index(time1.startIndex, offsetBy: 2)])!
let minute1: Int = Int((time1 as NSString).substring(with: NSMakeRange(3, 2)))! let minute1: Int = Int((time1 as NSString).substring(with: NSMakeRange(3, 2)))!
let time2: String = dataLoss[loss] let time2: String = dataLoss[loss]
let hour2: Int = Int(time2.substring(to: time2.index(time2.startIndex, offsetBy: 2)))! let hour2: Int = Int(time2[..<time2.index(time2.startIndex, offsetBy: 2)])!
let minute2: Int = Int((time2 as NSString).substring(with: NSMakeRange(3, 2)))! let minute2: Int = Int((time2 as NSString).substring(with: NSMakeRange(3, 2)))!
if hour1 < hour2 { break } if hour1 < hour2 { break }

View File

@ -30,7 +30,7 @@ class GraphLoadOperation: Operation {
graph.data = FileOperations.loadUpstream(log: item.regularFileContents! as NSData)! graph.data = FileOperations.loadUpstream(log: item.regularFileContents! as NSData)!
} }
let keyString: String = item.filename!.components(separatedBy: " ")[1] let keyString: String = item.filename!.components(separatedBy: " ")[1]
graph.frequency = Double(keyString.substring(to: keyString.index(keyString.endIndex, offsetBy: -4)))! / 1000000 graph.frequency = Double(keyString[..<keyString.index(keyString.endIndex, offsetBy: -4)])! / 1000000
graph.initView(operation: self) graph.initView(operation: self)
} }
} }

View File

@ -44,7 +44,7 @@
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>2.1</string> <string>2.1</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>491</string> <string>493</string>
<key>LSApplicationCategoryType</key> <key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string> <string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key> <key>LSMinimumSystemVersion</key>

View File

@ -1,2 +1,2 @@
version 2.1 version 2.1
build 491 build 493