Skip to content

Commit

Permalink
Update to Swift 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Chriskuei committed Sep 19, 2016
1 parent 3f4781f commit 8f2bd76
Show file tree
Hide file tree
Showing 152 changed files with 39,230 additions and 28,493 deletions.
28 changes: 23 additions & 5 deletions Bon.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
832444FE1CDF2D5C0031CFE0 /* BonUserDefaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 832444FD1CDF2D5C0031CFE0 /* BonUserDefaults.swift */; };
832445021CDF2DB80031CFE0 /* BIT.swift in Sources */ = {isa = PBXBuildFile; fileRef = 832445001CDF2DB80031CFE0 /* BIT.swift */; };
832445031CDF2DB80031CFE0 /* BonNetwork.swift in Sources */ = {isa = PBXBuildFile; fileRef = 832445011CDF2DB80031CFE0 /* BonNetwork.swift */; };
832445061CDF2FF30031CFE0 /* Alamofire.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 832445051CDF2FF30031CFE0 /* Alamofire.framework */; };
8324450B1CDF31570031CFE0 /* BonDelay.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8324450A1CDF31570031CFE0 /* BonDelay.swift */; };
83A4B2C51CE75299000E83B4 /* MainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83A4B2C41CE75299000E83B4 /* MainViewController.swift */; };
83A4B2C81CE752FD000E83B4 /* BonViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83A4B2C61CE752FD000E83B4 /* BonViewController.swift */; };
Expand Down Expand Up @@ -50,8 +49,8 @@
832444FD1CDF2D5C0031CFE0 /* BonUserDefaults.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BonUserDefaults.swift; sourceTree = "<group>"; };
832445001CDF2DB80031CFE0 /* BIT.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BIT.swift; sourceTree = "<group>"; };
832445011CDF2DB80031CFE0 /* BonNetwork.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BonNetwork.swift; sourceTree = "<group>"; };
832445051CDF2FF30031CFE0 /* Alamofire.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Alamofire.framework; path = Carthage/Build/Mac/Alamofire.framework; sourceTree = "<group>"; };
8324450A1CDF31570031CFE0 /* BonDelay.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BonDelay.swift; sourceTree = "<group>"; };
834E8D1D1D8F86CD00DF4EF2 /* Alamofire.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Alamofire.framework; path = Carthage/Build/iOS/Alamofire.framework; sourceTree = "<group>"; };
83A4B2C41CE75299000E83B4 /* MainViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MainViewController.swift; sourceTree = "<group>"; };
83A4B2C61CE752FD000E83B4 /* BonViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BonViewController.swift; sourceTree = "<group>"; };
83A4B2C71CE752FD000E83B4 /* BonViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = BonViewController.xib; sourceTree = "<group>"; };
Expand All @@ -62,14 +61,14 @@
83A4B2D71CE7698D000E83B4 /* BonItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BonItem.swift; sourceTree = "<group>"; };
83A4B2D91CE76C17000E83B4 /* BonLoginView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BonLoginView.swift; sourceTree = "<group>"; };
83A4B2DB1CE774FC000E83B4 /* SettingsMenuAction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsMenuAction.swift; sourceTree = "<group>"; };
83D8A4F71D8F8A7D00C6C3F3 /* Alamofire.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Alamofire.framework; path = Carthage/Build/Mac/Alamofire.framework; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
832444DE1CDF17860031CFE0 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
832445061CDF2FF30031CFE0 /* Alamofire.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -89,6 +88,7 @@
children = (
832444E31CDF17860031CFE0 /* Bon */,
832444E21CDF17860031CFE0 /* Products */,
834E8D1C1D8F86CD00DF4EF2 /* Frameworks */,
);
sourceTree = "<group>";
};
Expand Down Expand Up @@ -163,12 +163,20 @@
832445081CDF30150031CFE0 /* Frameworks */ = {
isa = PBXGroup;
children = (
832445051CDF2FF30031CFE0 /* Alamofire.framework */,
83D8A4F71D8F8A7D00C6C3F3 /* Alamofire.framework */,
);
name = Frameworks;
path = ..;
sourceTree = "<group>";
};
834E8D1C1D8F86CD00DF4EF2 /* Frameworks */ = {
isa = PBXGroup;
children = (
834E8D1D1D8F86CD00DF4EF2 /* Alamofire.framework */,
);
name = Frameworks;
sourceTree = "<group>";
};
83A4B2CC1CE756E6000E83B4 /* Extensions */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -218,11 +226,12 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 0730;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = Chris;
TargetAttributes = {
832444E01CDF17860031CFE0 = {
CreatedOnToolsVersion = 7.3;
LastSwiftMigration = 0800;
};
};
};
Expand Down Expand Up @@ -331,8 +340,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "-";
Expand Down Expand Up @@ -376,8 +387,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "-";
Expand All @@ -396,6 +409,7 @@
MACOSX_DEPLOYMENT_TARGET = 10.11;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
};
name = Release;
};
Expand All @@ -407,11 +421,13 @@
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Carthage/Build/Mac",
"$(PROJECT_DIR)/Carthage/Build/iOS",
);
INFOPLIST_FILE = Bon/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.chriskuei.Bon;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -423,11 +439,13 @@
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Carthage/Build/Mac",
"$(PROJECT_DIR)/Carthage/Build/iOS",
);
INFOPLIST_FILE = Bon/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.chriskuei.Bon;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
6 changes: 3 additions & 3 deletions Bon/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {

func applicationWillFinishLaunching(notification: NSNotification) {
func applicationWillFinishLaunching(_ notification: Notification) {
}

func applicationDidFinishLaunching(aNotification: NSNotification) {
func applicationDidFinishLaunching(_ aNotification: Notification) {
}

func applicationWillTerminate(aNotification: NSNotification) {
func applicationWillTerminate(_ aNotification: Notification) {
}

}
Expand Down
20 changes: 10 additions & 10 deletions Bon/BonButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import Cocoa

class BonButton: NSButton {

private let cursor = NSCursor.pointingHandCursor()
private var normalStateImage: NSImage?
private var highlightedStateImage: NSImage?
private var trackingArea: NSTrackingArea?
fileprivate let cursor = NSCursor.pointingHand()
fileprivate var normalStateImage: NSImage?
fileprivate var highlightedStateImage: NSImage?
fileprivate var trackingArea: NSTrackingArea?

override func resetCursorRects() {
addCursorRect(bounds, cursor: cursor)
Expand All @@ -38,8 +38,8 @@ class BonButton: NSButton {
func commonInit() {
}

func setImages(normalImage: String, highlitedImage: String) {
self.setButtonType(.MomentaryChangeButton)
func setImages(_ normalImage: String, highlitedImage: String) {
self.setButtonType(.momentaryChange)

normalStateImage = NSImage(named: normalImage)
highlightedStateImage = NSImage(named: highlitedImage)
Expand All @@ -53,9 +53,9 @@ class BonButton: NSButton {
}
}

private func createTrackingAreaIfNeeded() {
fileprivate func createTrackingAreaIfNeeded() {
if trackingArea == nil {
trackingArea = NSTrackingArea(rect: CGRect.zero, options: [.InVisibleRect, .MouseEnteredAndExited, .ActiveAlways], owner: self, userInfo: nil)
trackingArea = NSTrackingArea(rect: CGRect.zero, options: [.inVisibleRect, .mouseEnteredAndExited, .activeAlways], owner: self, userInfo: nil)
}
}

Expand All @@ -69,13 +69,13 @@ class BonButton: NSButton {
}
}

override func mouseEntered(theEvent: NSEvent) {
override func mouseEntered(with theEvent: NSEvent) {
if let highlightedImage = highlightedStateImage {
image = highlightedImage
}
}

override func mouseExited(theEvent: NSEvent) {
override func mouseExited(with theEvent: NSEvent) {
if let normalStateImage = normalStateImage {
image = normalStateImage
}
Expand Down
36 changes: 18 additions & 18 deletions Bon/BonCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ class BonCell: NSTableCellView {
@IBOutlet weak var infoLabel: NSTextField!
//@IBOutlet weak var circleView: NSView!

private let squareWithCircleView: SquareWithCircleView = SquareWithCircleView(frame: CGRectZero)
fileprivate let squareWithCircleView: SquareWithCircleView = SquareWithCircleView(frame: CGRect.zero)

private var item: BonItem?
fileprivate var item: BonItem?

private let cursor = NSCursor.pointingHandCursor()
private var trackingArea: NSTrackingArea?
private var mouseInside = false {
fileprivate let cursor = NSCursor.pointingHand()
fileprivate var trackingArea: NSTrackingArea?
fileprivate var mouseInside = false {
didSet {
updateUI()
}
}

class func view(tableView: NSTableView, owner: AnyObject?, subject: AnyObject?) -> NSView {
let view = tableView.makeViewWithIdentifier("BonCell", owner: owner) as! BonCell
class func view(_ tableView: NSTableView, owner: AnyObject?, subject: AnyObject?) -> NSView {
let view = tableView.make(withIdentifier: "BonCell", owner: owner) as! BonCell

if let item = subject as? BonItem {
view.setItem(item)
Expand All @@ -42,7 +42,7 @@ class BonCell: NSTableCellView {
commonInit()
}

private func commonInit() {
fileprivate func commonInit() {
wantsLayer = true

typeImageView.wantsLayer = true
Expand All @@ -61,7 +61,7 @@ class BonCell: NSTableCellView {
cursor.set()
}

private func setItem(item: BonItem?) {
fileprivate func setItem(_ item: BonItem?) {
guard let item = item else {
return
}
Expand All @@ -71,12 +71,12 @@ class BonCell: NSTableCellView {
updateUI()
}

private func updateUI() {
fileprivate func updateUI() {
guard let item = item else {
return
}

layer?.backgroundColor = mouseInside ? NSColor.bonHighlightColor().CGColor : NSColor.bonWhiteColor().CGColor
layer?.backgroundColor = mouseInside ? NSColor.bonHighlightColor().cgColor : NSColor.bonWhiteColor().cgColor

nameLabel.stringValue = item.nameText
infoLabel.stringValue = item.infoText
Expand All @@ -89,9 +89,9 @@ class BonCell: NSTableCellView {
//typeImageView.image = NSImage(named: item.imageType)
}

private func createTrackingAreaIfNeeded() {
fileprivate func createTrackingAreaIfNeeded() {
if trackingArea == nil {
trackingArea = NSTrackingArea(rect: CGRect.zero, options: [NSTrackingAreaOptions.InVisibleRect, NSTrackingAreaOptions.MouseEnteredAndExited, NSTrackingAreaOptions.ActiveAlways], owner: self, userInfo: nil)
trackingArea = NSTrackingArea(rect: CGRect.zero, options: [NSTrackingAreaOptions.inVisibleRect, NSTrackingAreaOptions.mouseEnteredAndExited, NSTrackingAreaOptions.activeAlways], owner: self, userInfo: nil)
}
}

Expand All @@ -105,22 +105,22 @@ class BonCell: NSTableCellView {
}
}

override func mouseEntered(theEvent: NSEvent) {
override func mouseEntered(with theEvent: NSEvent) {
mouseInside = true
}

override func mouseExited(theEvent: NSEvent) {
override func mouseExited(with theEvent: NSEvent) {
mouseInside = false
}
}

class SquareWithCircleView: NSView{
override func drawRect(dirtyRect: NSRect)
override func draw(_ dirtyRect: NSRect)
{
let circleFillColor = NSColor.bonTintColor()
let circleRect = NSMakeRect(dirtyRect.size.width/4, dirtyRect.size.height/4, dirtyRect.size.width/2, dirtyRect.size.height/2)
let path: NSBezierPath = NSBezierPath(ovalInRect: circleRect)
let path: NSBezierPath = NSBezierPath(ovalIn: circleRect)
circleFillColor.set()
path.fill()
}
}
}
25 changes: 11 additions & 14 deletions Bon/BonDelay.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,24 @@

import Foundation

typealias Task = (cancel : Bool) -> Void
typealias Task = (_ cancel : Bool) -> Void

func delay(time: NSTimeInterval, task: ()->()) -> Task? {
func delay(_ time: TimeInterval, task: @escaping ()->()) -> Task? {

func dispatch_later(block: ()->()) {
dispatch_after(
dispatch_time(
DISPATCH_TIME_NOW,
Int64(time * Double(NSEC_PER_SEC))),
dispatch_get_main_queue(),
block)
func dispatch_later(_ block: @escaping ()->()) {
DispatchQueue.main.asyncAfter(
deadline: DispatchTime.now() + Double(Int64(time * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC),
execute: block)
}

var closure: dispatch_block_t? = task
var closure: (()->())? = task
var result: Task?

let delayedClosure: Task = {
cancel in
if let internalClosure = closure {
if (cancel == false) {
dispatch_async(dispatch_get_main_queue(), internalClosure);
DispatchQueue.main.async(execute: internalClosure);
}
}
closure = nil
Expand All @@ -39,15 +36,15 @@ func delay(time: NSTimeInterval, task: ()->()) -> Task? {

dispatch_later {
if let delayedClosure = result {
delayedClosure(cancel: false)
delayedClosure(false)
}
}

return result;
}

func cancel(task: Task?) {
task?(cancel: true)
func cancel(_ task: Task?) {
task?(true)
}

//// Function to create a delay method that is easy to re-use
Expand Down
Loading

0 comments on commit 8f2bd76

Please sign in to comment.