cocoa-bindings

Use cocoa bindings and threads

末鹿安然 提交于 2021-01-29 11:23:48
问题 I have a few labels bound to a few variables that are modified in other threads via GCD. Now I've read that cocoa bindings are not thread safe but my app is running fine (the UI updates when the values of the variables are updated in a background thread) Would it be the correct way to do the calculations in the background thread and if I need to change the variable value make this via DispatchQueue.main.sync() { self.variable = newValue } ? If cocoa bindings are not thread safe, why I never

Binding to an NSDictionary's “allValues” array

ぃ、小莉子 提交于 2020-01-24 10:27:49
问题 Am I misunderstanding something about bindings? I bind (an NSArrayController's content) to an NSDictionary's "allValues" array, and it thinks it's empty. I bind to a random object with a property that I've set to be that same NSDictionary's "allValues" array, and it works fine. Is this expected behavior, or am I doing something wrong? Furthermore, if this is expected, what is the standard way to deal with this? Making relatively purposeless objects just to hold arrays in properties so I can

What are the correct bindings for an NSComboBox for use with Core Data

谁说胖子不能爱 提交于 2020-01-13 19:25:05
问题 Imagine if you will a Core Data app with two entities (Employee, and Department). Employees have a to-one relationship with department (department) and the inverse is a to-many relationship (employees). In the UI you can select individual Employee entities and edit the details in a detail area (there are of course other attributes and there is UI for adding and editing Department entities). When using a popup button the bindings are: content = PopUpArrayController.arrangedObjects content

Should I need to unbind cocoa-bindings in dealloc of windowController?

倖福魔咒の 提交于 2020-01-09 05:26:04
问题 I have window controller and view controller that use core data bindings, but I want to be able to have those views really, truly get deallocated. I then want to reset the managedObjectContext and at that point have given up as much memory as possible. I have found that I am required to unbind things which I've bound in the Nib, or the MOC keeps the Nib objects retained. The issue is this EXEC_BAD_ACCESS trace: If I do not unbind all of the bindings, even those created in Interface Builder,

Update property bound from text field without needing to press Enter

孤街醉人 提交于 2020-01-05 07:17:08
问题 I have a text field and I bind it to an NSString instance variable. When I type in the text field, it does not update the variable. It waits until I press the Enter key. I don't want to hit Enter every time. What do I need to change in order to make the binding change value immediately? 回答1: By default, the value binding of an NSTextField does not update continuously. To fix this, you need, after selecting your text field, to check the "Continuously Updates Value" box in the Bindings

Coercing a KVC type

穿精又带淫゛_ 提交于 2020-01-05 06:39:47
问题 I would like to parse XML to populate KVC compliant objects but, my parser is very dumb, it simply assembles NSStrings from the XML attributes/tags and tries to set them via KVC. This works for actual strings and numbers (I believe) but I need to also set dates. The problem is obviously that the parser doesn't know the string represents a date and it tries to sit it using the vanilla KVC calls - afterwhich the KVC framework complains about the type mismatch (setting a string on a date field).

Swift: Cocoa binding value to a computed property does not work

你离开我真会死。 提交于 2020-01-04 06:17:07
问题 I am learning KVC and binding. Currently, I am trying to bind an NSTextField to a computed property colorWallStr . I have bound the sliders' value to the corresponding color variable and also bound the value of the label to the computed property. However, the content of the label does not change when I move the slide. // Inside MainWindowController dynamic var colorRed: CGFloat = 1.0 dynamic var colorGreen: CGFloat = 1.0 dynamic var colorBlue: CGFloat = 0.0 dynamic var colorWallStr: String {

Separator item in NSPopupButton with bindings

天大地大妈咪最大 提交于 2020-01-03 07:21:28
问题 The contents of a NSPopupButton are bound to an NSArray of strings. How can we insert a separator item via bindings? The " - " strings (like in the olden/Classic days) doesn't work, i.e. shows up literally as a " - " menu item. Is there any out-of-the-box solution with standard Cocoa classes and bindings? This should be a trivial problem but I can't find any solution to the problem that doesn't involve silly hacks like subclassing NSMenu , NSPopupButton or other non-intuitive work arounds.

New Core Data object doesn't show up in NSArrayController arrangedObjects

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-02 05:48:06
问题 When I insert a new object in a Core Data managed object context and shortly after that try to find this new object in the NSArrayController (which is connect with the managedObjectContext through binding), I can't find it. I do the creation and search in one method. My question now. How long does it take for a new inserted object to show up in the NSArrayControllers arrangedObject array? Update: Here is the code for inserting and fetching the new objects NSEntityDescription *entity = [[[self

Make NSTextField update its bound value when setting its string value programmatically

喜欢而已 提交于 2019-12-25 04:11:34
问题 I have an NSTextField bound to a key in the user defaults. When I press enter or leave the field the bound value is properly updated (I have an observer for it). However when I programmatically set the value of the text field the bound value is not updated. The text field however shows the new string I set with: stockField1.stringValue = [sender representedObject]; (it's set from a menu item handler). Is it necessary to send an additional message to the text field or how else can I make this