Fix incompatibilities with Swift 1.2

This commit is contained in:
Matthias Neeracher 2015-02-14 17:43:20 +01:00 committed by Matthias Neeracher
parent 6e7135d298
commit 0d25f9a5a6
9 changed files with 107 additions and 106 deletions

View File

@ -10,7 +10,7 @@ import Foundation
extension ACEView {
class func themeIdByName(themeName: String) -> UInt? {
for (themeIdx, theme) in enumerate(ACEThemeNames.themeNames() as [NSString]) {
for (themeIdx, theme) in enumerate(ACEThemeNames.themeNames() as! [String]) {
if themeName == theme {
return UInt(themeIdx)
}
@ -19,7 +19,7 @@ extension ACEView {
}
class func handlerIdByName(handlerName: String) -> ACEKeyboardHandler? {
for (handlerIdx, handler) in enumerate(ACEKeyboardHandlerNames.humanKeyboardHandlerNames() as [NSString]) {
for (handlerIdx, handler) in enumerate(ACEKeyboardHandlerNames.humanKeyboardHandlerNames() as! [String]) {
if handlerName == handler {
return ACEKeyboardHandler(rawValue: UInt(handlerIdx))!
}

View File

@ -32,7 +32,7 @@ class ASApplication: NSObject, NSApplicationDelegate, NSMenuDelegate {
let workSpace = NSWorkspace.sharedWorkspace()
let userDefaults = NSUserDefaults.standardUserDefaults()
let appDefaultsURL = NSBundle.mainBundle().URLForResource("Defaults", withExtension: "plist")!
let appDefaults = NSMutableDictionary(contentsOfURL: appDefaultsURL)!
var appDefaults = NSDictionary(contentsOfURL: appDefaultsURL) as! [String: AnyObject]
//
// Add dynamic app defaults
//
@ -55,12 +55,12 @@ class ASApplication: NSObject, NSApplicationDelegate, NSMenuDelegate {
}
func applicationDidFinishLaunching(aNotification: NSNotification) {
themeMenu.removeAllItems()
for (index, theme) in enumerate(ACEThemeNames.humanThemeNames() as [NSString]) {
for (index, theme) in enumerate(ACEThemeNames.humanThemeNames() as! [String]) {
let menuItem = themeMenu.addItemWithTitle(theme, action: "changeTheme:", keyEquivalent: "")
menuItem!.tag = index
}
keyboardMenu.removeAllItems()
for (index, theme) in enumerate(ACEKeyboardHandlerNames.humanKeyboardHandlerNames() as [NSString]) {
for (index, theme) in enumerate(ACEKeyboardHandlerNames.humanKeyboardHandlerNames() as! [String]) {
let menuItem = keyboardMenu.addItemWithTitle(theme, action: "changeKeyboardHandler:", keyEquivalent: "")
menuItem!.tag = index
}
@ -76,7 +76,7 @@ class ASApplication: NSObject, NSApplicationDelegate, NSMenuDelegate {
case "Sketchbook":
menu.removeAllItems()
sketches = [String]()
for sketchBook in NSUserDefaults.standardUserDefaults().objectForKey("Sketchbooks") as [NSString] {
for sketchBook in NSUserDefaults.standardUserDefaults().objectForKey("Sketchbooks") as! [String] {
if NSFileManager.defaultManager().fileExistsAtPath(sketchBook) {
ASSketchBook.addSketches(menu, target: self, action: "openSketch:", path: sketchBook, sketches: &sketches)
}
@ -93,7 +93,7 @@ class ASApplication: NSObject, NSApplicationDelegate, NSMenuDelegate {
while menu.numberOfItems > 2 {
menu.removeItemAtIndex(2)
}
for port in ASSerial.ports() as [String] {
for port in ASSerial.ports() as! [String] {
menu.addItemWithTitle(port, action:"serialConnectMenu:", keyEquivalent:"")
}
default:
@ -132,7 +132,7 @@ class ASApplication: NSObject, NSApplicationDelegate, NSMenuDelegate {
let sketch = ASSketchBook.findSketch(saveTo.path!)
switch sketch {
case .Sketch(_, let path):
let doc = NSDocumentController.sharedDocumentController() as NSDocumentController
let doc = NSDocumentController.sharedDocumentController() as! NSDocumentController
doc.openDocumentWithContentsOfURL(NSURL(fileURLWithPath: path)!, display: true) { (doc, alreadyOpen, error) -> Void in
}
default:
@ -143,7 +143,7 @@ class ASApplication: NSObject, NSApplicationDelegate, NSMenuDelegate {
@IBAction func openSketch(item: NSMenuItem) {
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
}
}
@ -160,7 +160,7 @@ class ASApplication: NSObject, NSApplicationDelegate, NSMenuDelegate {
let fileManager = NSFileManager.defaultManager()
fileManager.createDirectoryAtURL(saveTo, withIntermediateDirectories:false, attributes:nil, error:nil)
let proj = saveTo.URLByAppendingPathComponent(saveTo.lastPathComponent!+".avrsackproj")
let docController = NSDocumentController.sharedDocumentController() as NSDocumentController
let docController = NSDocumentController.sharedDocumentController() as! NSDocumentController
if let doc = docController.openUntitledDocumentAndDisplay(true, error:nil) as? ASProjDoc {
doc.fileURL = proj
doc.updateProjectURL()

View File

@ -48,18 +48,18 @@ class ASBuilder {
}
func buildProject(board: String, files: ASFileTree) {
let toolChain = (NSApplication.sharedApplication().delegate as ASApplication).preferences.toolchainPath
let toolChain = (NSApplication.sharedApplication().delegate as! ASApplication).preferences.toolchainPath
task = NSTask()
task!.currentDirectoryPath = dir.path!
task!.launchPath = NSBundle.mainBundle().pathForResource("BuildProject", ofType: "")!
let fileManager = NSFileManager.defaultManager()
let libPath = (ASLibraries.instance().directories as NSArray).componentsJoinedByString(":")
var args = [NSString]()
var args = [String]()
let boardProp = ASHardware.instance().boards[board]!
let library = boardProp["library"]!
var corePath = library+"/cores/"+boardProp["build.core"]!
var variantPath : NSString?
var variantPath : String?
if fileManager.fileExistsAtPath(corePath) {
if let variantName = boardProp["build.variant"] {
variantPath = library+"/variants/"+variantName
@ -103,7 +103,7 @@ class ASBuilder {
let useProgrammer = mode != .Upload
let interactive = mode == .Interactive
let portPath = ASSerial.fileNameForPort(port)
let toolChain = (NSApplication.sharedApplication().delegate as ASApplication).preferences.toolchainPath
let toolChain = (NSApplication.sharedApplication().delegate as! ASApplication).preferences.toolchainPath
task = NSTask()
task!.currentDirectoryPath = dir.path!
task!.launchPath = toolChain+"/bin/avrdude"
@ -231,7 +231,7 @@ class ASBuilder {
}
func disassembleProject(board: String) {
let toolChain = (NSApplication.sharedApplication().delegate as ASApplication).preferences.toolchainPath
let toolChain = (NSApplication.sharedApplication().delegate as! ASApplication).preferences.toolchainPath
task = NSTask()
task!.currentDirectoryPath = dir.path!
task!.launchPath = toolChain+"/bin/avr-objdump"

View File

@ -61,11 +61,11 @@ class ASFileNode {
func apply(closure:(ASFileNode)->()) {
closure(self)
}
func propertyList(rootPath: NSString) -> AnyObject {
func propertyList(rootPath: String) -> AnyObject {
return ""
}
class func readPropertyList(prop: NSDictionary, rootURL: NSURL) -> ASFileNode {
switch prop[kTypeKey] as String {
switch prop[kTypeKey] as! String {
case kNodeTypeProject:
return ASProject(prop, withRootURL:rootURL)
case kNodeTypeGroup:
@ -76,8 +76,8 @@ class ASFileNode {
assertionFailure("Undefined item type in file hierarchy")
}
}
func paths(rootPath: NSString) -> [NSString] {
return [NSString]()
func paths(rootPath: String) -> [String] {
return [String]()
}
func exists() -> Bool {
return true
@ -112,11 +112,11 @@ class ASFileGroup : ASFileNode {
self.expanded = true
}
init(_ prop: NSDictionary, withRootURL rootURL: NSURL) {
name = prop[kNameKey] as String
expanded = prop[kExpandedKey] as Bool
name = prop[kNameKey] as! String
expanded = prop[kExpandedKey] as! Bool
children = []
for child in (prop[kChildrenKey] as NSArray) {
children.append(ASFileNode.readPropertyList(child as NSDictionary, rootURL: rootURL))
for child in (prop[kChildrenKey] as! [NSDictionary]) {
children.append(ASFileNode.readPropertyList(child, rootURL: rootURL))
}
}
override func nodeName() -> String {
@ -128,15 +128,15 @@ class ASFileGroup : ASFileNode {
child.apply(closure)
}
}
func childrenPropertyList(rootPath: NSString) -> [AnyObject] {
func childrenPropertyList(rootPath: String) -> [AnyObject] {
return children.map() { (node) in node.propertyList(rootPath) }
}
override func propertyList(rootPath: NSString) -> AnyObject {
override func propertyList(rootPath: String) -> AnyObject {
return [kTypeKey: kNodeType, kNameKey: name, kExpandedKey: expanded,
kChildrenKey: childrenPropertyList(rootPath)]
}
override func paths(rootPath: NSString) -> [NSString] {
var allPaths = [NSString]()
override func paths(rootPath: String) -> [String] {
var allPaths = [String]()
for child in children {
allPaths += child.paths(rootPath)
}
@ -164,11 +164,11 @@ class ASFileItem : ASFileNode {
self.type = type
}
init(_ prop: NSDictionary, withRootURL rootURL: NSURL) {
type = ASFileType(rawValue: prop[kKindKey] as String)!
if let relativeURL = NSURL(string: prop[kPathKey] as NSString, relativeToURL: rootURL) {
type = ASFileType(rawValue: prop[kKindKey] as! String)!
if let relativeURL = NSURL(string: prop[kPathKey] as! String, relativeToURL: rootURL) {
url = relativeURL.standardizedURL!
} else {
url = NSURL(fileURLWithPath: prop[kPathKey] as NSString)!.standardizedURL!
url = NSURL(fileURLWithPath:(prop[kPathKey] as! String))!.standardizedURL!
}
}
override func nodeName() -> String {
@ -197,10 +197,10 @@ class ASFileItem : ASFileNode {
let resComp = Array(count: relCount-matchComp, repeatedValue: "..")+pathComp[matchComp..<pathCount]
return "/".join(resComp)
}
override func propertyList(rootPath: NSString) -> AnyObject {
override func propertyList(rootPath: String) -> AnyObject {
return [kTypeKey: kNodeTypeFile, kKindKey: type.rawValue, kPathKey: relativePath(rootPath)]
}
override func paths(rootPath: NSString) -> [NSString] {
override func paths(rootPath: String) -> [String] {
return [relativePath(rootPath)]
}
override func exists() -> Bool {
@ -232,9 +232,9 @@ class ASFileTree : NSObject, NSOutlineViewDataSource {
return root.propertyList(dir.path!)
}
func readPropertyList(prop: NSDictionary) {
root = ASFileNode.readPropertyList(prop, rootURL:dir) as ASProject
root = ASFileNode.readPropertyList(prop, rootURL:dir) as! ASProject
}
var paths : [NSString] {
var paths : [String] {
return root.paths(dir.path!)
}
@ -243,7 +243,7 @@ class ASFileTree : NSObject, NSOutlineViewDataSource {
if item == nil {
return 4
} else {
return (item as ASFileGroup).children.count
return (item as! ASFileGroup).children.count
}
}
func outlineView(outlineView: NSOutlineView, child index: Int, ofItem item: AnyObject?) -> AnyObject {
@ -259,7 +259,7 @@ class ASFileTree : NSObject, NSOutlineViewDataSource {
return root
}
} else {
let group = item as ASFileGroup
let group = item as! ASFileGroup
return group.children[index]
}
}
@ -267,6 +267,6 @@ class ASFileTree : NSObject, NSOutlineViewDataSource {
return item is ASFileGroup
}
func outlineView(outlineView: NSOutlineView, objectValueForTableColumn tableColumn: NSTableColumn?, byItem item: AnyObject?) -> AnyObject? {
return (item as ASFileNode).nodeName()
return (item as! ASFileNode).nodeName()
}
}

View File

@ -20,12 +20,12 @@ extension NSMenu {
}
}
private func subdirectories(path: NSString) -> [NSString] {
private func subdirectories(path: String) -> [String] {
let fileManager = NSFileManager.defaultManager()
var subDirs = [NSString]()
var subDirs = [String]()
var isDir : ObjCBool = false
if fileManager.fileExistsAtPath(path, isDirectory: &isDir) && isDir {
for item in fileManager.contentsOfDirectoryAtPath(path, error: nil) as [NSString] {
for item in fileManager.contentsOfDirectoryAtPath(path, error: nil) as! [String] {
let subPath = path+"/"+item
if fileManager.fileExistsAtPath(subPath, isDirectory: &isDir) && isDir {
subDirs.append(subPath)
@ -38,9 +38,9 @@ private func subdirectories(path: NSString) -> [NSString] {
private let hardwareInstance = ASHardware()
class ASHardware {
class func instance() -> ASHardware { return hardwareInstance }
let directories = [NSString]()
let programmers = ASProperties()
let boards = ASProperties()
var directories = [String]()
var programmers = ASProperties()
var boards = ASProperties()
init() {
//
// Gather hardware directories
@ -51,11 +51,11 @@ class ASHardware {
let arduinoHardwarePath = arduinoPath + "/Contents/Resources/Java/hardware"
directories += subdirectories(arduinoHardwarePath)
}
for sketchDir in userDefaults.objectForKey("Sketchbooks") as [NSString] {
for sketchDir in userDefaults.objectForKey("Sketchbooks") as! [String] {
let hardwarePath = sketchDir + "/hardware"
directories += subdirectories(hardwarePath)
}
let property = NSRegularExpression(pattern: "\\s*(\\w+)\\.(\\S+?)\\s*=\\s*(\\S.*\\S)\\s*", options: nil, error: nil)
let property = NSRegularExpression(pattern: "\\s*(\\w+)\\.(\\S+?)\\s*=\\s*(\\S.*\\S)\\s*", options: nil, error: nil)!
//
// Gather board declarations
//
@ -64,11 +64,11 @@ class ASHardware {
let provenience = dir.lastPathComponent
if let boardsFile = NSString(contentsOfFile: boardsPath, usedEncoding: nil, error: nil) {
var seen = [String: Bool]()
for line in boardsFile.componentsSeparatedByString("\n") as [NSString] {
if let match = property?.firstMatchInString(line, options: .Anchored, range: NSMakeRange(0, line.length)) {
let board = line.substringWithRange(match.rangeAtIndex(1))
let property = line.substringWithRange(match.rangeAtIndex(2))
let value = line.substringWithRange(match.rangeAtIndex(3))
for line in boardsFile.componentsSeparatedByString("\n") as! [NSString] {
if let match = property.firstMatchInString(line as String, options: .Anchored, range: NSMakeRange(0, line.length)) {
let board = line.substringWithRange(match.rangeAtIndex(1)) as String
let property = line.substringWithRange(match.rangeAtIndex(2)) as String
let value = line.substringWithRange(match.rangeAtIndex(3)) as String
if seen.updateValue(true, forKey: board) == nil {
boards[board] = ASPropertyEntry()
boards[board]!["provenience"] = provenience
@ -88,8 +88,8 @@ class ASHardware {
let provenience = dir.lastPathComponent
if let programmersFile = NSString(contentsOfFile: programmersPath, usedEncoding: nil, error: nil) {
var seen = [String: Bool]()
for line in programmersFile.componentsSeparatedByString("\n") as [NSString] {
if let match = property?.firstMatchInString(line, options: .Anchored, range: NSMakeRange(0, line.length)) {
for line in programmersFile.componentsSeparatedByString("\n") as! [NSString] {
if let match = property.firstMatchInString(line as String, options: .Anchored, range: NSMakeRange(0, line.length)) {
let programmer = line.substringWithRange(match.rangeAtIndex(1))
let property = line.substringWithRange(match.rangeAtIndex(2))
let value = line.substringWithRange(match.rangeAtIndex(3))
@ -145,8 +145,8 @@ class ASHardware {
private let librariesInstance = ASLibraries()
class ASLibraries {
class func instance() -> ASLibraries { return librariesInstance }
let directories = [NSString]()
let libraries = [NSString]()
var directories = [String]()
var libraries = [String]()
init() {
//
// Gather hardware directories
@ -161,7 +161,7 @@ class ASLibraries {
libraries += dirs
}
}
for sketchDir in userDefaults.objectForKey("Sketchbooks") as [NSString] {
for sketchDir in userDefaults.objectForKey("Sketchbooks") as! [String] {
let librariesPath = sketchDir + "/libraries"
let dirs = subdirectories(librariesPath)
if dirs.count > 0 {

View File

@ -15,7 +15,7 @@ private let kASToolchainOther = 2
class ASPreferences: NSWindowController, NSOpenSavePanelDelegate {
var toolchainPref : String {
get {
return NSUserDefaults.standardUserDefaults().objectForKey("Toolchain") as String
return NSUserDefaults.standardUserDefaults().objectForKey("Toolchain") as! String
}
set(newToolchain) {
NSUserDefaults.standardUserDefaults().setObject(newToolchain, forKey: "Toolchain")
@ -50,7 +50,7 @@ class ASPreferences: NSWindowController, NSOpenSavePanelDelegate {
var toolchainPath : String {
get {
if toolchainPref != "" {
if toolchainPref != ("" as String) {
return toolchainPref
} else {
return NSWorkspace.sharedWorkspace().URLForApplicationWithBundleIdentifier("cc.arduino.Arduino")!.path! +

View File

@ -45,7 +45,7 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
dynamic var port : String = ""
var recentBoards = [String]()
var recentProgrammers = [String]()
var logModified = NSDate.distantPast() as NSDate
var logModified = NSDate.distantPast() as! NSDate
var logSize = 0
var updateLogTimer : NSTimer?
@ -81,8 +81,8 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
board = userDefaults.stringForKey(kBoardKey)!
programmer = userDefaults.stringForKey(kProgrammerKey)!
port = userDefaults.stringForKey(kPortKey)!
recentBoards = userDefaults.objectForKey(kRecentBoardsKey) as [String]
recentProgrammers = userDefaults.objectForKey(kRecentProgrammersKey) as [String]
recentBoards = userDefaults.objectForKey(kRecentBoardsKey) as! [String]
recentProgrammers = userDefaults.objectForKey(kRecentProgrammersKey) as! [String]
var nc = NSNotificationCenter.defaultCenter()
themeObserver = nc.addObserverForName(kBindingsKey, object: nil, queue: nil, usingBlock: { (NSNotification) in
@ -164,10 +164,10 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
}
let filesInProject =
NSFileManager.defaultManager().contentsOfDirectoryAtURL(url, includingPropertiesForKeys: nil,
options: .SkipsHiddenFiles, error: nil)!
options: .SkipsHiddenFiles, error: nil) as! [NSURL]
updateProjectURL()
for file in filesInProject {
files.addFileURL(file as NSURL)
files.addFileURL(file)
}
return true
}
@ -187,14 +187,14 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
return success
}
override func readFromData(data: NSData, ofType typeName: String, error outError: NSErrorPointer) -> Bool {
if typeName != "Project" {
if typeName != ("Project" as String) {
return false
}
updateProjectURL()
let projectData : NSDictionary = NSPropertyListSerialization.propertyListFromData(data, mutabilityOption: .Immutable, format: nil, errorDescription: nil) as NSDictionary
let projectVersion = projectData[kVersionKey] as Double
let projectData : NSDictionary = NSPropertyListSerialization.propertyListFromData(data, mutabilityOption: .Immutable, format: nil, errorDescription: nil) as! NSDictionary
let projectVersion = projectData[kVersionKey] as! Double
assert(projectVersion <= floor(kCurVersion+1.0), "Project version too new for this app")
if let themeName = projectData[kThemeKey] as? NSString {
if let themeName = projectData[kThemeKey] as? String {
if let themeId = ACEView.themeIdByName(themeName) {
currentTheme = themeId
}
@ -202,7 +202,7 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
if let fontSz = projectData[kFontSizeKey] as? Int {
fontSize = UInt(fontSz)
}
files.readPropertyList(projectData[kFilesKey] as NSDictionary)
files.readPropertyList(projectData[kFilesKey] as! NSDictionary)
board = (projectData[kBoardKey] as? String) ?? board
programmer = (projectData[kProgrammerKey] as? String) ?? programmer
port = (projectData[kPortKey] as? String) ?? port
@ -228,13 +228,13 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
return
}
if (modified as NSDate).compare(logModified) == .OrderedDescending || (size as Int) != logSize {
if (modified as! NSDate).compare(logModified) == .OrderedDescending || (size as! Int) != logSize {
var enc : UInt = 0
let newText = NSString(contentsOfURL:url!, usedEncoding:&enc, error:nil)
let newText = NSString(contentsOfURL:url!, usedEncoding:&enc, error:nil) as! String
editor.setString(newText)
editor.gotoLine(1000000000, column: 0, animated: true)
logModified = modified as NSDate
logSize = size as Int
logModified = modified as! NSDate
logSize = size as! Int
}
}
}
@ -244,7 +244,7 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
}
if let file = (selection as? ASFileItem) {
var enc : UInt = 0
editor.setString(NSString(contentsOfURL:file.url, usedEncoding:&enc, error:nil))
editor.setString(NSString(contentsOfURL:file.url, usedEncoding:&enc, error:nil) as! String)
editor.setMode(UInt(file.type.aceMode))
editor.alphaValue = 1.0
mainEditor = selection
@ -252,7 +252,7 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
editor.setString("")
editor.setMode(UInt(ACEModeText))
editor.alphaValue = 0.8
logModified = NSDate.distantPast() as NSDate
logModified = NSDate.distantPast() as! NSDate
logSize = -1
mainEditor = selection
updateLog(nil)
@ -279,17 +279,17 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
func outlineViewSelectionDidChange(notification: NSNotification) {
willChangeValueForKey("hasSelection")
if outline.numberOfSelectedRows < 2 {
selectNode(outline.itemAtRow(outline.selectedRow) as ASFileNode?)
selectNode(outline.itemAtRow(outline.selectedRow) as! ASFileNode?)
}
didChangeValueForKey("hasSelection")
}
func outlineViewItemDidExpand(notification: NSNotification) {
let group = notification.userInfo!["NSObject"] as ASFileGroup
let group = notification.userInfo!["NSObject"] as! ASFileGroup
group.expanded = true
updateChangeCount(.ChangeDone)
}
func outlineViewItemDidCollapse(notification: NSNotification) {
let group = notification.userInfo!["NSObject"] as ASFileGroup
let group = notification.userInfo!["NSObject"] as! ASFileGroup
group.expanded = false
updateChangeCount(.ChangeDone)
}
@ -300,7 +300,7 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
textCell.font = NSFont.boldSystemFontOfSize(13.0)
} else {
textCell.font = NSFont.systemFontOfSize(13.0)
if !(item as ASFileNode).exists() {
if !(item as! ASFileNode).exists() {
textCell.textColor = NSColor.redColor()
}
}
@ -326,8 +326,8 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
alert.addButtonWithTitle("Move to Trash")
alert.addButtonWithTitle(selection.count == 1 ? "Remove Reference" : "Remove References")
alert.addButtonWithTitle("Cancel")
(alert.buttons[0] as NSButton).keyEquivalent = ""
(alert.buttons[1] as NSButton).keyEquivalent = "\r"
(alert.buttons[0] as! NSButton).keyEquivalent = ""
(alert.buttons[1] as! NSButton).keyEquivalent = "\r"
alert.beginSheetModalForWindow(outline.window!) { (response) in
if response != NSAlertThirdButtonReturn {
if response == NSAlertFirstButtonReturn {
@ -361,7 +361,7 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
panel.delegate = self
panel.beginSheetModalForWindow(outline.window!, completionHandler: { (returnCode: Int) -> Void in
if returnCode == NSFileHandlingPanelOKButton {
for url in panel.URLs as [NSURL] {
for url in panel.URLs as! [NSURL] {
self.files.addFileURL(url)
}
self.outline.deselectAll(self)
@ -372,7 +372,7 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
}
func panel(panel:NSSavePanel, shouldEnableURL url:NSURL) -> Bool {
func panel(panel:AnyObject, shouldEnableURL url:NSURL) -> Bool {
var shouldEnable = true
var resourceID : AnyObject?
url.getResourceValue(&resourceID, forKey:NSURLFileResourceIdentifierKey, error:nil)
@ -414,7 +414,7 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
break
}
var header = ""
if prefix != "" {
if prefix != ("" as String) {
if firstPfx == "" {
firstPfx = prefix
}
@ -541,7 +541,7 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
pushToFront(&recentBoards, board)
let userDefaults = NSUserDefaults.standardUserDefaults()
var globalBoards = userDefaults.objectForKey(kRecentBoardsKey) as [String]
var globalBoards = userDefaults.objectForKey(kRecentBoardsKey) as! [String]
pushToFront(&globalBoards, board)
userDefaults.setObject(globalBoards, forKey: kRecentBoardsKey)
@ -555,7 +555,7 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
}
@IBAction func selectBoard(item: AnyObject) {
selectedBoard = (item as NSMenuItem).title
selectedBoard = (item as! NSMenuItem).title
}
var selectedProgrammer : String {
@ -571,7 +571,7 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
pushToFront(&recentProgrammers, programmer)
let userDefaults = NSUserDefaults.standardUserDefaults()
var globalProgs = userDefaults.objectForKey(kRecentProgrammersKey) as [String]
var globalProgs = userDefaults.objectForKey(kRecentProgrammersKey) as! [String]
pushToFront(&globalProgs, programmer)
userDefaults.setObject(globalProgs, forKey: kRecentProgrammersKey)
@ -586,18 +586,18 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
}
@IBAction func selectProgrammer(item: AnyObject) {
selectedProgrammer = (item as NSMenuItem).title
selectedProgrammer = (item as! NSMenuItem).title
}
@IBAction func selectPort(item: AnyObject) {
port = (item as NSPopUpButton).titleOfSelectedItem!
port = (item as! NSPopUpButton).titleOfSelectedItem!
portTool.setTitle(port)
}
var hasUploadProtocol : Bool {
get {
if let proto = ASHardware.instance().boards[board]?["upload.protocol"] {
return proto != ""
return proto != ("" as String)
} else {
return false
}
@ -609,7 +609,7 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
var hasValidPort : Bool {
get {
return (ASSerial.ports() as NSArray).containsObject(port)
return contains(ASSerial.ports() as! [String], port)
}
}
class func keyPathsForValuesAffectingHasValidPort() -> NSSet {
@ -618,7 +618,7 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
var canUpload : Bool {
get {
return hasValidPort && (hasUploadProtocol || programmer != "")
return hasValidPort && (hasUploadProtocol || programmer != ("" as String))
}
}
class func keyPathsForValuesAffectingCanUpload() -> NSSet {

View File

@ -80,7 +80,7 @@ class ASSerialWin: NSWindowController {
let userDefaults = NSUserDefaults.standardUserDefaults()
if let portDef = (userDefaults.objectForKey("SerialDefaults") as NSDictionary).objectForKey(port) as? [String: AnyObject] {
if let portDef = (userDefaults.objectForKey("SerialDefaults") as! NSDictionary).objectForKey(port) as? [String: AnyObject] {
portDefaults = portDef
} else {
portDefaults["Theme"] = userDefaults.stringForKey("SerialTheme")
@ -89,13 +89,13 @@ class ASSerialWin: NSWindowController {
portDefaults["SendLF"] = sendLF
portDefaults["BaudRate"] = 19200
}
if let themeId = ACEView.themeIdByName(portDefaults["Theme"] as String) {
if let themeId = ACEView.themeIdByName(portDefaults["Theme"] as! String) {
currentTheme = themeId
}
fontSize = portDefaults["FontSize"] as UInt
sendCR = portDefaults["SendCR"] as Bool
sendLF = portDefaults["SendLF"] as Bool
baudRate = portDefaults["BaudRate"] as Int
fontSize = portDefaults["FontSize"] as! UInt
sendCR = portDefaults["SendCR"] as! Bool
sendLF = portDefaults["SendLF"] as! Bool
baudRate = portDefaults["BaudRate"] as! Int
if let handlerName = userDefaults.stringForKey("Bindings") {
if let handlerId = ACEView.handlerIdByName(handlerName) {
@ -162,7 +162,7 @@ class ASSerialWin: NSWindowController {
logView.setString(serialData)
readHandle.readabilityHandler = {(handle) in
let newData = handle.availableDataIgnoringExceptions()
let newString = NSString(data: newData, encoding: NSASCIIStringEncoding)!
let newString = NSString(data: newData, encoding: NSASCIIStringEncoding) as! String
self.serialData += newString
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.logView.setString(self.serialData)
@ -186,7 +186,7 @@ class ASSerialWin: NSWindowController {
}
baudRate = speed
self.task = task
portHandle = (task.standardInput as NSPipe).fileHandleForWriting
portHandle = (task.standardInput as! NSPipe).fileHandleForWriting
showWindow(self)
installReader((task.standardOutput as? NSPipe)?.fileHandleForReading)
}
@ -227,7 +227,7 @@ class ASSerialWin: NSWindowController {
}
var hasValidPort : Bool {
get {
return (ASSerial.ports() as NSArray).containsObject(port)
return contains(ASSerial.ports() as! [String], port)
}
}
@ -278,8 +278,9 @@ class ASSerialWin: NSWindowController {
}
func updatePortDefaults() {
let userDefaults = NSUserDefaults.standardUserDefaults()
let serialDefaults = NSMutableDictionary(dictionary:userDefaults.objectForKey("SerialDefaults") as NSDictionary)
let userDefaults = NSUserDefaults.standardUserDefaults()
let sd = userDefaults.objectForKey("SerialDefaults") as! [String: AnyObject]
let serialDefaults = NSMutableDictionary(dictionary: sd)
serialDefaults.setValue(NSDictionary(dictionary:portDefaults), forKey:port)
userDefaults.setObject(serialDefaults, forKey:"SerialDefaults")
}

View File

@ -15,10 +15,10 @@ class ASSketchBook {
case SketchDir(String, [SketchBookItem])
}
class func findSketch(path: NSString) -> SketchBookItem {
class func findSketch(path: String) -> SketchBookItem {
let fileManager = NSFileManager.defaultManager()
var inoSketch = SketchBookItem.Nothing
let contents = fileManager.contentsOfDirectoryAtPath(path, error: nil) as [String]
let contents = fileManager.contentsOfDirectoryAtPath(path, error: nil) as! [String]
for item in contents {
switch item.pathExtension {
case "avrsackproj":
@ -32,9 +32,9 @@ class ASSketchBook {
return inoSketch
}
private class func enumerateSketches(path: NSString) -> SketchBookItem {
private class func enumerateSketches(path: String) -> SketchBookItem {
let fileManager = NSFileManager.defaultManager()
let contents = fileManager.contentsOfDirectoryAtPath(path, error: nil) as [String]
let contents = fileManager.contentsOfDirectoryAtPath(path, error: nil) as! [String]
let sketch = findSketch(path)
switch sketch {
case .Sketch:
@ -98,7 +98,7 @@ class ASSketchBook {
}
}
class func addSketches(menu: NSMenu, target: AnyObject, action: Selector, path: NSString, inout sketches: [String]) {
class func addSketches(menu: NSMenu, target: AnyObject, action: Selector, path: String, inout sketches: [String]) {
switch enumerateSketches(path) {
case .SketchDir(let item, let sketchList):
appendSketchesToMenu(menu, target: target, action: action, sketchList: sketchList, sketches: &sketches)