From 9c138a3b6bf392de8dc9d15355d721a971b70b4f Mon Sep 17 00:00:00 2001 From: Matthias Neeracher Date: Wed, 4 Feb 2015 02:12:47 +0100 Subject: [PATCH] Update to newer version of Swift: lastPathComponent now an optional --- AVRsack/ASApplication.swift | 10 +++++----- AVRsack/ASBuilder.swift | 6 +++--- AVRsack/ASFileTree.swift | 6 +++--- AVRsack/ASProjDoc.swift | 6 +++--- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/AVRsack/ASApplication.swift b/AVRsack/ASApplication.swift index 049b567..bb78c30 100644 --- a/AVRsack/ASApplication.swift +++ b/AVRsack/ASApplication.swift @@ -109,8 +109,8 @@ class ASApplication: NSObject, NSApplicationDelegate, NSMenuDelegate { ASApplication.newProjectLocation(nil, message: "Save editable copy of project \(template.lastPathComponent)") { (saveTo) -> Void in - let oldName = template.lastPathComponent - let newName = saveTo.lastPathComponent + let oldName = template.lastPathComponent! + let newName = saveTo.lastPathComponent! let fileManager = NSFileManager.defaultManager() fileManager.copyItemAtURL(template, toURL: saveTo, error: nil) let contents = fileManager.enumeratorAtURL(saveTo, @@ -118,7 +118,7 @@ class ASApplication: NSObject, NSApplicationDelegate, NSMenuDelegate { options: .SkipsHiddenFiles, errorHandler: nil) while let item = contents?.nextObject() as? NSURL { var renameItem = false - var itemName = item.lastPathComponent + var itemName = item.lastPathComponent! if itemName.stringByDeletingPathExtension == oldName { renameItem = true itemName = newName.stringByAppendingPathExtension(itemName.pathExtension)! @@ -159,12 +159,12 @@ class ASApplication: NSObject, NSApplicationDelegate, NSMenuDelegate { { (saveTo) -> Void in let fileManager = NSFileManager.defaultManager() fileManager.createDirectoryAtURL(saveTo, withIntermediateDirectories:false, attributes:nil, error:nil) - let proj = saveTo.URLByAppendingPathComponent(saveTo.lastPathComponent+".avrsackproj") + let proj = saveTo.URLByAppendingPathComponent(saveTo.lastPathComponent!+".avrsackproj") let docController = NSDocumentController.sharedDocumentController() as NSDocumentController if let doc = docController.openUntitledDocumentAndDisplay(true, error:nil) as? ASProjDoc { doc.fileURL = proj doc.updateProjectURL() - doc.createFileAtURL(saveTo.URLByAppendingPathComponent(saveTo.lastPathComponent+".ino")) + doc.createFileAtURL(saveTo.URLByAppendingPathComponent(saveTo.lastPathComponent!+".ino")) doc.writeToURL(proj, ofType: "Project", forSaveOperation: .SaveAsOperation, originalContentsURL: nil, error: nil) } } diff --git a/AVRsack/ASBuilder.swift b/AVRsack/ASBuilder.swift index ec59ee0..f5bd56d 100644 --- a/AVRsack/ASBuilder.swift +++ b/AVRsack/ASBuilder.swift @@ -74,7 +74,7 @@ class ASBuilder { return } args.append("toolchain="+toolChain) - args.append("project="+dir.lastPathComponent) + args.append("project="+dir.lastPathComponent!) args.append("board="+board) args.append("mcu="+boardProp["build.mcu"]!) args.append("f_cpu="+boardProp["build.f_cpu"]!) @@ -143,7 +143,7 @@ class ASBuilder { if hasBootloader { args += ["-D"] } - args += ["-U", "flash:w:build/"+board+"/"+dir.lastPathComponent+".hex:i"] + args += ["-U", "flash:w:build/"+board+"/"+dir.lastPathComponent!+".hex:i"] continuation = { dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(2*NSEC_PER_SEC)), dispatch_get_main_queue(), { ASSerialWin.portAvailableAfterUpload(port) @@ -245,7 +245,7 @@ class ASBuilder { let showSource = NSUserDefaults.standardUserDefaults().boolForKey("ShowSourceInDisassembly") var args = showSource ? ["-S"] : [] - args += ["-d", "build/"+board+"/"+dir.lastPathComponent+".elf"] + args += ["-d", "build/"+board+"/"+dir.lastPathComponent!+".elf"] let cmdLine = task!.launchPath+" "+(args as NSArray).componentsJoinedByString(" ")+"\n" logOut.writeData(cmdLine.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: true)!) task!.arguments = args; diff --git a/AVRsack/ASFileTree.swift b/AVRsack/ASFileTree.swift index f35526b..8c02ada 100644 --- a/AVRsack/ASFileTree.swift +++ b/AVRsack/ASFileTree.swift @@ -18,7 +18,7 @@ enum ASFileType : String { case Markdown = "doc.md" static func guessForURL(url: NSURL) -> ASFileType { - switch url.pathExtension.lowercaseString { + switch url.pathExtension!.lowercaseString { case "hpp", "hh", "h": return .Header case "c": @@ -172,7 +172,7 @@ class ASFileItem : ASFileNode { } } override func nodeName() -> String { - return "📄 "+url.lastPathComponent + return "📄 "+url.lastPathComponent! } func relativePath(relativeTo: String) -> String { @@ -222,7 +222,7 @@ class ASFileTree : NSObject, NSOutlineViewDataSource { } } func setProjectURL(url: NSURL) { - root.name = url.lastPathComponent.stringByDeletingPathExtension + root.name = url.lastPathComponent!.stringByDeletingPathExtension dir = url.URLByDeletingLastPathComponent!.standardizedURL! } func apply(closure: (ASFileNode) -> ()) { diff --git a/AVRsack/ASProjDoc.swift b/AVRsack/ASProjDoc.swift index d712a42..33339c5 100644 --- a/AVRsack/ASProjDoc.swift +++ b/AVRsack/ASProjDoc.swift @@ -157,7 +157,7 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa } func importProject(url: NSURL, error outError: NSErrorPointer) -> Bool { - let existingProject = url.URLByAppendingPathComponent(url.lastPathComponent+".avrsackproj") + let existingProject = url.URLByAppendingPathComponent(url.lastPathComponent!+".avrsackproj") if existingProject.checkResourceIsReachableAndReturnError(nil) { fileURL = existingProject return readFromURL(existingProject, ofType:"Project", error:outError) @@ -424,8 +424,8 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa let dateFmt = NSDateFormatter() dateFmt.dateFormat = "yyyy-MM-dd" header = firstPfx + "\n" + - prefix + " Project: " + fileURL!.URLByDeletingLastPathComponent!.lastPathComponent + "\n" + - prefix + " File: " + url.lastPathComponent + "\n" + + prefix + " Project: " + fileURL!.URLByDeletingLastPathComponent!.lastPathComponent! + "\n" + + prefix + " File: " + url.lastPathComponent! + "\n" + prefix + " Created: " + dateFmt.stringFromDate(NSDate()) + "\n" + lastPfx + "\n\n" }