{"id":188,"date":"2016-01-29T09:48:11","date_gmt":"2016-01-29T08:48:11","guid":{"rendered":"http:\/\/blog.powered-up-games.com\/wordpress\/?p=188"},"modified":"2016-01-31T16:05:43","modified_gmt":"2016-01-31T15:05:43","slug":"a-can-of-colours","status":"publish","type":"post","link":"https:\/\/powered-up-games.com\/blog\/wordpress\/archives\/188","title":{"rendered":"A can of colours"},"content":{"rendered":"<p>Last night was the first Croydon Tech City programming surgery of the new year. On several of these events last year, I forgot to write up the questions and learning. So, this time I decided to keep notes as we went along to remind me what I needed to write up.<\/p>\n<p><!--more--><\/p>\n<p>As with most of our sessions so far, our mission was to battle our way through <a href=\"https:\/\/developer.apple.com\/xcode\/interface-builder\/\">Apple&#8217;s xcode interface builder<\/a> and get it to do our bidding. We set ourselves the following objectives for the night:<\/p>\n<ul>\n<li>add a menu item<\/li>\n<li>open a window when menu item is selected<\/li>\n<li>trigger some Swift or C++ code when a menu item is selected<\/li>\n<\/ul>\n<p>Adding the menu item was a simple enough process: find the menu item control, drag and drop it onto the provided menu bar, and name the item. Easy!<\/p>\n<p>Our next objective was to get that menu item to do something. The first idea was to get it to open a colour picker window. And here&#8217;s where we hit the, by now, familiar brick wall of Apple&#8217;s obtuse developer documentation. After some considerable digging, it appeared that opening a colour picker window was a built in feature of applications created in the interface builder. So you can create a new application in Xcode, compile and run it, and press shift command C and up it pops.<\/p>\n<p>However, what we really wanted here was the ability to open the colour picker from our menu item. And we already had our new menu item and a way to open the colour picker. All we required was a way to connect it. Attempting that took the rest of the night. (In fact I didn&#8217;t find a solution until after the event.)<\/p>\n<p>I won&#8217;t list all of the things we tried, or all the many pages of documentation we skimmed through looking for an answer to this seemingly trivial problem. Instead, I&#8217;ll skip to the end.<\/p>\n<p>To open the colour picker from a menu item:<\/p>\n<ul>\n<li>click on the menu item<\/li>\n<li>connect Sent Actions &#8220;action&#8221; to the Application<\/li>\n<li>choose orderFrontColorPanel: in the menu that pops up<\/li>\n<li>compile and run<\/li>\n<\/ul>\n<p>Of course, once I&#8217;d finally worked this out, I discovered that there was already a menu item that did exactly this in the Format sub menu of the Font menu. And this is given to you by default. But it was a relief to have figured it out for my own peace of mind.<\/p>\n<p>My Tech City programming surgery currently runs monthly on the last Thursday from 7pm to 9pm at <a href=\"http:\/\/matthewsyard.com\">Matthews Yard<\/a>. There&#8217;s no charge to attend. If you have a programming problem that has you flummoxed, or you&#8217;d just like some help learning to program, come along and we&#8217;ll give you a hand.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Last night was the first Croydon Tech City programming surgery of the new year. On several of these events last year, I forgot to write up the questions and learning. So, this time I decided to keep notes as we went along to remind me what I needed to write up.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[40,41,25,43,22,39,44,20,19],"class_list":["post-188","post","type-post","status-publish","format-standard","hentry","category-programming","tag-color-picker","tag-colour-picker","tag-croydon","tag-mac-osx","tag-matthews-yard","tag-programming","tag-storyboard","tag-tech-city","tag-xcode"],"_links":{"self":[{"href":"https:\/\/powered-up-games.com\/blog\/wordpress\/wp-json\/wp\/v2\/posts\/188","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/powered-up-games.com\/blog\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/powered-up-games.com\/blog\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/powered-up-games.com\/blog\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/powered-up-games.com\/blog\/wordpress\/wp-json\/wp\/v2\/comments?post=188"}],"version-history":[{"count":9,"href":"https:\/\/powered-up-games.com\/blog\/wordpress\/wp-json\/wp\/v2\/posts\/188\/revisions"}],"predecessor-version":[{"id":195,"href":"https:\/\/powered-up-games.com\/blog\/wordpress\/wp-json\/wp\/v2\/posts\/188\/revisions\/195"}],"wp:attachment":[{"href":"https:\/\/powered-up-games.com\/blog\/wordpress\/wp-json\/wp\/v2\/media?parent=188"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/powered-up-games.com\/blog\/wordpress\/wp-json\/wp\/v2\/categories?post=188"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/powered-up-games.com\/blog\/wordpress\/wp-json\/wp\/v2\/tags?post=188"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}