Skip to content

Commit

Permalink
Remake if pyramids to switch pattern matching
Browse files Browse the repository at this point in the history
  • Loading branch information
savelichalex committed Sep 3, 2016
1 parent 003fbfd commit edf5a99
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 58 deletions.
4 changes: 0 additions & 4 deletions SerialsManager.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
4AE5B06E316A1176A11BC77E /* Pods_SerialsManager.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 06904BF05179C14EA0F573D1 /* Pods_SerialsManager.framework */; };
8421FFD81D7ACC4000DC2CA3 /* RemoteDB.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8421FFD71D7ACC4000DC2CA3 /* RemoteDB.swift */; };
8421FFDA1D7ACEB900DC2CA3 /* DropboxDB.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8421FFD91D7ACEB900DC2CA3 /* DropboxDB.swift */; };
842D06511D60DE610077E766 /* AppConfig.plist in Resources */ = {isa = PBXBuildFile; fileRef = 842D06501D60DE610077E766 /* AppConfig.plist */; };
8430721E1D2A6F4300C08568 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8430721D1D2A6F4300C08568 /* AppDelegate.swift */; };
843072201D2A6F4300C08568 /* SerialsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8430721F1D2A6F4300C08568 /* SerialsViewController.swift */; };
843072221D2A6F4300C08568 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 843072211D2A6F4300C08568 /* Assets.xcassets */; };
Expand All @@ -28,7 +27,6 @@
71CBF9B5B8108202D74EF33C /* Pods-SerialsManager.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SerialsManager.release.xcconfig"; path = "Pods/Target Support Files/Pods-SerialsManager/Pods-SerialsManager.release.xcconfig"; sourceTree = "<group>"; };
8421FFD71D7ACC4000DC2CA3 /* RemoteDB.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RemoteDB.swift; sourceTree = "<group>"; };
8421FFD91D7ACEB900DC2CA3 /* DropboxDB.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DropboxDB.swift; sourceTree = "<group>"; };
842D06501D60DE610077E766 /* AppConfig.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = AppConfig.plist; sourceTree = "<group>"; };
8430721A1D2A6F4200C08568 /* SerialsManager.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SerialsManager.app; sourceTree = BUILT_PRODUCTS_DIR; };
8430721D1D2A6F4300C08568 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
8430721F1D2A6F4300C08568 /* SerialsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SerialsViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -96,7 +94,6 @@
8421FFD61D7ACB7200DC2CA3 /* Services */,
845131EC1D76FFFA00B76B1E /* SecretConfig.swift */,
845131F11D773A8A00B76B1E /* config.yml.sample */,
842D06501D60DE610077E766 /* AppConfig.plist */,
84E1828A1D5215DF003A6FB6 /* Main.storyboard */,
8430721D1D2A6F4300C08568 /* AppDelegate.swift */,
8430721F1D2A6F4300C08568 /* SerialsViewController.swift */,
Expand Down Expand Up @@ -180,7 +177,6 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
842D06511D60DE610077E766 /* AppConfig.plist in Resources */,
84E1828B1D5215DF003A6FB6 /* Main.storyboard in Resources */,
843072221D2A6F4300C08568 /* Assets.xcassets in Resources */,
845131F21D773A8A00B76B1E /* config.yml.sample in Resources */,
Expand Down
12 changes: 0 additions & 12 deletions SerialsManager/AppConfig.plist

This file was deleted.

9 changes: 0 additions & 9 deletions SerialsManager/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
)
Dropbox.authorizedClient = client
DropboxClient.sharedClient = client
client.users.getCurrentAccount().response { response, error in
if let account = response {
print("Hello \(account.name.givenName)")
} else {
let errorMirror = Mirror(reflecting: error)
print(errorMirror.subjectType)
print(error)
}
}

serialsService.getSerials().then { serials -> Void in
self.serialsVC?.serials = serials
Expand Down
54 changes: 21 additions & 33 deletions SerialsManager/SerialsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,45 +65,29 @@ class SerialsViewController: NSViewController {
extension SerialsViewController: NSOutlineViewDataSource {

func outlineView(outlineView: NSOutlineView, numberOfChildrenOfItem item: AnyObject?) -> Int {
if let i = item as? Serial {
if i.seasons != nil {
return i.seasons!.count
} else {
return 0
}
} else if let i = item as? Season {
if i.chapters != nil {
return i.chapters!.count
} else {
return 0
}
} else if ((item as? Chapter) != nil) {
return 0
switch item {
case let i as Serial: return i.seasons != nil ? i.seasons!.count : 0
case let i as Season: return i.chapters != nil ? i.chapters!.count : 0
case is Chapter: return 0
default: return serials != nil ? serials!.count : 0
}

return serials?.count ?? 0
}

func outlineView(outlineView: NSOutlineView, child index: Int, ofItem item: AnyObject?) -> AnyObject {
if let i = item as? Serial {
return (i.seasons?[index])!
} else if let i = item as? Season {
return (i.chapters?[index])!
switch item {
case let i as Serial: return (i.seasons?[index])!
case let i as Season: return (i.chapters?[index])!
default: return (serials?[index])!
}

return (serials?[index])!
}

func outlineView(outlineView: NSOutlineView, isItemExpandable item: AnyObject) -> Bool {
if let i = item as? Serial {
return i.seasons != nil
} else if let i = item as? Season {
return i.chapters != nil
} else if ((item as? Chapter) != nil) {
return false
switch item {
case let i as Serial: return i.seasons != nil ? i.seasons!.count > 0 : false
case let i as Season: return i.chapters != nil ? i.chapters!.count > 0 : false
case is Chapter: return false
default: return false
}

return false
}

}
Expand All @@ -112,24 +96,28 @@ extension SerialsViewController: NSOutlineViewDelegate {
func outlineView(outlineView: NSOutlineView, viewForTableColumn tableColumn: NSTableColumn?, item: AnyObject) -> NSView? {
var view: NSTableCellView?

if let i = item as? Serial {
switch item {
case let i as Serial:
view = outlineView.makeViewWithIdentifier("SerialItemCell", owner: self) as? NSTableCellView
if let textField = view?.textField {
textField.stringValue = "Serial: " + i.data.title
textField.sizeToFit()
}
} else if let i = item as? Season {
break
case let i as Season:
view = outlineView.makeViewWithIdentifier("SerialItemCell", owner: self) as? NSTableCellView
if let textField = view?.textField {
textField.stringValue = "Season: " + i.data.title
textField.sizeToFit()
}
} else if let i = item as? Chapter {
break
case let i as Chapter:
view = outlineView.makeViewWithIdentifier("SerialItemCell", owner: self) as? NSTableCellView
if let textField = view?.textField {
textField.stringValue = "Chapter " + (i.data.title ?? "unknown")
textField.sizeToFit()
}
default: ()
}

return view
Expand Down

0 comments on commit edf5a99

Please sign in to comment.