Skip to content
This repository has been archived by the owner on May 23, 2022. It is now read-only.

Commit

Permalink
Merge pull request #65 from Tulleb/swift3
Browse files Browse the repository at this point in the history
Swift 3 compatibility.
  • Loading branch information
morizotter authored Jul 6, 2016
2 parents 94ee0ba + 1041002 commit c13c9d9
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 113 deletions.
6 changes: 6 additions & 0 deletions Example/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,11 @@
TargetAttributes = {
FF828F141A74E52500DC12EF = {
CreatedOnToolsVersion = 6.1.1;
LastSwiftMigration = 0800;
};
FF828F291A74E52500DC12EF = {
CreatedOnToolsVersion = 6.1.1;
LastSwiftMigration = 0800;
TestTargetID = FF828F141A74E52500DC12EF;
};
};
Expand Down Expand Up @@ -383,6 +385,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.molabo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -400,6 +403,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.molabo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand All @@ -420,6 +424,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.molabo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Example.app/Example";
};
name = Debug;
Expand All @@ -436,6 +441,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.molabo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Example.app/Example";
};
name = Release;
Expand Down
12 changes: 6 additions & 6 deletions Example/Example/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

// It's the simpest way!
Visualizer.start()
Expand All @@ -30,25 +30,25 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
return true
}

func applicationWillResignActive(application: UIApplication) {
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(application: UIApplication) {
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(application: UIApplication) {
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(application: UIApplication) {
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(application: UIApplication) {
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

Expand Down
77 changes: 51 additions & 26 deletions Example/Example/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions Example/Example/ConfigViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ final class ConfigViewController: UITableViewController {

// MARK: - Life Cycle

override func viewDidAppear(animated: Bool) {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
Visualizer.start()
updateCells()
}

// MARK: - TableView Delegate

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

tableView.deselectRowAtIndexPath(indexPath, animated: true)
tableView.deselectRow(at: indexPath, animated: true)

let cell = tableView.cellForRowAtIndexPath(indexPath)
let cell = tableView.cellForRow(at: indexPath)

if cell == timerCell {
config.showsTimer = !config.showsTimer
Expand All @@ -50,10 +50,10 @@ final class ConfigViewController: UITableViewController {
let controller = UIAlertController(
title: "Warning",
message: "This property doesn't work on the simulator because it is not possible to read touch radius on it. Please test it on device.",
preferredStyle: .Alert
preferredStyle: .alert
)
controller.addAction(UIAlertAction(title: "OK", style: .Cancel, handler: nil))
self.presentViewController(controller, animated: true, completion: nil)
controller.addAction(UIAlertAction(title: "OK", style: .cancel, handler: nil))
self.present(controller, animated: true, completion: nil)
return
}
config.showsTouchRadius = !config.showsTouchRadius
Expand All @@ -78,11 +78,11 @@ final class ConfigViewController: UITableViewController {
func updateCells() {
let boolCells = [timerCell, touchRadiusCell, logCell]
for cell in boolCells {
cell.detailTextLabel?.text = "false"
cell?.detailTextLabel?.text = "false"
}
let checkmarkCells = [blueColorCell, redColorCell, greenColorCell]
for cell in checkmarkCells {
cell.accessoryType = .None
cell?.accessoryType = .none
}

if config.showsTimer {
Expand All @@ -95,23 +95,23 @@ final class ConfigViewController: UITableViewController {
logCell.detailTextLabel?.text = "true"
}
if config.color == colors["blue"] {
blueColorCell.accessoryType = .Checkmark
blueColorCell.accessoryType = .checkmark
} else if config.color == colors["red"] {
redColorCell.accessoryType = .Checkmark
redColorCell.accessoryType = .checkmark
} else if config.color == colors["green"] {
greenColorCell.accessoryType = .Checkmark
greenColorCell.accessoryType = .checkmark
}
}

// MARK: - Actions

@IBAction func cancelButtonTapped(sender: UIBarButtonItem) {
dismissViewControllerAnimated(true, completion: nil)
dismiss(animated: true, completion: nil)
Visualizer.start()
}

@IBAction func doneButtonTapped(sender: UIBarButtonItem) {
self.dismissViewControllerAnimated(true, completion: nil)
self.dismiss(animated: true, completion: nil)
}

func isSimulator() -> Bool {
Expand Down
28 changes: 14 additions & 14 deletions Example/Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ViewController: UITableViewController {

// MARK: - Life Cycle

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
override func prepare(for segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "PushToDetail" {
let viewController = segue.destinationViewController as! DetailViewController
if let cell = sender as? UITableViewCell {
Expand All @@ -23,12 +23,12 @@ class ViewController: UITableViewController {

// MARK: - TableView DataSource

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 100
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
cell.textLabel?.text = "Smooth scrolling!"
cell.detailTextLabel?.text = "\(indexPath.row)"
return cell
Expand All @@ -37,38 +37,38 @@ class ViewController: UITableViewController {
// MARK: - Actions

@IBAction func rightBarButtonItemTapped(sender: AnyObject) {
let alertAction = UIAlertAction(title: "Show Alert", style: .Default, handler: { [unowned self] (alertAction) -> Void in
let alertAction = UIAlertAction(title: "Show Alert", style: .default, handler: { [unowned self] (alertAction) -> Void in
let controller = UIAlertController(
title: "Alert",
message: "Even when alert shows, your tap is visible.",
preferredStyle: .Alert
preferredStyle: .alert
)
controller.addAction(UIAlertAction(title: "OK", style: .Cancel, handler: nil))
self.presentViewController(controller, animated: true, completion: nil)
controller.addAction(UIAlertAction(title: "OK", style: .cancel, handler: nil))
self.present(controller, animated: true, completion: nil)
})

var startOrStopTitle = "Start Visualizer"
if Visualizer.isEnabled() {
startOrStopTitle = "Stop Visualizer"
}
let startOrStopAction = UIAlertAction(title: startOrStopTitle, style: .Default, handler: { [unowned self] (alertAction) -> Void in
let startOrStopAction = UIAlertAction(title: startOrStopTitle, style: .default, handler: { [unowned self] (alertAction) -> Void in
if Visualizer.isEnabled() {
Visualizer.stop()
self.navigationItem.leftBarButtonItem?.enabled = false
self.navigationItem.leftBarButtonItem?.isEnabled = false
} else {
Visualizer.start()
self.navigationItem.leftBarButtonItem?.enabled = true
self.navigationItem.leftBarButtonItem?.isEnabled = true
}
})

let controller = UIAlertController(
title: "ActionSheet",
message: "Even when action sheet shows, your tap is visible.",
preferredStyle: .ActionSheet
preferredStyle: .actionSheet
)
controller.addAction(alertAction)
controller.addAction(startOrStopAction)
controller.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: nil))
self.presentViewController(controller, animated: true, completion: nil)
controller.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
self.present(controller, animated: true, completion: nil)
}
}
2 changes: 1 addition & 1 deletion Example/ExampleTests/ExampleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ExampleTests: XCTestCase {

func testPerformanceExample() {
// This is an example of a performance test case.
self.measureBlock() {
self.measure() {
// Put the code you want to measure the time of here.
}
}
Expand Down
3 changes: 3 additions & 0 deletions TouchVisualizer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
TargetAttributes = {
FF1A1A9E1AFF6C2200267156 = {
CreatedOnToolsVersion = 6.4;
LastSwiftMigration = 0800;
};
};
};
Expand Down Expand Up @@ -267,6 +268,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -284,6 +286,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.molabo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
6 changes: 3 additions & 3 deletions TouchVisualizer/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public struct Configuration {

UIGraphicsBeginImageContextWithOptions(rect.size, false, 0.0)
let contextRef = UIGraphicsGetCurrentContext()
CGContextSetFillColorWithColor(contextRef, Constants.defaultColor.CGColor)
CGContextFillEllipseInRect(contextRef, rect)
contextRef?.setFillColor(Constants.defaultColor.cgColor)
contextRef?.fillEllipse(in: rect)
var image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()

return image.imageWithRenderingMode(.AlwaysTemplate)
return image?.withRenderingMode(.alwaysTemplate)
}()

/**
Expand Down
26 changes: 13 additions & 13 deletions TouchVisualizer/TouchView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ final public class TouchView: UIImageView {

// MARK: - Public Variables
internal weak var touch: UITouch?
private weak var timer: NSTimer?
private weak var timer: Timer?
private var _config: Configuration
private var previousRatio: CGFloat = 1.0
private var startDate: NSDate?
private var startDate: Date?
private var lastTimeString: String!

public var config: Configuration {
Expand All @@ -30,21 +30,21 @@ final public class TouchView: UIImageView {
let bottom: CGFloat = 8.0
var label = UILabel()

label.frame = CGRect(x: -(size.width - CGRectGetWidth(self.frame)) / 2,
label.frame = CGRect(x: -(size.width - self.frame.width) / 2,
y: -size.height - bottom,
width: size.width,
height: size.height)

label.font = UIFont(name: "Helvetica", size: 24.0)
label.textAlignment = .Center
label.textAlignment = .center
self.addSubview(label)

return label
}()

// MARK: - Object life cycle
convenience init() {
self.init(frame: CGRectZero)
self.init(frame: CGRect.zero)
}

override init(frame: CGRect) {
Expand All @@ -69,12 +69,12 @@ final public class TouchView: UIImageView {
layer.transform = CATransform3DIdentity
previousRatio = 1.0
frame = CGRect(origin: frame.origin, size: _config.defaultSize)
startDate = NSDate()
timer = NSTimer.scheduledTimerWithTimeInterval(1.0 / 60.0, target: self, selector: #selector(self.update(_:)), userInfo: nil, repeats: true)
startDate = Date()
timer = Timer.scheduledTimer(timeInterval: 1.0 / 60.0, target: self, selector: #selector(self.update(_:)), userInfo: nil, repeats: true)

NSRunLoop
.mainRunLoop()
.addTimer(timer!, forMode: NSRunLoopCommonModes)
RunLoop
.main()
.add(timer!, forMode: RunLoopMode.commonModes)

if _config.showsTimer {
timerLabel.alpha = 1.0
Expand All @@ -90,9 +90,9 @@ final public class TouchView: UIImageView {
}

// MARK: - Update Functions
internal func update(timer: NSTimer) {
internal func update(_ timer: Timer) {
if let startDate = startDate {
let interval = NSDate().timeIntervalSinceDate(startDate)
let interval = Date().timeIntervalSince(startDate)
let timeString = String(format: "%.02f", Float(interval))
timerLabel.text = timeString
}
Expand All @@ -111,4 +111,4 @@ final public class TouchView: UIImageView {
}
}
}
}
}
8 changes: 4 additions & 4 deletions TouchVisualizer/UIWindow+Swizzle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ extension UIWindow {
}

public func swizzle() {
let range = self.description.rangeOfString(swizzlingMessage, options: .LiteralSearch, range: nil, locale: nil)
if (range?.startIndex != nil) {
let range = self.description.range(of: swizzlingMessage, options: .literalSearch, range: nil, locale: nil)
if (range?.lowerBound != nil) {
return
}

Expand All @@ -25,12 +25,12 @@ extension UIWindow {
method_exchangeImplementations(description, swizzledDescription)
}

public func swizzledSendEvent(event: UIEvent) {
public func swizzledSendEvent(_ event: UIEvent) {
Visualizer.sharedInstance.handleEvent(event)
swizzledSendEvent(event)
}

public func swizzledDescription() -> String {
return swizzledDescription() + "; " + swizzlingMessage
}
}
}
Loading

0 comments on commit c13c9d9

Please sign in to comment.