Commit e29d22e8 authored by Roy Marmelstein's avatar Roy Marmelstein

Swift 3 updates

parent a97fe9b9
...@@ -6,7 +6,7 @@ env: ...@@ -6,7 +6,7 @@ env:
- LANG=en_US.UTF-8 - LANG=en_US.UTF-8
before_install: before_install:
- brew update || brew update - brew update || brew update
- gem install cocoapods - gem install cocoapods --pre
install: echo "<3" install: echo "<3"
env: env:
- MODE=framework - MODE=framework
......
...@@ -172,9 +172,11 @@ ...@@ -172,9 +172,11 @@
TargetAttributes = { TargetAttributes = {
3430F66C1C45C930007473A6 = { 3430F66C1C45C930007473A6 = {
CreatedOnToolsVersion = 7.2; CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0800;
}; };
3430F6801C45C930007473A6 = { 3430F6801C45C930007473A6 = {
CreatedOnToolsVersion = 7.2; CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0800;
TestTargetID = 3430F66C1C45C930007473A6; TestTargetID = 3430F66C1C45C930007473A6;
}; };
}; };
...@@ -359,6 +361,7 @@ ...@@ -359,6 +361,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.roymarmelstein.Sample; PRODUCT_BUNDLE_IDENTIFIER = com.roymarmelstein.Sample;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
}; };
name = Debug; name = Debug;
}; };
...@@ -370,6 +373,7 @@ ...@@ -370,6 +373,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.roymarmelstein.Sample; PRODUCT_BUNDLE_IDENTIFIER = com.roymarmelstein.Sample;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
}; };
name = Release; name = Release;
}; };
...@@ -381,6 +385,7 @@ ...@@ -381,6 +385,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.roymarmelstein.SampleTests; PRODUCT_BUNDLE_IDENTIFIER = com.roymarmelstein.SampleTests;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Sample.app/Sample"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Sample.app/Sample";
}; };
name = Debug; name = Debug;
...@@ -393,6 +398,7 @@ ...@@ -393,6 +398,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.roymarmelstein.SampleTests; PRODUCT_BUNDLE_IDENTIFIER = com.roymarmelstein.SampleTests;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Sample.app/Sample"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Sample.app/Sample";
}; };
name = Release; name = Release;
......
...@@ -14,18 +14,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate { ...@@ -14,18 +14,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow? var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: Any]?) -> Bool {
if NSUserDefaults.standardUserDefaults().boolForKey("firstLaunch") == false { if UserDefaults.standard.bool(forKey: "firstLaunch") == false {
NSUserDefaults.standardUserDefaults().setBool(true, forKey: "firstLaunch") UserDefaults.standard.set(true, forKey: "firstLaunch")
NSUserDefaults.standardUserDefaults().synchronize() UserDefaults.standard.synchronize()
let fileManager = NSFileManager.defaultManager() let fileManager = FileManager.default
let fileNames = ["Image1.jpg", "Image2.jpg", "Image3.jpg", "Images.zip"] let fileNames = ["Image1.jpg", "Image2.jpg", "Image3.jpg", "Images.zip"]
let documentsUrl = fileManager.URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as NSURL let documentsUrl = fileManager.urls(for: .documentDirectory, in: .userDomainMask)[0] as URL
let bundleUrl = NSBundle.mainBundle().resourceURL let bundleUrl = Bundle.main.resourceURL
for file in fileNames { for file in fileNames {
if let srcPath = bundleUrl?.URLByAppendingPathComponent(file).path, let toPath = documentsUrl.URLByAppendingPathComponent(file).path{ if let srcPath = bundleUrl?.appendingPathComponent(file).path, let toPath = documentsUrl.appendingPathComponent(file).path{
do { do {
try fileManager.copyItemAtPath(srcPath, toPath: toPath) try fileManager.copyItem(atPath: srcPath, toPath: toPath)
} catch {} } catch {}
} }
} }
...@@ -34,25 +34,25 @@ class AppDelegate: UIResponder, UIApplicationDelegate { ...@@ -34,25 +34,25 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
return true 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. // 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. // 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. // 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. // 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. // 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. // 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:. // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
} }
......
...@@ -17,9 +17,9 @@ class FileBrowser: UIViewController, UITableViewDataSource, UITableViewDelegate ...@@ -17,9 +17,9 @@ class FileBrowser: UIViewController, UITableViewDataSource, UITableViewDelegate
@IBOutlet weak var zipButton: UIBarButtonItem! @IBOutlet weak var zipButton: UIBarButtonItem!
@IBOutlet weak var unzipButton: UIBarButtonItem! @IBOutlet weak var unzipButton: UIBarButtonItem!
let fileManager = NSFileManager.defaultManager() let fileManager = FileManager.default
var path: NSURL? { var path: URL? {
didSet { didSet {
updateFiles() updateFiles()
} }
...@@ -34,7 +34,7 @@ class FileBrowser: UIViewController, UITableViewDataSource, UITableViewDelegate ...@@ -34,7 +34,7 @@ class FileBrowser: UIViewController, UITableViewDataSource, UITableViewDelegate
override func viewDidLoad() { override func viewDidLoad() {
if self.path == nil { if self.path == nil {
let documentsUrl = fileManager.URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as NSURL let documentsUrl = fileManager.urls(for: .documentDirectory, in: .userDomainMask)[0] as URL
self.path = documentsUrl self.path = documentsUrl
} }
updateSelection() updateSelection()
...@@ -47,7 +47,7 @@ class FileBrowser: UIViewController, UITableViewDataSource, UITableViewDelegate ...@@ -47,7 +47,7 @@ class FileBrowser: UIViewController, UITableViewDataSource, UITableViewDelegate
var tempFiles = [String]() var tempFiles = [String]()
do { do {
self.title = filePath.lastPathComponent self.title = filePath.lastPathComponent
tempFiles = try self.fileManager.contentsOfDirectoryAtPath(filePath.path!) tempFiles = try self.fileManager.contentsOfDirectory(atPath: filePath.path)
} catch { } catch {
if path == "/System" { if path == "/System" {
tempFiles = ["Library"] tempFiles = ["Library"]
...@@ -62,50 +62,50 @@ class FileBrowser: UIViewController, UITableViewDataSource, UITableViewDelegate ...@@ -62,50 +62,50 @@ class FileBrowser: UIViewController, UITableViewDataSource, UITableViewDelegate
tempFiles = ["lib", "libexec", "bin"] tempFiles = ["lib", "libexec", "bin"]
} }
} }
self.files = tempFiles.sort(){$0 < $1} self.files = tempFiles.sorted(){$0 < $1}
tableView.reloadData() tableView.reloadData()
} }
} }
//MARK: UITableView Data Source and Delegate //MARK: UITableView Data Source and Delegate
func numberOfSectionsInTableView(tableView: UITableView) -> Int { func numberOfSections(in tableView: UITableView) -> Int {
return 1 return 1
} }
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return files.count return files.count
} }
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellIdentifier = "FileCell" let cellIdentifier = "FileCell"
var cell = UITableViewCell(style: .Subtitle, reuseIdentifier: cellIdentifier) var cell = UITableViewCell(style: .subtitle, reuseIdentifier: cellIdentifier)
if let reuseCell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) { if let reuseCell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier) {
cell = reuseCell cell = reuseCell
} }
guard let path = path else { guard let path = path else {
return cell return cell
} }
cell.selectionStyle = .None cell.selectionStyle = .none
let filePath = files[indexPath.row] let filePath = files[(indexPath as NSIndexPath).row]
let newPath = path.URLByAppendingPathComponent(filePath).path! let newPath = path.appendingPathComponent(filePath).path
var isDirectory: ObjCBool = false var isDirectory: ObjCBool = false
fileManager.fileExistsAtPath(newPath, isDirectory: &isDirectory) fileManager.fileExists(atPath: newPath, isDirectory: &isDirectory)
cell.textLabel?.text = files[indexPath.row] cell.textLabel?.text = files[(indexPath as NSIndexPath).row]
if isDirectory { if isDirectory {
cell.imageView?.image = UIImage(named: "Folder") cell.imageView?.image = UIImage(named: "Folder")
} }
else { else {
cell.imageView?.image = UIImage(named: "File") cell.imageView?.image = UIImage(named: "File")
} }
cell.backgroundColor = (selectedFiles.contains(filePath)) ? UIColor(white: 0.9, alpha: 1.0):UIColor.whiteColor() cell.backgroundColor = (selectedFiles.contains(filePath)) ? UIColor(white: 0.9, alpha: 1.0):UIColor.white
return cell return cell
} }
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let filePath = files[indexPath.row] let filePath = files[(indexPath as NSIndexPath).row]
if let index = selectedFiles.indexOf(filePath) where selectedFiles.contains(filePath) { if let index = selectedFiles.index(of: filePath) , selectedFiles.contains(filePath) {
selectedFiles.removeAtIndex(index) selectedFiles.remove(at: index)
} }
else { else {
selectedFiles.append(filePath) selectedFiles.append(filePath)
...@@ -117,27 +117,27 @@ class FileBrowser: UIViewController, UITableViewDataSource, UITableViewDelegate ...@@ -117,27 +117,27 @@ class FileBrowser: UIViewController, UITableViewDataSource, UITableViewDelegate
tableView.reloadData() tableView.reloadData()
selectionCounter.title = "\(selectedFiles.count) Selected" selectionCounter.title = "\(selectedFiles.count) Selected"
zipButton.enabled = (selectedFiles.count > 0) zipButton.isEnabled = (selectedFiles.count > 0)
if (selectedFiles.count == 1) { if (selectedFiles.count == 1) {
let filePath = selectedFiles.first let filePath = selectedFiles.first
let pathExtension = path!.URLByAppendingPathComponent(filePath!).pathExtension let pathExtension = path!.appendingPathComponent(filePath!).pathExtension
if pathExtension == "zip" { if pathExtension == "zip" {
unzipButton.enabled = true unzipButton.isEnabled = true
} }
else { else {
unzipButton.enabled = false unzipButton.isEnabled = false
} }
} }
else { else {
unzipButton.enabled = false unzipButton.isEnabled = false
} }
} }
//MARK: Actions //MARK: Actions
@IBAction func unzipSelection(sender: AnyObject) { @IBAction func unzipSelection(_ sender: AnyObject) {
let filePath = selectedFiles.first let filePath = selectedFiles.first
let pathURL = path!.URLByAppendingPathComponent(filePath!) let pathURL = path!.appendingPathComponent(filePath!)
do { do {
try Zip.quickUnzipFile(pathURL) try Zip.quickUnzipFile(pathURL)
self.selectedFiles.removeAll() self.selectedFiles.removeAll()
...@@ -148,10 +148,10 @@ class FileBrowser: UIViewController, UITableViewDataSource, UITableViewDelegate ...@@ -148,10 +148,10 @@ class FileBrowser: UIViewController, UITableViewDataSource, UITableViewDelegate
} }
} }
@IBAction func zipSelection(sender: AnyObject) { @IBAction func zipSelection(_ sender: AnyObject) {
var urlPaths = [NSURL]() var urlPaths = [URL]()
for filePath in selectedFiles { for filePath in selectedFiles {
urlPaths.append(path!.URLByAppendingPathComponent(filePath)) urlPaths.append(path!.appendingPathComponent(filePath))
} }
do { do {
try Zip.quickZipFiles(urlPaths, fileName: "Archive") try Zip.quickZipFiles(urlPaths, fileName: "Archive")
......
...@@ -28,7 +28,7 @@ class SampleTests: XCTestCase { ...@@ -28,7 +28,7 @@ class SampleTests: XCTestCase {
func testPerformanceExample() { func testPerformanceExample() {
// This is an example of a performance test case. // This is an example of a performance test case.
self.measureBlock { self.measure {
// Put the code you want to measure the time of here. // Put the code you want to measure the time of here.
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment