Further Swift 3 fixes

This commit is contained in:
Matthias Neeracher 2016-11-21 20:33:02 +01:00 committed by Matthias Neeracher
parent 780d132e27
commit 9518d54f5f
7 changed files with 45 additions and 45 deletions

View File

@ -29,14 +29,14 @@ class ASApplication: NSObject, NSApplicationDelegate, NSMenuDelegate {
let workSpace = NSWorkspace.shared()
let userDefaults = UserDefaults.standard
let appDefaultsURL = Bundle.main.url(forResource: "Defaults", withExtension: "plist")!
var appDefaults = NSDictionary(contentsOf: appDefaultsURL) as! [String: AnyObject]
var appDefaults = NSDictionary(contentsOf: appDefaultsURL) as! [String: Any]
//
// Add dynamic app defaults
//
if let arduinoPath = workSpace.urlForApplication(withBundleIdentifier: "cc.arduino.Arduino")?.path {
appDefaults["Arduino"] = arduinoPath
}
var sketchbooks = [NSString]()
var sketchbooks = [String]()
for doc in fileManager.urls(for: .documentDirectory, in: .userDomainMask) {
sketchbooks.append(doc.appendingPathComponent("Arduino").path)
sketchbooks.append(doc.appendingPathComponent("AVRSack").path)
@ -180,7 +180,7 @@ class ASApplication: NSObject, NSApplicationDelegate, NSMenuDelegate {
}
}
class func newProjectLocation(documentWindow: NSWindow?, message: String, completion: (URL) -> ()) {
class func newProjectLocation(documentWindow: NSWindow?, message: String, completion: @escaping (URL) -> ()) {
let savePanel = NSSavePanel()
savePanel.allowedFileTypes = [kUTTypeFolder as String]
savePanel.message = message
@ -200,14 +200,14 @@ class ASApplication: NSObject, NSApplicationDelegate, NSMenuDelegate {
}
@IBAction func goToHelpPage(_ sender: AnyObject) {
let helpString: String
let helpString: CFString
switch sender.tag {
case 0:
helpString = "license.html"
helpString = "license.html" as CFString
default:
abort()
}
let locBookName = Bundle.main.object(forInfoDictionaryKey: "CFBundleHelpBookName") as! String
let locBookName = Bundle.main.object(forInfoDictionaryKey: "CFBundleHelpBookName") as! CFString
AHGotoPage(locBookName, helpString, nil)
}

View File

@ -10,15 +10,15 @@ import Foundation
class ASBuilder {
var dir = URL(fileURLWithPath: "/")
var task : Task?
var task : Process?
var continuation: (()->())?
var termination : AnyObject?
init() {
termination = NotificationCenter.default.addObserver(forName: Task.didTerminateNotification,
termination = NotificationCenter.default.addObserver(forName: Process.didTerminateNotification,
object: nil, queue: nil, using:
{ (notification: Notification) in
if notification.object as? Task == self.task {
if notification.object as? Process == self.task {
if self.task!.terminationStatus == 0 {
if let cont = self.continuation {
self.continuation = nil
@ -52,7 +52,7 @@ class ASBuilder {
func buildProject(board: String, files: ASFileTree) {
let toolChain = (NSApplication.shared().delegate as! ASApplication).preferences.toolchainPath
task = Task()
task = Process()
task!.currentDirectoryPath = dir.path
task!.launchPath = Bundle.main.path(forResource: "BuildProject", ofType: "")!
@ -111,7 +111,7 @@ class ASBuilder {
let interactive = mode == .Interactive
let portPath = ASSerial.fileName(forPort: port)
let toolChain = (NSApplication.shared().delegate as! ASApplication).preferences.toolchainPath
task = Task()
task = Process()
task!.currentDirectoryPath = dir.path
task!.launchPath = toolChain+"/bin/avrdude"
@ -182,7 +182,7 @@ class ASBuilder {
needPhase2 = true
}
if needPhase2 {
let task2 = Task()
let task2 = Process()
task2.currentDirectoryPath = dir.path
task2.launchPath = toolChain+"/bin/avrdude"
task2.arguments = loaderArgs
@ -242,7 +242,7 @@ class ASBuilder {
func disassembleProject(board: String) {
let toolChain = (NSApplication.shared().delegate as! ASApplication).preferences.toolchainPath
task = Task()
task = Process()
task!.currentDirectoryPath = dir.path
task!.launchPath = toolChain+"/bin/avr-objdump"

View File

@ -69,7 +69,7 @@ class ASFileNode : Equatable {
closure(self)
}
func propertyList(rootPath: String) -> Dictionary<String, AnyObject> {
func propertyList(rootPath: String) -> Dictionary<String, Any> {
return [:]
}
@ -127,7 +127,7 @@ class ASFileGroup : ASFileNode {
private let kChildrenKey = "Children"
private let kExpandedKey = "Expanded"
private var kNodeType : String { return kNodeTypeGroup }
fileprivate var kNodeType : String { return kNodeTypeGroup }
override init(name: String = "") {
self.children = []
@ -155,11 +155,11 @@ class ASFileGroup : ASFileNode {
}
}
func childrenPropertyList(rootPath: String) -> [AnyObject] {
func childrenPropertyList(rootPath: String) -> [Any] {
return children.map() { (node) in node.propertyList(rootPath: rootPath) }
}
override func propertyList(rootPath: String) -> Dictionary<String, AnyObject> {
override func propertyList(rootPath: String) -> Dictionary<String, Any> {
return [kTypeKey: kNodeType, kNameKey: name, kExpandedKey: expanded,
kChildrenKey: childrenPropertyList(rootPath: rootPath)]
}
@ -174,7 +174,7 @@ class ASFileGroup : ASFileNode {
}
class ASProject : ASFileGroup {
override private var kNodeType : String { return kNodeTypeProject }
override fileprivate var kNodeType : String { return kNodeTypeProject }
override init(name: String = "") {
super.init(name: name)
@ -259,7 +259,7 @@ class ASFileItem : ASFileNode {
return resComp.joined(separator: "/")
}
override func propertyList(rootPath: String) -> Dictionary<String, AnyObject> {
override func propertyList(rootPath: String) -> Dictionary<String, Any> {
return [kTypeKey: kNodeTypeFile, kKindKey: type.rawValue,
kPathKey: relativePath(relativeTo: rootPath)]
}
@ -283,7 +283,7 @@ class ASFileItem : ASFileNode {
}
override func revision() -> String? {
let task = Task()
let task = Process()
task.launchPath = Bundle.main.path(forResource: "FileRevision", ofType: "")!
let outputPipe = Pipe()
task.standardOutput = outputPipe
@ -319,7 +319,7 @@ class ASFileTree : NSObject, NSOutlineViewDataSource {
func apply(closure: (ASFileNode) -> ()) {
root.apply(closure: closure)
}
func propertyList() -> AnyObject {
func propertyList() -> Any {
return root.propertyList(rootPath: projectPath())
}
func readPropertyList(prop: Dictionary<String, AnyObject>) {
@ -330,14 +330,14 @@ class ASFileTree : NSObject, NSOutlineViewDataSource {
}
// MARK: Outline Data Source
func outlineView(_ outlineView: NSOutlineView, numberOfChildrenOfItem item: AnyObject?) -> Int {
func outlineView(_ outlineView: NSOutlineView, numberOfChildrenOfItem item: Any?) -> Int {
if item == nil {
return 4
} else {
return (item as! ASFileGroup).children.count
}
}
func outlineView(_ outlineView: NSOutlineView, child index: Int, ofItem item: AnyObject?) -> AnyObject {
func outlineView(_ outlineView: NSOutlineView, child index: Int, ofItem item: Any?) -> Any {
if item == nil {
switch index {
case 1:
@ -354,15 +354,15 @@ class ASFileTree : NSObject, NSOutlineViewDataSource {
return group.children[index]
}
}
func outlineView(_ outlineView: NSOutlineView, isItemExpandable item: AnyObject) -> Bool {
func outlineView(_ outlineView: NSOutlineView, isItemExpandable item: Any) -> Bool {
return item is ASFileGroup
}
func outlineView(_ outlineView: NSOutlineView, objectValueFor tableColumn: NSTableColumn?, byItem item: AnyObject?) -> AnyObject? {
func outlineView(_ outlineView: NSOutlineView, objectValueFor tableColumn: NSTableColumn?, byItem item: Any?) -> Any? {
return (item as! ASFileNode).nodeName()
}
let kLocalReorderPasteboardType = "ASFilePasteboardType"
func outlineView(_ outlineView: NSOutlineView, writeItems items: [AnyObject], to pasteboard: NSPasteboard) -> Bool {
private func outlineView(_ outlineView: NSOutlineView, writeItems items: [AnyObject], to pasteboard: NSPasteboard) -> Bool {
dragged = items as! [ASFileNode]
pasteboard.declareTypes([kLocalReorderPasteboardType], owner: self)
pasteboard.setData(Data(), forType: kLocalReorderPasteboardType)
@ -378,7 +378,7 @@ class ASFileTree : NSObject, NSOutlineViewDataSource {
return itemIsDescendentOfDrag(outlineView: outlineView, item: outlineView.parent(forItem: item) as! ASFileNode)
}
}
func outlineView(_ outlineView: NSOutlineView, validateDrop info: NSDraggingInfo, proposedItem item: AnyObject?, proposedChildIndex index: Int) -> NSDragOperation {
func outlineView(_ outlineView: NSOutlineView, validateDrop info: NSDraggingInfo, proposedItem item: Any?, proposedChildIndex index: Int) -> NSDragOperation {
if info.draggingPasteboard().availableType(from: [kLocalReorderPasteboardType]) == nil {
return [] // Only allow reordering drags
}
@ -400,7 +400,7 @@ class ASFileTree : NSObject, NSOutlineViewDataSource {
}
return NSDragOperation.generic
}
func outlineView(_ outlineView: NSOutlineView, acceptDrop info: NSDraggingInfo, item: AnyObject?, childIndex insertAtIndex: Int) -> Bool {
func outlineView(_ outlineView: NSOutlineView, acceptDrop info: NSDraggingInfo, item: Any?, childIndex insertAtIndex: Int) -> Bool {
var insertAtIndex = insertAtIndex
let parent : ASFileGroup = (item as? ASFileGroup) ?? root
if insertAtIndex == NSOutlineViewDropOnItemIndex {

View File

@ -13,7 +13,7 @@ typealias ASProperties = [String: ASPropertyEntry]
extension NSMenu {
func addSortedChoices(choices:[ASPropertyEntry], target: AnyObject, selector: Selector) {
for choice in choices.sorted(by: { $0["name"] < $1["name"] }) {
for choice in choices.sorted(by: { $0["name"]! < $1["name"]! }) {
let item = self.addItem(withTitle: choice["name"]!, action: selector, keyEquivalent: "")
item.target = target
}

View File

@ -86,7 +86,7 @@ class ASPreferences: NSWindowController, NSOpenSavePanelDelegate {
})
}
func panel(_ sender: AnyObject, shouldEnable url: URL) -> Bool {
func panel(_ sender: Any, shouldEnable url: URL) -> Bool {
let gccPath = url.appendingPathComponent("bin/avr-gcc")
return FileManager.default.fileExists(atPath: gccPath.path)
}

View File

@ -176,7 +176,7 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
kPortKey: port,
kRecentBoardsKey: recentBoards,
kRecentProgrammersKey: recentProgrammers
]
] as [String : Any]
return try PropertyListSerialization.data(fromPropertyList: data, format:.xml, options:0)
}
@ -238,7 +238,7 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
updateChangeCount(.changeCleared)
}
override func duplicate(_ sender: AnyObject?) {
override func duplicate(_ sender: Any?) {
let app = NSApplication.shared().delegate as! ASApplication
app.openTemplate(template: fileURL!.deletingLastPathComponent(), fromReadOnly:false)
}
@ -301,7 +301,7 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
// MARK: Printing
override func print(withSettings printSettings: [String : AnyObject], showPrintPanel: Bool, delegate: AnyObject?, didPrint didPrintSelector: Selector?, contextInfo: UnsafeMutablePointer<Void>?) {
override func print(withSettings printSettings: [String : Any], showPrintPanel: Bool, delegate: Any?, didPrint didPrintSelector: Selector?, contextInfo: UnsafeMutableRawPointer?) {
printingDone =
{ () -> () in
InvokeCallback(delegate, didPrintSelector, contextInfo);
@ -395,7 +395,7 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
let pageNoAttr = [
NSFontAttributeName: pageNoFont,
NSForegroundColorAttributeName: NSColor.white,
NSStrokeWidthAttributeName: -5.0]
NSStrokeWidthAttributeName: -5.0] as [String : Any]
let pageNoStr = "\(pageNo)"
let pageNoSize = pageNoStr.size(withAttributes: pageNoAttr)
let pageNoAt = NSPoint(
@ -478,20 +478,20 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
group.expanded = false
updateChangeCount(.changeDone)
}
func outlineView(_ outlineView: NSOutlineView, willDisplayCell cell: AnyObject, for tableColumn: NSTableColumn?, item: AnyObject) {
if let textCell = cell as? NSTextFieldCell {
func outlineView(_ outlineView: NSOutlineView, willDisplayCell cell: Any, for tableColumn: NSTableColumn?, item: Any) {
if let textCell = cell as? NSTextFieldCell, let item = item as? ASFileNode {
textCell.textColor = NSColor.black
if item === files.root || item === files.buildLog || item === files.uploadLog || item === files.disassembly {
textCell.font = NSFont.boldSystemFont(ofSize: 13.0)
} else {
textCell.font = NSFont.systemFont(ofSize: 13.0)
if !(item as! ASFileNode).exists() {
if !item.exists() {
textCell.textColor = NSColor.red
}
}
}
}
func outlineView(_ outlineView: NSOutlineView, shouldTrackCell cell: NSCell, for tableColumn: NSTableColumn?, item: AnyObject) -> Bool {
func outlineView(_ outlineView: NSOutlineView, shouldTrackCell cell: NSCell, for tableColumn: NSTableColumn?, item: Any) -> Bool {
return outlineView.isRowSelected(outlineView.row(forItem: item))
}
@ -559,7 +559,7 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
}
func panel(_ panel:AnyObject, shouldEnable url:URL) -> Bool {
func panel(_ panel:Any, shouldEnable url:URL) -> Bool {
guard let values = try? url.resourceValues(forKeys: [.fileResourceIdentifierKey]),
let resourceID = values.fileResourceIdentifier
else {

View File

@ -15,6 +15,7 @@ class ASSerialWin: NSWindowController {
@IBOutlet weak var inputLine : NSTextField!
@IBOutlet weak var logView : ACEView!
var portDefaults = [String: Any]()
var baudRate : Int = 9600 {
didSet(oldRate) {
if portHandle != nil {
@ -41,9 +42,8 @@ class ASSerialWin: NSWindowController {
dynamic var portHandle : FileHandle?
var currentTheme : ACETheme = .xcode
var fontSize : UInt = 12
var portDefaults = [String: AnyObject]()
var shouldReconnect = false
dynamic var task : Task?
dynamic var task : Process?
class func showWindowWithPort(port: String) {
if let existing = serialInstances[port] {
@ -54,7 +54,7 @@ class ASSerialWin: NSWindowController {
newInstance.showWindow(self)
}
}
class func showWindowWithPort(port: String, task: Task, speed: Int) {
class func showWindowWithPort(port: String, task: Process, speed: Int) {
if let existing = serialInstances[port] {
existing.showWindowWithTask(task: task, speed:speed)
} else {
@ -116,10 +116,10 @@ class ASSerialWin: NSWindowController {
}
}
})
termination = NotificationCenter.default.addObserver(forName: Task.didTerminateNotification,
termination = NotificationCenter.default.addObserver(forName: Process.didTerminateNotification,
object: nil, queue: nil, using:
{ (notification: Notification) in
if notification.object as? Task == self.task {
if notification.object as? Process == self.task {
self.task = nil
self.portHandle = nil
}
@ -182,7 +182,7 @@ class ASSerialWin: NSWindowController {
portHandle?.write(data)
}
func showWindowWithTask(task: Task, speed:Int) {
func showWindowWithTask(task: Process, speed:Int) {
if portHandle != nil {
connect(self)
}