Audit force unwraps, removed a few

This commit is contained in:
Matthias Neeracher 2015-03-18 00:17:55 +01:00 committed by Matthias Neeracher
parent c9ad05a693
commit 5ea9dc38a8
4 changed files with 24 additions and 14 deletions

View File

@ -56,13 +56,13 @@ class ASApplication: NSObject, NSApplicationDelegate, NSMenuDelegate {
func applicationDidFinishLaunching(aNotification: NSNotification) { func applicationDidFinishLaunching(aNotification: NSNotification) {
themeMenu.removeAllItems() themeMenu.removeAllItems()
for (index, theme) in enumerate(ACEThemeNames.humanThemeNames() as! [String]) { for (index, theme) in enumerate(ACEThemeNames.humanThemeNames() as! [String]) {
let menuItem = themeMenu.addItemWithTitle(theme, action: "changeTheme:", keyEquivalent: "") let menuItem = themeMenu.addItemWithTitle(theme, action: "changeTheme:", keyEquivalent: "")!
menuItem!.tag = index menuItem.tag = index
} }
keyboardMenu.removeAllItems() keyboardMenu.removeAllItems()
for (index, theme) in enumerate(ACEKeyboardHandlerNames.humanKeyboardHandlerNames() as! [String]) { for (index, theme) in enumerate(ACEKeyboardHandlerNames.humanKeyboardHandlerNames() as! [String]) {
let menuItem = keyboardMenu.addItemWithTitle(theme, action: "changeKeyboardHandler:", keyEquivalent: "") let menuItem = keyboardMenu.addItemWithTitle(theme, action: "changeKeyboardHandler:", keyEquivalent: "")!
menuItem!.tag = index menuItem.tag = index
} }
} }
func applicationShouldOpenUntitledFile(sender: NSApplication) -> Bool { func applicationShouldOpenUntitledFile(sender: NSApplication) -> Bool {
@ -142,15 +142,17 @@ class ASApplication: NSObject, NSApplicationDelegate, NSMenuDelegate {
} }
@IBAction func openSketch(item: NSMenuItem) { @IBAction func openSketch(item: NSMenuItem) {
let url = NSURL(fileURLWithPath: sketches[item.tag])! if let url = NSURL(fileURLWithPath: sketches[item.tag]) {
let doc = NSDocumentController.sharedDocumentController() as! NSDocumentController let doc = NSDocumentController.sharedDocumentController() as! NSDocumentController
doc.openDocumentWithContentsOfURL(url, display: true) { (doc, alreadyOpen, error) -> Void in doc.openDocumentWithContentsOfURL(url, display: true) { (doc, alreadyOpen, error) -> Void in
}
} }
} }
@IBAction func openExample(item: NSMenuItem) { @IBAction func openExample(item: NSMenuItem) {
let url = NSURL(fileURLWithPath: examples[item.tag])! if let url = NSURL(fileURLWithPath: examples[item.tag]) {
openTemplate(url.URLByDeletingLastPathComponent!) openTemplate(url.URLByDeletingLastPathComponent!)
}
} }
@IBAction func createSketch(AnyObject) { @IBAction func createSketch(AnyObject) {

View File

@ -56,6 +56,10 @@ class ASBuilder {
let fileManager = NSFileManager.defaultManager() let fileManager = NSFileManager.defaultManager()
let libPath = (ASLibraries.instance().directories as NSArray).componentsJoinedByString(":") let libPath = (ASLibraries.instance().directories as NSArray).componentsJoinedByString(":")
var args = [String]() var args = [String]()
if ASHardware.instance().boards[board] == nil {
NSLog("Unable to find board %s\n", board);
return
}
let boardProp = ASHardware.instance().boards[board]! let boardProp = ASHardware.instance().boards[board]!
let library = boardProp["library"]! let library = boardProp["library"]!
var corePath = library+"/cores/"+boardProp["build.core"]! var corePath = library+"/cores/"+boardProp["build.core"]!
@ -82,8 +86,8 @@ class ASBuilder {
args.append("core="+boardProp["build.core"]!) args.append("core="+boardProp["build.core"]!)
args.append("libs="+libPath) args.append("libs="+libPath)
args.append("core_path="+corePath) args.append("core_path="+corePath)
if variantPath != nil { if let varPath = variantPath {
args.append("variant_path="+variantPath!) args.append("variant_path="+varPath)
} }
args.append("usb_vid="+(boardProp["build.vid"] ?? "null")); args.append("usb_vid="+(boardProp["build.vid"] ?? "null"));
args.append("usb_pid="+(boardProp["build.pid"] ?? "null")); args.append("usb_pid="+(boardProp["build.pid"] ?? "null"));
@ -125,7 +129,11 @@ class ASBuilder {
task!.standardOutput = logOut task!.standardOutput = logOut
task!.standardError = logOut task!.standardError = logOut
} }
if ASHardware.instance().boards[board] == nil {
NSLog("Unable to find board %s\n", board);
return
}
let libPath = (ASLibraries.instance().directories as NSArray).componentsJoinedByString(":") let libPath = (ASLibraries.instance().directories as NSArray).componentsJoinedByString(":")
let boardProp = ASHardware.instance().boards[board]! let boardProp = ASHardware.instance().boards[board]!
let progProp = ASHardware.instance().programmers[programmer] let progProp = ASHardware.instance().programmers[programmer]

View File

@ -252,7 +252,7 @@ class ASFileTree : NSObject, NSOutlineViewDataSource {
func addFileURL(url: NSURL, omitUnknown: Bool = true) { func addFileURL(url: NSURL, omitUnknown: Bool = true) {
let type = ASFileType.guessForURL(url) let type = ASFileType.guessForURL(url)
if !omitUnknown || type != .Unknown { if !omitUnknown || type != .Unknown {
root.children.append(ASFileItem(url: url.standardizedURL!, type: type)) root.children.append(ASFileItem(url: url.URLByStandardizingPath!, type: type))
} }
} }
func setProjectURL(url: NSURL) { func setProjectURL(url: NSURL) {

View File

@ -222,7 +222,7 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
func updateLog(AnyObject?) { func updateLog(AnyObject?) {
if let logNode = mainEditor as? ASLogNode { if let logNode = mainEditor as? ASLogNode {
let url = fileURL!.URLByDeletingLastPathComponent?.URLByAppendingPathComponent(logNode.path) let url = fileURL?.URLByDeletingLastPathComponent?.URLByAppendingPathComponent(logNode.path)
if url == nil { if url == nil {
return return
} }