add optionals as return value

This commit is contained in:
Felix Förtsch
2018-10-11 12:58:02 +02:00
parent f09ee87b45
commit f3950041c7
7 changed files with 79 additions and 67 deletions

View File

@@ -11,15 +11,16 @@ import SwiftSoup
class MatchesAPI {
func fetchMatches(for game: String) -> [Match] {
func fetchMatches(for game: String) -> [Match]? {
let games = ["dota2", "starcraft", "starcraft2", "heroes", "counterstrike", "rocketleague", "rainbowsix", "overwatch"]
if !games.contains(game) { return [Match]() }
let data = fetchData(for: game)
let matches = extractMatches(from: data)
return matches
if !games.contains(game) { return nil }
if let data = fetchData(for: game) {
return extractMatches(from: data)
}
return nil
}
private func fetchData(for game: String) -> String {
private func fetchData(for game: String) -> String? {
let url = constructURL(for: game)
// DispatchQueue.global().async { [unowned self] in
if let url = URL(string: url) {
@@ -28,10 +29,10 @@ class MatchesAPI {
}
}
// }
return ""
return nil
}
private func extractMatches(from data: String) -> [Match] {
private func extractMatches(from data: String) -> [Match]? {
var tmp = data.replacingOccurrences(of: "\\n", with: "")
tmp = tmp.replacingOccurrences(of: "\\", with: "")
@@ -61,10 +62,10 @@ class MatchesAPI {
return matches
} catch Exception.Error(_, _) {
print("")
return [Match]()
return nil
} catch {
print("")
return [Match]()
return nil
}
}

View File

@@ -8,7 +8,7 @@
import Cocoa
class StatusBarController: NSObject {
class StatusBarController: NSObject, NSMenuDelegate {
@IBOutlet weak var statusBar: NSMenu!
let statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
let matchesAPI = MatchesAPI()
@@ -27,17 +27,18 @@ class StatusBarController: NSObject {
statusBar.addItem(withTitle: "Refresh", action: #selector(generateMenu), keyEquivalent: "")
statusBar.addItem(NSMenuItem.separator())
matches = matchesAPI.fetchMatches(for: "dota2")
for match in matches {
let myItem = NSMenuItem(title: match.league, action: nil, keyEquivalent: "")
statusBar.addItem(myItem)
if let matches = matchesAPI.fetchMatches(for: "dota2") {
for match in matches {
let myItem = NSMenuItem(title: match.league, action: nil, keyEquivalent: "")
statusBar.addItem(myItem)
}
statusBar.addItem(NSMenuItem.separator())
statusBar.addItem(withTitle: "Quit", action: #selector(quitClicked), keyEquivalent: "")
}
statusBar.addItem(NSMenuItem.separator())
statusBar.addItem(withTitle: "Quit", action: #selector(quitClicked), keyEquivalent: "")
}
@objc func quitClicked() {
@objc func quitClicked(_ sender: NSMenuItem) {
NSApplication.shared.terminate(self)
}
}

View File

@@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objectVersion = 46;
objects = {
/* Begin PBXBuildFile section */
@@ -84,7 +84,7 @@
/* Begin PBXFileReference section */
007D3C79D0CF0BE6FF2556B8846850EA /* ArrayExt.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = ArrayExt.swift; path = Sources/ArrayExt.swift; sourceTree = "<group>"; };
0AEE3159671F061357B3988820992AB3 /* DataUtil.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = DataUtil.swift; path = Sources/DataUtil.swift; sourceTree = "<group>"; };
0BCEAB189E2E70EA4D235E29DE325877 /* Pods_LiquipediaMenu.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; name = Pods_LiquipediaMenu.framework; path = "Pods-LiquipediaMenu.framework"; sourceTree = BUILT_PRODUCTS_DIR; };
0BCEAB189E2E70EA4D235E29DE325877 /* Pods_LiquipediaMenu.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_LiquipediaMenu.framework; sourceTree = BUILT_PRODUCTS_DIR; };
0D016381C9FBB25D558EF8C55592E6D7 /* Pods-LiquipediaMenu.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = "Pods-LiquipediaMenu.release.xcconfig"; sourceTree = "<group>"; };
0FD1D556718F7F72612DBB852C53A11A /* Pods-LiquipediaMenu-acknowledgements.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = "Pods-LiquipediaMenu-acknowledgements.plist"; sourceTree = "<group>"; };
1105B1B4BC31DB983BC3200EE5BC75E4 /* Pods-LiquipediaMenu-resources.sh */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.script.sh; path = "Pods-LiquipediaMenu-resources.sh"; sourceTree = "<group>"; };
@@ -124,7 +124,7 @@
8DC8E1146AEDC184675DE3BFD3225260 /* Pods-LiquipediaMenu-umbrella.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = "Pods-LiquipediaMenu-umbrella.h"; sourceTree = "<group>"; };
9161B06CA12DCBC5B4DD06E44D91CB1E /* SwiftSoup.modulemap */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.module; path = SwiftSoup.modulemap; sourceTree = "<group>"; };
91F70944F55E23CA9F1AA9C3F5E543E6 /* Attribute.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = Attribute.swift; path = Sources/Attribute.swift; sourceTree = "<group>"; };
93A4A3777CF96A4AAC1D13BA6DCCEA73 /* Podfile */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; includeInIndex = 1; lastKnownFileType = text; name = Podfile; path = ../Podfile; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.ruby; };
93A4A3777CF96A4AAC1D13BA6DCCEA73 /* Podfile */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; includeInIndex = 1; name = Podfile; path = ../Podfile; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.ruby; };
97B9BE6A120CF124AC947FD213458C40 /* TextNode.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = TextNode.swift; path = Sources/TextNode.swift; sourceTree = "<group>"; };
9A1C5C6357B71AF5FED442F9E3F6C77C /* XmlDeclaration.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = XmlDeclaration.swift; path = Sources/XmlDeclaration.swift; sourceTree = "<group>"; };
9CF8CDB58FEC3DF8E9E9C788D7986C1A /* Evaluator.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = Evaluator.swift; path = Sources/Evaluator.swift; sourceTree = "<group>"; };
@@ -151,7 +151,7 @@
DF0F2496EE4A25ED1BC61246533BA9DB /* Exception.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = Exception.swift; path = Sources/Exception.swift; sourceTree = "<group>"; };
DF428FC7C7A6555B2B02D8E238C8D8F2 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/Cocoa.framework; sourceTree = DEVELOPER_DIR; };
E06D59F71CA62BD4EDB256AE1B680688 /* Pods-LiquipediaMenu.modulemap */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.module; path = "Pods-LiquipediaMenu.modulemap"; sourceTree = "<group>"; };
E11AE56DD631B971DAE87B4973B29116 /* SwiftSoup.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; name = SwiftSoup.framework; path = SwiftSoup.framework; sourceTree = BUILT_PRODUCTS_DIR; };
E11AE56DD631B971DAE87B4973B29116 /* SwiftSoup.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftSoup.framework; sourceTree = BUILT_PRODUCTS_DIR; };
E206093B8CFA7D169994473FF3E06161 /* TokeniserState.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = TokeniserState.swift; path = Sources/TokeniserState.swift; sourceTree = "<group>"; };
E7E9CAE847A747B6035DD7897522E6B3 /* StructuralEvaluator.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = StructuralEvaluator.swift; path = Sources/StructuralEvaluator.swift; sourceTree = "<group>"; };
F2005E18A17D8432D600D482946D4853 /* TreeBuilder.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = TreeBuilder.swift; path = Sources/TreeBuilder.swift; sourceTree = "<group>"; };
@@ -289,7 +289,6 @@
579FD986C85730D8DF75FB2A4152B0BD /* XmlTreeBuilder.swift */,
2585406248F42708599608914EA31A98 /* Support Files */,
);
name = SwiftSoup;
path = SwiftSoup;
sourceTree = "<group>";
};
@@ -393,7 +392,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0930;
LastUpgradeCheck = 0930;
LastUpgradeCheck = 1000;
};
buildConfigurationList = 2D8E8EC45A3A1A1D94AE762CB5028504 /* Build configuration list for PBXProject "Pods" */;
compatibilityVersion = "Xcode 3.2";
@@ -517,11 +516,7 @@
FRAMEWORK_VERSION = A;
INFOPLIST_FILE = "Target Support Files/Pods-LiquipediaMenu/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
"@loader_path/Frameworks",
);
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
MACH_O_TYPE = staticlib;
MACOSX_DEPLOYMENT_TARGET = 10.13;
MODULEMAP_FILE = "Target Support Files/Pods-LiquipediaMenu/Pods-LiquipediaMenu.modulemap";
@@ -558,11 +553,7 @@
FRAMEWORK_VERSION = A;
INFOPLIST_FILE = "Target Support Files/Pods-LiquipediaMenu/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
"@loader_path/Frameworks",
);
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
MACH_O_TYPE = staticlib;
MACOSX_DEPLOYMENT_TARGET = 10.13;
MODULEMAP_FILE = "Target Support Files/Pods-LiquipediaMenu/Pods-LiquipediaMenu.modulemap";
@@ -598,11 +589,7 @@
GCC_PREFIX_HEADER = "Target Support Files/SwiftSoup/SwiftSoup-prefix.pch";
INFOPLIST_FILE = "Target Support Files/SwiftSoup/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
"@loader_path/Frameworks",
);
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.10;
MODULEMAP_FILE = "Target Support Files/SwiftSoup/SwiftSoup.modulemap";
PRODUCT_MODULE_NAME = SwiftSoup;
@@ -636,11 +623,7 @@
GCC_PREFIX_HEADER = "Target Support Files/SwiftSoup/SwiftSoup-prefix.pch";
INFOPLIST_FILE = "Target Support Files/SwiftSoup/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
"@loader_path/Frameworks",
);
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.10;
MODULEMAP_FILE = "Target Support Files/SwiftSoup/SwiftSoup.modulemap";
PRODUCT_MODULE_NAME = SwiftSoup;
@@ -772,6 +755,7 @@
MTL_ENABLE_DEBUG_INFO = NO;
PRODUCT_NAME = "$(TARGET_NAME)";
STRIP_INSTALLED_PRODUCT = NO;
SWIFT_COMPILATION_MODE = wholemodule;
SYMROOT = "${SRCROOT}/../build";
};
name = Release;

View File

@@ -1,36 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0930"
LastUpgradeVersion = "1000"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForAnalyzing = "YES"
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES">
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "87305DDAD60744B392C628F78F26819A"
BuildableName = "Pods_LiquipediaMenu.framework"
BlueprintName = "Pods-LiquipediaMenu"
ReferencedContainer = "container:Pods.xcodeproj"
BuildableName = "Pods-LiquipediaMenu.framework">
ReferencedContainer = "container:Pods.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"
@@ -38,17 +41,25 @@
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
buildConfiguration = "Debug"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "87305DDAD60744B392C628F78F26819A"
BuildableName = "Pods_LiquipediaMenu.framework"
BlueprintName = "Pods-LiquipediaMenu"
ReferencedContainer = "container:Pods.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES"
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES">
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">

View File

@@ -1,36 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0930"
LastUpgradeVersion = "1000"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForAnalyzing = "YES"
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES">
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D47F756842B991E029C8EBA0479AE68A"
BuildableName = "SwiftSoup.framework"
BlueprintName = "SwiftSoup"
ReferencedContainer = "container:Pods.xcodeproj"
BuildableName = "SwiftSoup.framework">
ReferencedContainer = "container:Pods.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"
@@ -38,17 +41,25 @@
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
buildConfiguration = "Debug"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D47F756842B991E029C8EBA0479AE68A"
BuildableName = "SwiftSoup.framework"
BlueprintName = "SwiftSoup"
ReferencedContainer = "container:Pods.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES"
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES">
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">

View File

@@ -8,11 +8,15 @@
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>0</integer>
</dict>
<key>SwiftSoup.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>1</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>