2016-12-07 3 views
0

hier zum Aufruf ist der Code:EXC_BAD_ACCESS Error-Methode in schnellen

import Cocoa 

@NSApplicationMain 
class AppDelegate: NSObject, NSApplicationDelegate { 

    @IBOutlet weak var window: NSWindow! 

    @IBAction func changeBtn(_ sender: NSButton) { 
     obj1.changeColor() 
     obj2.changeBackgroundColor() 
     objFld1.textColor = obj1.color 
     objFld2.drawsBackground = true 
     objFld2.backgroundColor = obj2.backgroundColor 
    } 

    @IBOutlet weak var objFld1: NSTextField! 
    @IBOutlet weak var objFld2: NSTextField! 
    class colored { 
     var color = NSColor.black 
     var backgroundColor = NSColor.gray 
     func changeColor() { 
      color = NSColor.yellow 
     } 
     func changeBackgroundColor() { 
      backgroundColor = NSColor.blue 
     } 
    } 

    var obj1: colored 
    var obj2: colored 
    override init() { 
     obj1 = colored() 
     obj2 = colored() 
    } 

    func applicationDidFinishLaunching(_ aNotification: Notification) { 
     // Insert code here to initialize your application 
    } 

    func applicationWillTerminate(_ aNotification: Notification) { 
     // Insert code here to tear down your application 
    } 


} 

Alles sieht unschuldig und compiliert und einfach gut startet, aber wenn ich die Schaltfläche „Ändern“ klicken, ich habe einen Fehler (im Debug Modus):

enter image description here

Im Release-Modus, wird der Fehler an einem anderen Ort:

enter image description here

Irgendeine Idee über was schief gelaufen ist?

macOS Sierra, Xcode 8.1 (8B62)

Die Debug-Sitzung gibt mir diese Info:

InheritProgram`@objc AppDelegate.changeBtn(NSButton) ->(): 
    0x100001f10 <+0>: pushq %rbp 
    0x100001f11 <+1>: movq %rsp, %rbp 
    0x100001f14 <+4>: subq $0x30, %rsp 
    0x100001f18 <+8>: movq %rdi, -0x8(%rbp) 
    0x100001f1c <+12>: movq %rdx, %rdi 
    0x100001f1f <+15>: movq %rsi, -0x10(%rbp) 
    0x100001f23 <+19>: movq %rdx, -0x18(%rbp) 
    0x100001f27 <+23>: callq 0x100002bd8    ; symbol stub for: objc_retain 
    0x100001f2c <+28>: movq -0x8(%rbp), %rdi 
    0x100001f30 <+32>: movq %rax, -0x20(%rbp) 
    0x100001f34 <+36>: callq 0x100002bd8    ; symbol stub for: objc_retain 
    0x100001f39 <+41>: movq -0x18(%rbp), %rdi 
    0x100001f3d <+45>: movq -0x8(%rbp), %rsi 
    0x100001f41 <+49>: movq %rax, -0x28(%rbp) 
    0x100001f45 <+53>: callq 0x100001bd0    ; InheritProgram.AppDelegate.changeBtn (__ObjC.NSButton) ->() at AppDelegate.swift:16 
    0x100001f4a <+58>: movq -0x8(%rbp), %rdi 
    0x100001f4e <+62>: callq 0x100002bd2    ; symbol stub for: objc_release 
    0x100001f53 <+67>: addq $0x30, %rsp 
    0x100001f57 <+71>: popq %rbp 
    0x100001f58 <+72>: retq 

Antwort

1

haben noch keine Ahnung, was da passiert ist, aber den Code in ein neues Projekt zu kopieren arbeitete völlig in Ordnung .

0

In einer sehr ähnlichen Situation, ein Produkt> Clean behoben das gleiche Problem für mich. Eine einfache Klasse stürzte bei der ersten Eigenschaft der Datei mit EXC_BAD_ACCESS ab.