{"id":245,"date":"2006-09-21T16:15:55","date_gmt":"2006-09-21T20:15:55","guid":{"rendered":"http:\/\/auroralux.net\/blog\/2006\/09\/21\/cocoa-bindings\/"},"modified":"2006-09-27T07:21:38","modified_gmt":"2006-09-27T11:21:38","slug":"cocoa-bindings","status":"publish","type":"post","link":"https:\/\/fhmiv.net\/blog\/2006\/09\/21\/cocoa-bindings\/","title":{"rendered":"Cocoa Bindings"},"content":{"rendered":"<p>Wil Shipley of Delicious Monster <a href=\"http:\/\/wilshipley.com\/blog\/2006\/03\/pimp-my-code-part-9-beginner-code.html\">pointed out<\/a> that the challenge from Chapter 4 of Aaron Hillegas&#8217; book &#8220;Cocoa Programming for Mac OS X&#8221; can be easily solved by using Cocoa Bindings, rather than using the more typical target\/action approach. When I was going through Aaron&#8217;s book, I hadn&#8217;t been exposed to Cocoa Bindings yet, since those aren&#8217;t introduced until Chapter 6. <\/p>\n<p>I thought, &#8216;Huh, yep, that way looks pretty easy,&#8217; but there are a few steps missing from Wil&#8217;s description that are critical if it&#8217;s to work right. I admit I don&#8217;t understand all of them; I&#8217;m busy reading the Cocoa Bindings and Core Data documentation to try to fill in my understanding. <\/p>\n<p>So here&#8217;s what I did:<br \/>\nAdd a controller class for the methods. This is implied and easy to see. I called mine AppController. <\/p>\n<p>Remove the button from the Window in IB; you don&#8217;t need it anymore! <\/p>\n<p>Drag an NSObjectController instance from the palette to your NIB. Change the class name to match the controller you created in step 1.<\/p>\n<p>Now, your object controller should show up in the Bindings -> Value -> Bind To inspector when you&#8217;ve got either your input or your output text field selected. Without adding the NSObjectController, I floundered around for a minute or two trying to figure out what to do at this stage of trying to follow Wil&#8217;s example. <\/p>\n<p>For some reason I had to modify Bindings -> Availability -> Editable and Enabled for the input text field; I set them both to isEditable on NSObjectController. Finally, I selected the NSObjectController in my NIB and set its Editable attribute to True. Now when I run the app, I can enter characters in the input field, tab or return out, and the count of characters updates to the output field. Pretty cool!<\/p>\n<p>I think someone should sponsor a contest to see who can make the most useful application with no code. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Wil Shipley of Delicious Monster pointed out that the challenge from Chapter 4 of Aaron Hillegas&#8217; book &#8220;Cocoa Programming for Mac OS X&#8221; can be easily solved by using Cocoa Bindings, rather than using the more typical target\/action approach. When &hellip; <a href=\"https:\/\/fhmiv.net\/blog\/2006\/09\/21\/cocoa-bindings\/\">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\/245"}],"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=245"}],"version-history":[{"count":0,"href":"https:\/\/fhmiv.net\/blog\/wp-json\/wp\/v2\/posts\/245\/revisions"}],"wp:attachment":[{"href":"https:\/\/fhmiv.net\/blog\/wp-json\/wp\/v2\/media?parent=245"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fhmiv.net\/blog\/wp-json\/wp\/v2\/categories?post=245"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fhmiv.net\/blog\/wp-json\/wp\/v2\/tags?post=245"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}