Skip to content

Commit

Permalink
Merge pull request #25 from Electrode-iOS/swift3
Browse files Browse the repository at this point in the history
migrate to Swift 3
  • Loading branch information
angelodipaolo authored Nov 14, 2016
2 parents f3f6cf0 + 5281e6b commit cd4bf87
Show file tree
Hide file tree
Showing 15 changed files with 126 additions and 120 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: objective-c
osx_image: xcode8
osx_image: xcode8.1

script:
- xcodebuild -project ELLog.xcodeproj -scheme ELLog -sdk iphonesimulator test -destination 'platform=iOS Simulator,name=iPhone 6,OS=10.0'
- xcodebuild -project ELLog.xcodeproj -scheme ELLog -sdk iphonesimulator test -destination 'platform=iOS Simulator,name=iPhone 6,OS=10.0' CODE_SIGNING_REQUIRED=NO
30 changes: 21 additions & 9 deletions ELLog.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -270,16 +270,19 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0720;
LastUpgradeCheck = 0800;
LastUpgradeCheck = 0810;
ORGANIZATIONNAME = WalmartLabs;
TargetAttributes = {
CA24104F1AF966F600AA4410 = {
LastSwiftMigration = 0810;
};
CA8D47BA1AAE6FF50028B74D = {
CreatedOnToolsVersion = 6.3;
LastSwiftMigration = 0800;
LastSwiftMigration = 0810;
};
CA8D47C51AAE6FF50028B74D = {
CreatedOnToolsVersion = 6.3;
LastSwiftMigration = 0800;
LastSwiftMigration = 0810;
};
};
};
Expand Down Expand Up @@ -396,6 +399,7 @@
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -417,6 +421,7 @@
PRODUCT_NAME = ELLog;
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down Expand Up @@ -523,6 +528,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -539,7 +545,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -548,6 +554,7 @@
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = NO;
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -564,14 +571,15 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.walmartlabs.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
};
name = Release;
};
CA8D47D51AAE6FF50028B74D /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/ELLogTests",
Expand All @@ -582,14 +590,15 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "ELLogTests/ELLogTests-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
};
name = Debug;
};
CA8D47D61AAE6FF50028B74D /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/ELLogTests",
Expand All @@ -599,7 +608,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.walmartlabs.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "ELLogTests/ELLogTests-Bridging-Header.h";
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down Expand Up @@ -658,6 +667,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -675,14 +685,15 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
};
name = QADeployment;
};
DB5F6F731C77CD910048EA81 /* QADeployment */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/ELLog",
Expand All @@ -698,7 +709,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "ELLogTests/ELLogTests-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
};
name = QADeployment;
};
Expand Down Expand Up @@ -728,6 +739,7 @@
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
};
name = QADeployment;
};
Expand Down
2 changes: 1 addition & 1 deletion ELLog.xcodeproj/xcshareddata/xcschemes/ELLog.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0800"
LastUpgradeVersion = "0810"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion ELLog.xcodeproj/xcshareddata/xcschemes/ELLog_osx.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0800"
LastUpgradeVersion = "0810"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class LogCrashlyticsDestination: ELLog.LogDestinationBase {
showTimestamp = true
}

public override func log(detail: ELLog.LogDetail) {
public override func log(_ detail: ELLog.LogDetail) {
var output: String = ""

if showLogLevel {
Expand All @@ -58,12 +58,12 @@ public class LogCrashlyticsDestination: ELLog.LogDestinationBase {

if showTimestamp {
if let date = detail.date {
output += "[\(dateFormatter.stringFromDate(date))] "
output += "[\(dateFormatter.string(from: date))] "
}
}

if showCaller {
if let filename = detail.filename, line = detail.line, function = detail.function {
if let filename = detail.filename, let line = detail.line, let function = detail.function {
output += "(\(function), \((filename as NSString).lastPathComponent):\(line)) "
}
}
Expand All @@ -77,4 +77,3 @@ public class LogCrashlyticsDestination: ELLog.LogDestinationBase {
CLSLogv("%@", getVaList([output]))
}
}

12 changes: 5 additions & 7 deletions ELLog/Destinations/LogConsoleDestination.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

/**
LogConsoleDestination provides output to the console via NSLog.
LogConsoleDestination provides output to the console via NSLog.

The default behavior is:

Expand All @@ -27,19 +27,17 @@ public class LogConsoleDestination: LogDestinationBase {
showLogLevel = true
showTimestamp = false
}

public convenience init() {
self.init(level: .Debug)
}
public override func log(detail: LogDetail) {

public override func log(_ detail: LogDetail) {
let logString = formatted(detail)
// You must pass NSLog a format string and then pass the Swift string as a vaArg
// or the code will crash when it tries to format %f in the Swift string
NSLog("%@", logString)
}

}


}

31 changes: 16 additions & 15 deletions ELLog/Destinations/LogTextfileDestination.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ The default behavior is:
@objc(ELLogTextfileDestination)
public class LogTextfileDestination: LogDestinationBase {

private let filename: String
private let outputStream: NSOutputStream?
fileprivate let filename: String
fileprivate let outputStream: OutputStream?

public init(filename: String) {
self.filename = filename

let folder = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0]
let path = (folder as NSString).stringByAppendingPathComponent(filename)
outputStream = NSOutputStream(toFileAtPath: path, append: true)
let folder = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
let path = (folder as NSString).appendingPathComponent(filename)
outputStream = OutputStream(toFileAtPath: path, append: true)

if let outputStream = outputStream {
outputStream.open()
Expand All @@ -39,7 +39,7 @@ public class LogTextfileDestination: LogDestinationBase {
}

super.init(level: .Debug)

showCaller = false
showLogLevel = true
showTimestamp = true
Expand All @@ -49,23 +49,24 @@ public class LogTextfileDestination: LogDestinationBase {
outputStream?.close()
}

public override func log(detail: LogDetail) {
public override func log(_ detail: LogDetail) {

if outputStream == nil {
return
}

outputStream?.write(formatted(detail))
}
}


extension NSOutputStream {
extension OutputStream {

func write(string: String, encoding: NSStringEncoding = NSUTF8StringEncoding, allowLossyConversion: Bool = true) -> Int {
if let data = string.dataUsingEncoding(encoding, allowLossyConversion: allowLossyConversion) {
var bytes = UnsafePointer<UInt8>(data.bytes)
var bytesRemaining = data.length
@discardableResult
func write(_ string: String, encoding: String.Encoding = String.Encoding.utf8, allowLossyConversion: Bool = true) -> Int {
if let data = string.data(using: encoding, allowLossyConversion: allowLossyConversion) {
var bytes = (data as NSData).bytes.bindMemory(to: UInt8.self, capacity: data.count)
var bytesRemaining = data.count
var totalBytesWritten = 0

while bytesRemaining > 0 {
Expand All @@ -81,8 +82,8 @@ extension NSOutputStream {

return totalBytesWritten
}

return -1
}

}
16 changes: 8 additions & 8 deletions ELLog/Extensions/NSThread+ELLog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ minimize dependencies. It is being renamed so that it can be used as source in p
frameworks, e.g. command line apps.
*/

extension NSThread {
extension Thread {

static private let formatterCacheKey = "ELLog.Console.dateFormatter_ELLog"
static fileprivate let formatterCacheKey = "ELLog.Console.dateFormatter_ELLog"

class func dateFormatter_ELLog(format: String, locale: NSLocale = NSLocale.currentLocale()) -> NSDateFormatter {
let threadDictionary = NSThread.currentThread().threadDictionary
class func dateFormatter_ELLog(_ format: String, locale: Locale = Locale.current) -> DateFormatter {
let threadDictionary = Thread.current.threadDictionary

var cache: Dictionary<String, NSDateFormatter>? = threadDictionary.objectForKey(formatterCacheKey) as? Dictionary<String, NSDateFormatter>
var cache: Dictionary<String, DateFormatter>? = threadDictionary.object(forKey: formatterCacheKey) as? Dictionary<String, DateFormatter>
if cache == nil {
cache = Dictionary<String, NSDateFormatter>()
cache = Dictionary<String, DateFormatter>()
}

let formatKey = "\(format)_\(locale.localeIdentifier)"
let formatKey = "\(format)_\(locale.identifier)"
if let existing = cache?[formatKey] {
return existing
}

let result = NSDateFormatter()
let result = DateFormatter()
result.locale = locale
result.dateFormat = format
cache?[formatKey] = result
Expand Down
2 changes: 1 addition & 1 deletion ELLog/Log.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Convenicen function to post logs to the default logging mechanism.
- parameter level: The log level.
- parameter message: The message to display.
*/
public func log(level: LogLevel, _ message: String) {
public func log(_ level: LogLevel, _ message: String) {
Logger.defaultInstance.log(level, message: message)
}

Loading

0 comments on commit cd4bf87

Please sign in to comment.