Navigation Menu

Skip to content

Commit

Permalink
Converts to Swift2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ricobeck committed Aug 27, 2015
1 parent 9dceb94 commit e99cb0d
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 35 deletions.
4 changes: 4 additions & 0 deletions Swell.xcodeproj/project.pbxproj
Expand Up @@ -353,6 +353,8 @@
DF0A054B1954EC4800E35A15 /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftMigration = 0700;
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0600;
ORGANIZATIONNAME = "Minute Apps LLC";
TargetAttributes = {
Expand Down Expand Up @@ -767,6 +769,7 @@
1DED2DC71B11C210006DF7E7 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
1DED2DC81B11C210006DF7E7 /* Build configuration list for PBXNativeTarget "Swell-OSXTests" */ = {
isa = XCConfigurationList;
Expand All @@ -775,6 +778,7 @@
1DED2DCA1B11C210006DF7E7 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
DF0A054E1954EC4800E35A15 /* Build configuration list for PBXProject "Swell" */ = {
isa = XCConfigurationList;
Expand Down
17 changes: 10 additions & 7 deletions Swell.xcodeproj/xcshareddata/xcschemes/Swell-OSX.xcscheme
Expand Up @@ -15,35 +15,38 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "1DED2DB11B11C210006DF7E7"
BuildableName = "Swell-OSX.framework"
BuildableName = "Swell.framework"
BlueprintName = "Swell-OSX"
ReferencedContainer = "container:Swell.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "1DED2DB11B11C210006DF7E7"
BuildableName = "Swell-OSX.framework"
BuildableName = "Swell.framework"
BlueprintName = "Swell-OSX"
ReferencedContainer = "container:Swell.xcodeproj">
</BuildableReference>
Expand All @@ -52,16 +55,16 @@
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "1DED2DB11B11C210006DF7E7"
BuildableName = "Swell-OSX.framework"
BuildableName = "Swell.framework"
BlueprintName = "Swell-OSX"
ReferencedContainer = "container:Swell.xcodeproj">
</BuildableReference>
Expand Down
10 changes: 5 additions & 5 deletions Swell/Formatter.swift
Expand Up @@ -140,9 +140,9 @@ public class FlexFormatter: LogFormatter {
func getFunctionFormat(function: String) -> String {
var result = function;
if (result.hasPrefix("Optional(")) {
let len = count("Optional(")
let start = advance(result.startIndex, len)
let end = advance(result.endIndex, -len)
let len = "Optional(".characters.count
let start = result.startIndex.advancedBy(len)
let end = result.endIndex.advancedBy(-len)
let range = start..<end
result = result[range]
}
Expand All @@ -155,7 +155,7 @@ public class FlexFormatter: LogFormatter {
public func formatLog<T>(logger: Logger, level: LogLevel, @autoclosure message givenMessage: () -> T,
filename: String?, line: Int?, function: String?) -> String {
var logMessage = ""
for (index, part) in enumerate(format) {
for (index, part) in format.enumerate() {
switch part {
case .MESSAGE:
let message = givenMessage()
Expand Down Expand Up @@ -203,7 +203,7 @@ public class FlexFormatter: LogFormatter {

public func description() -> String {
var desc = ""
for (index, part) in enumerate(format) {
for (index, part) in format.enumerate() {
switch part {
case .MESSAGE: desc += "MESSAGE"
case .NAME: desc += "NAME"
Expand Down
2 changes: 1 addition & 1 deletion Swell/LogLevel.swift
Expand Up @@ -41,7 +41,7 @@ public struct LogLevel {
}

static func create(level: PredefinedLevel, name: String, label: String) -> LogLevel {
var result = LogLevel(level:level.rawValue, name: name, label: label);
let result = LogLevel(level:level.rawValue, name: name, label: label);
//let key =
allLevels[result.level] = result
return result
Expand Down
4 changes: 2 additions & 2 deletions Swell/LogLocation.swift
Expand Up @@ -38,7 +38,7 @@ public class ConsoleLocation: LogLocation {

public func log(@autoclosure message: () -> String) {
if enabled {
println(message())
print(message())
}
}

Expand All @@ -64,7 +64,7 @@ public class FileLocation: LogLocation {
var fileHandle: NSFileHandle?

public class func getInstance(filename: String) -> LogLocation {
var temp = internalFileLocationDictionary[filename]
let temp = internalFileLocationDictionary[filename]
if let result = temp {
return result
} else {
Expand Down
2 changes: 1 addition & 1 deletion Swell/LogSelector.swift
Expand Up @@ -96,7 +96,7 @@ public class LogSelector {
let temp = string.componentsSeparatedByString(",")
for s: String in temp {
// 'countElements(s)' returns s.length
if (count(s) > 0) {
if (s.characters.count > 0) {
result.append(s)
}
//if (s.lengthOfBytesUsingEncoding(NSUTF8StringEncoding) > 0) {
Expand Down
2 changes: 1 addition & 1 deletion Swell/Logger.swift
Expand Up @@ -7,7 +7,7 @@
//


@objc

public class Logger {

let name: String
Expand Down
36 changes: 18 additions & 18 deletions Swell/Swell.swift
Expand Up @@ -33,7 +33,7 @@ struct LoggerConfiguration {
let globalSwell = Swell();


@objc

public class Swell {

lazy var swellLogger: Logger = {
Expand Down Expand Up @@ -169,7 +169,7 @@ public class Swell {
/// Returns the Logger instance configured for a given logger name.
/// Use this to get Logger instances for use in classes.
func getLogger(name: String) -> Logger {
var logger = allLoggers[name]
let logger = allLoggers[name]
if (logger != nil) {
return logger!
} else {
Expand All @@ -184,11 +184,11 @@ public class Swell {
/// Use getLogger(name) to get a logger for normal use.
func createLogger(name: String) -> Logger {
let config = getConfigurationForLoggerName(name)
var result = Logger(name: name, level: config.level!, formatter: config.formatter!, logLocation: config.locations[0])
let result = Logger(name: name, level: config.level!, formatter: config.formatter!, logLocation: config.locations[0])

// Now we need to handle potentially > 1 locations
if config.locations.count > 1 {
for (index,location) in enumerate(config.locations) {
for (index,location) in config.locations.enumerate() {
if (index > 0) {
result.locations += [location]
}
Expand Down Expand Up @@ -257,7 +257,7 @@ public class Swell {

func readConfigurationFile() {

var filename: String? = NSBundle.mainBundle().pathForResource("Swell", ofType: "plist");
let filename: String? = NSBundle.mainBundle().pathForResource("Swell", ofType: "plist");

var dict: NSDictionary? = nil;
if let bundleFilename = filename {
Expand All @@ -267,7 +267,7 @@ public class Swell {

//-----------------------------------------------------------------
// Read the root configuration
var configuration = readLoggerPList("ROOT", map: map);
let configuration = readLoggerPList("ROOT", map: map);
//Swell.info("map: \(map)");

// Now any values configured, we put in our root configuration
Expand All @@ -288,7 +288,7 @@ public class Swell {
if (!key.hasPrefix("SWL")) {
let value: AnyObject? = map[key]
if let submap: Dictionary<String, AnyObject> = value as? Dictionary<String, AnyObject> {
var subconfig = readLoggerPList(key, map: submap)
let subconfig = readLoggerPList(key, map: submap)
applyLoggerConfiguration(key, configuration: subconfig)
}
}
Expand Down Expand Up @@ -412,7 +412,7 @@ public class Swell {
configuration.formatter = getConfiguredFlexFormatter(configuration, item: value);
} else {
let formatKey = getFormatKey(map)
println("formatKey=\(formatKey)")
print("formatKey=\(formatKey)")
}
}

Expand All @@ -428,23 +428,23 @@ public class Swell {

func getConfiguredQuickFormatter(configuration: LoggerConfiguration, item: AnyObject) -> LogFormatter? {
if let formatString: String = item as? String {
var formatter = QuickFormatter.logFormatterForString(formatString)
let formatter = QuickFormatter.logFormatterForString(formatString)
return formatter
}
return nil
}

func getConfiguredFlexFormatter(configuration: LoggerConfiguration, item: AnyObject) -> LogFormatter? {
if let formatString: String = item as? String {
var formatter = FlexFormatter.logFormatterForString(formatString);
let formatter = FlexFormatter.logFormatterForString(formatString);
return formatter
}
return nil
}

func getConfiguredFileLocation(configuration: LoggerConfiguration, item: AnyObject) -> LogLocation? {
if let filename: String = item as? String {
var logLocation = FileLocation.getInstance(filename);
let logLocation = FileLocation.getInstance(filename);
return logLocation
}
return nil
Expand All @@ -462,7 +462,7 @@ public class Swell {
for value in values {
if (value == "file") {
// handle file name
var filenameValue: AnyObject? = map["SWLLocationFilename"]
let filenameValue: AnyObject? = map["SWLLocationFilename"]
if let filename: AnyObject = filenameValue {
let fileLocation = getConfiguredFileLocation(configuration, item: filename);
if fileLocation != nil {
Expand All @@ -472,7 +472,7 @@ public class Swell {
} else if (value == "console") {
results += [ConsoleLocation.getInstance()]
} else {
println("Unrecognized location value in Swell.plist: '\(value)'")
print("Unrecognized location value in Swell.plist: '\(value)'")
}
}
}
Expand All @@ -482,8 +482,8 @@ public class Swell {
func getFormatKey(map: Dictionary<String, AnyObject>) -> String? {
for (key, value) in map {
if ((key.hasPrefix("SWL")) && (key.hasSuffix("Format"))) {
let start = advance(key.startIndex, 3)
let end = advance(key.endIndex, -6)
let start = key.startIndex.advancedBy(3)
let end = key.endIndex.advancedBy(-6)
let result: String = key[start..<end]
return result
}
Expand All @@ -496,9 +496,9 @@ public class Swell {
func getFunctionFormat(function: String) -> String {
var result = function;
if (result.hasPrefix("Optional(")) {
let len = count("Optional(")
let start = advance(result.startIndex, len)
let end = advance(result.endIndex, -len)
let len = "Optional(".characters.count
let start = result.startIndex.advancedBy(len)
let end = result.endIndex.advancedBy(-len)
let range = start..<end
result = result[range]
}
Expand Down

0 comments on commit e99cb0d

Please sign in to comment.