• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Swift bindings issue, Swift.Dictionary, NSMutableDictionary and NSObjectController
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Swift bindings issue, Swift.Dictionary, NSMutableDictionary and NSObjectController (From: Samuel Williams <email@hidden>)
 >Re: Swift bindings issue, Swift.Dictionary, NSMutableDictionary and NSObjectController (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: Swift bindings issue, Swift.Dictionary, NSMutableDictionary and NSObjectController
  • Next by Date: Re: Secure coding NSArray
  • Previous by thread: Re: Swift bindings issue, Swift.Dictionary, NSMutableDictionary and NSObjectController
  • Next by thread: ScalableUserInterface.framework
  • Index(es):
    • Date
    • Thread