Re: Swift bindings issue, Swift.Dictionary, NSMutableDictionary and NSObjectController
Re: Swift bindings issue, Swift.Dictionary, NSMutableDictionary and NSObjectController
- Subject: Re: Swift bindings issue, Swift.Dictionary, NSMutableDictionary and NSObjectController
- From: Samuel Williams <email@hidden>
- Date: Mon, 15 Feb 2016 11:49:48 +1300
Yeah, the easiest solution was to not use a dictionary but use a class,
which copied the data into the dictionary.
Here is the top level sheet:
class PMSRConfigurationSheet: NSWindowController {
dynamic var metadata: [String : AnyObject] = [String : AnyObject]()
override class func keyPathsForValuesAffectingValueForKey(key: String) ->
Set<String> {
if (key != "metadata") {
return ["metadata"]
} else {
return []
}
}
@IBOutlet var objectController: NSObjectController?
@IBAction func apply(sender: AnyObject?) {
objectController?.commitEditing()
if let window = self.window {
if let sheetParent = window.sheetParent {
sheetParent.endSheet(window, returnCode: NSModalResponseContinue)
}
}
}
@IBAction func cancel(sender: AnyObject?) {
objectController?.discardEditing()
if let window = self.window {
if let sheetParent = window.sheetParent {
sheetParent.endSheet(window, returnCode: NSModalResponseAbort)
}
}
}
}
Here is the actually subclass with some properties:
@objc(PMSRExpenseReportConfigurationSheet)
class PMSRExpenseReportConfigurationSheet: PMSRConfigurationSheet {
dynamic var startDate: NSDate? {
get {
return self.metadata["startDate"] as? NSDate
}
set(value) {
self.metadata["startDate"] = value
}
}
dynamic var endDate: NSDate? {
get {
return self.metadata["endDate"] as? NSDate
}
set(value) {
self.metadata["endDate"] = value
}
}
override init(window: NSWindow?) {
super.init(window: window)
}
required init?(coder: NSCoder) {
super.init(coder: coder)
}
init() {
self.init(windowNibName: "PMSRExpenseReportConfigurationSheet")
}
override func apply(sender: AnyObject?) {
print("Date range: \(self.startDate) -> \(self.endDate)")
super.apply(sender)
}
}
Works perfectly!
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden