Fixed compiler issues. Starting to get very annoyed about optionals.
This commit is contained in:
parent
4857ddc018
commit
96e857dbee
|
@ -4,11 +4,18 @@ import Cocoa
|
|||
var spaced = false
|
||||
var firstvert = true
|
||||
|
||||
// keep alive
|
||||
// apparently I'm not allowed to declare a variable and then assign to it first thing in a function
|
||||
// it'd be great if people weren't so afraid of nil pointers
|
||||
var keepAliveMainwin: Window? = nil
|
||||
|
||||
func appLaunched() {
|
||||
var mainwin = Window()
|
||||
mainwin.SetMargined(spaced)
|
||||
|
||||
mainwin.Show()
|
||||
|
||||
keepAliveMainwin = mainwin
|
||||
}
|
||||
|
||||
class appDelegate : NSObject, NSApplicationDelegate {
|
||||
|
|
|
@ -9,29 +9,34 @@ func isAmbiguous(view: NSView, indent: Int) {
|
|||
view.window?.visualizeConstraints(view.superview!.constraints)
|
||||
}
|
||||
for subview in view.subviews {
|
||||
tIsAmbiguous(subview as! NSView, indent + 1)
|
||||
isAmbiguous(subview as! NSView, indent + 1)
|
||||
}
|
||||
}
|
||||
|
||||
class Window : NSWindow, Control {
|
||||
private var c: tControl?
|
||||
private var c: Control?
|
||||
private var margined: Bool
|
||||
|
||||
init() {
|
||||
self.c = nil
|
||||
self.margined = false
|
||||
// we have to initialize our own instance variables first, unfortunately (thanks erica in irc.freenode.net/#swift-lang)
|
||||
super.init(
|
||||
contentRect: NSMakeRect(0, 0, 320, 240),
|
||||
styleMask: (NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask),
|
||||
backing: NSBackingStoreType.Buffered,
|
||||
defer: true)
|
||||
self.title = "Auto Layout Test"
|
||||
self.c = nil
|
||||
self.margined = false
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("can't use this constructor, sorry")
|
||||
}
|
||||
|
||||
func SetControl(c: Control) {
|
||||
self.c = c
|
||||
var contentView = self.contentView as! NSView
|
||||
contentView.addSubview(self.c?.View())
|
||||
contentView.addSubview(self.c!.View())
|
||||
self.Relayout()
|
||||
}
|
||||
|
||||
|
@ -43,7 +48,7 @@ class Window : NSWindow, Control {
|
|||
func Show() {
|
||||
self.cascadeTopLeftFromPoint(NSMakePoint(20, 20))
|
||||
self.makeKeyAndOrderFront(self)
|
||||
tIsAmbiguous(self.contentView as! NSView, 0)
|
||||
isAmbiguous(self.contentView as! NSView, 0)
|
||||
}
|
||||
|
||||
func View() -> NSView {
|
||||
|
@ -59,13 +64,11 @@ class Window : NSWindow, Control {
|
|||
return
|
||||
}
|
||||
|
||||
var contentView = self.w.contentView as! NSView
|
||||
var contentView = self.contentView as! NSView
|
||||
contentView.removeConstraints(contentView.constraints)
|
||||
|
||||
// TODO why can't I just say var views = [ "view": p.view ]?
|
||||
// I think the parser is getting confused
|
||||
var views = [
|
||||
"view": self.c?.View(),
|
||||
"view": self.c!.View(),
|
||||
]
|
||||
var margin = ""
|
||||
if self.margined {
|
||||
|
|
Loading…
Reference in New Issue