{"id":293,"date":"2007-03-03T18:36:14","date_gmt":"2007-03-03T22:36:14","guid":{"rendered":"http:\/\/auroralux.net\/blog\/2007\/03\/03\/cocoa-bindings-are-awesome-yet-fraught-with-peril-for-the-inexperienced\/"},"modified":"2007-03-03T19:02:41","modified_gmt":"2007-03-03T23:02:41","slug":"cocoa-bindings-are-awesome-yet-fraught-with-peril-for-the-inexperienced","status":"publish","type":"post","link":"https:\/\/fhmiv.net\/blog\/2007\/03\/03\/cocoa-bindings-are-awesome-yet-fraught-with-peril-for-the-inexperienced\/","title":{"rendered":"Cocoa Bindings are awesome, yet fraught with peril for the inexperienced"},"content":{"rendered":"<p>Apparently ivars that are bound to from a nib, via a controller object, don&#8217;t have an initial or default value unless I assign one either via code or via the UI element.<\/p>\n<p>Almost all of my experience with the NeXT and Apple APIs pre-dates bindings and core data by nearly a decade, but I&#8217;ve had enough of the kool-aid to know the lines of code I never write are much less likely to have bugs than the lines I do write. <\/p>\n<p>Lately I&#8217;ve been working on a couple of one-off apps for my personal use, and also to help my mom with gallery images for her <a href=\"http:\/\/zeninkart.com\">website<\/a>. In the process I&#8217;m learning that the practice of bindings is a bit more complicated than the theory of bindings. <\/p>\n<p>For example, I&#8217;m working on a simple application that takes a directory full of images, scales each one to a particular square dimension, and pads the shorter side with a user-chosen color. In the NIB for this app, I have an NSTextField for the target dimension and an NSColorWell for the background color.<\/p>\n<p>I&#8217;ve discovered that when I launch the app, those IB elements that are bound through an NSObjectController to ivars in MyDocument don&#8217;t have an initial default value! For example one of my ivars is *backgroundColor, and the color well is bound to it through the NSObjectController. If I try to read that value from another method in MyDocument without first setting it either via code, e.g. backgroundColor = [NSColor colorBlack], or via the NSColorWell UI element itself, the ivar will be nil! I spent half an hour this afternoon using GDB to track this backwards through my set of Core Image filters before I finally figured it out.<\/p>\n<p>Anyone know how to fix this? I see Core Data has a willReadValueForKey: but I don&#8217;t know if it would do the trick. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Apparently ivars that are bound to from a nib, via a controller object, don&#8217;t have an initial or default value unless I assign one either via code or via the UI element. Almost all of my experience with the NeXT &hellip; <a href=\"https:\/\/fhmiv.net\/blog\/2007\/03\/03\/cocoa-bindings-are-awesome-yet-fraught-with-peril-for-the-inexperienced\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[11],"_links":{"self":[{"href":"https:\/\/fhmiv.net\/blog\/wp-json\/wp\/v2\/posts\/293"}],"collection":[{"href":"https:\/\/fhmiv.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fhmiv.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fhmiv.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/fhmiv.net\/blog\/wp-json\/wp\/v2\/comments?post=293"}],"version-history":[{"count":0,"href":"https:\/\/fhmiv.net\/blog\/wp-json\/wp\/v2\/posts\/293\/revisions"}],"wp:attachment":[{"href":"https:\/\/fhmiv.net\/blog\/wp-json\/wp\/v2\/media?parent=293"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fhmiv.net\/blog\/wp-json\/wp\/v2\/categories?post=293"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fhmiv.net\/blog\/wp-json\/wp\/v2\/tags?post=293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}