Moin,
ich melde mich nochmal.
Spoiler anzeigen
Alles anzeigen
Alles anzeigen
Alles anzeigen
Nun habe ich noch eine entsprechende
Mein Problem ist jetzt folgendes:
Beim Debuggen klicke ich meinen entsprechenden Button im Menü (das habe ich entsprechend zur Übersichtlichkeit oben rausgenommen), der dann mit der
Was mache ich falsch?
Grüße
ich melde mich nochmal.
JavaScript-Quellcode: TweetWindow.swift
- import Cocoa
- import CoreLocation
- class TweetWindow: NSWindow {
- var locationManager: CLLocationManager!
- var geoCoder: CLGeocoder!
- func initialize() {
- self.titleVisibility = NSWindowTitleVisibility.Hidden;
- self.locationManager = CLLocationManager();
- self.locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
- self.locationManager.distanceFilter = 10;
- self.geoCoder = CLGeocoder();
- }
- func windowWillShow() {
- if !self.visible {
- let systemAppearanceName = (NSUserDefaults.standardUserDefaults().stringForKey("AppleInterfaceStyle") ?? "Light").lowercaseString;
- let systemAppearance = systemAppearanceName == "dark" ? NSAppearance(named: NSAppearanceNameVibrantDark) : NSAppearance(named: NSAppearanceNameVibrantLight);
- self.appearance = systemAppearance;
- self.locationManager.startUpdatingLocation();
- }
- }
- func windowWillClose() {
- self.locationManager.stopUpdatingLocation();
- }
- // Mehr kommt noch.
- }
JavaScript-Quellcode: AppDelegate.swift
- import Cocoa
- @NSApplicationMain
- class AppDelegate: NSObject, NSApplicationDelegate {
- var tweetWindowController:TweetWindowController!
- func applicationDidFinishLaunching(aNotification: NSNotification) {
- // Insert code here to initialize your application
- tweetWindowController = TweetWindowController(windowNibName: "TweetWindow");
- }
- func applicationWillTerminate(aNotification: NSNotification) {
- // Insert code here to tear down your application
- }
- func showTweetWindowInternal() {
- NSApp.activateIgnoringOtherApps(true);
- tweetWindowController.showWindow(nil);
- }
- @IBAction func showTweetWindow(sender: AnyObject) {
- showTweetWindowInternal();
- }
- }
JavaScript-Quellcode: TweetWindowController.swift
- import Cocoa
- class TweetWindowController: NSWindowController {
- var tweetWindow: TweetWindow { return self.window as! TweetWindow }
- override func windowDidLoad() {
- super.windowDidLoad()
- self.tweetWindow.initialize();
- // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
- }
- override func showWindow(sender: AnyObject?) {
- self.tweetWindow.windowWillShow()
- super.showWindow(sender)
- }
- }
Nun habe ich noch eine entsprechende
TweetWindow.xib
, in der sich mein Window befindet. Für dieses habe ich entsprechend als Klasse meine Unterklasse eingetragen, also TweetWindow
.Mein Problem ist jetzt folgendes:
Beim Debuggen klicke ich meinen entsprechenden Button im Menü (das habe ich entsprechend zur Übersichtlichkeit oben rausgenommen), der dann mit der
IBAction func showTweetWindow
verbunden ist. Der Controller wird ja oben im AppDelegate initialisiert und das sollte so korrekt sein. Im Controller versucht er dann ja self.tweetWindow
aufzurufen und dazu greift er oben darauf zurück. In dem Moment fliegt mir eine Exception: fatal error: unexpectedly found nil while unwrapping an Optional value
. Entsprechende Debug-Ausgaben zeigten mir dann, wie vermutet, dass self.window
nil ist. Ich kann mir allerdings nicht erklären, warum.Was mache ich falsch?
Grüße