<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" >

<channel><title><![CDATA[Gieta Laksmana - Blog]]></title><link><![CDATA[https://www.gietal.net/blog]]></link><description><![CDATA[Blog]]></description><pubDate>Mon, 21 Sep 2026 14:33:40 -0700</pubDate><generator>Weebly</generator><item><title><![CDATA[XCode10 and prebuild script output files xcfilelist]]></title><link><![CDATA[https://www.gietal.net/blog/xcode10-and-prebuild-script-output-files-xcfilelist]]></link><comments><![CDATA[https://www.gietal.net/blog/xcode10-and-prebuild-script-output-files-xcfilelist#comments]]></comments><pubDate>Sun, 14 Oct 2018 17:00:00 GMT</pubDate><category><![CDATA[software engineering]]></category><category><![CDATA[xcode]]></category><guid isPermaLink="false">https://www.gietal.net/blog/xcode10-and-prebuild-script-output-files-xcfilelist</guid><description><![CDATA[&#8203;Found another quirk with XCode 10. Although this time they did mention it on their release notes (I read the release notes after I hit this issue).Let's say you have a simple project that generates a file on your pre-build phase, and you include that file on the compilation phase.                &#8203;This setup will work just fine on&nbsp;Xcode&nbsp;9 with the old build system. However, on the new build system on&nbsp;Xcode 10, when you build the project for the first time you will get  [...] ]]></description><content:encoded><![CDATA[<div class="paragraph">&#8203;Found another quirk with XCode 10. Although this time they did mention it on their release notes (I read the release notes after I hit this issue).<br /><br />Let's say you have a simple project that generates a file on your pre-build phase, and you include that file on the compilation phase.</div>  <div><div class="wsite-image wsite-image-border-none " style="padding-top:10px;padding-bottom:10px;margin-left:0;margin-right:0;text-align:center"> <a> <img src="https://www.gietal.net/uploads/2/6/4/8/26484310/screen-shot-2018-10-07-at-2-33-39-pm_orig.png" alt="Picture" style="width:auto;max-width:100%" /> </a> <div style="display:block;font-size:90%"></div> </div></div>  <div><div class="wsite-image wsite-image-border-none " style="padding-top:10px;padding-bottom:10px;margin-left:0;margin-right:0;text-align:center"> <a> <img src="https://www.gietal.net/uploads/2/6/4/8/26484310/screen-shot-2018-10-07-at-2-33-29-pm_orig.png" alt="Picture" style="width:auto;max-width:100%" /> </a> <div style="display:block;font-size:90%"></div> </div></div>  <div class="paragraph">&#8203;This setup will work just fine on&nbsp;Xcode&nbsp;9 with the old build system. However, on the new build system on&nbsp;Xcode 10, when you build the project for the first time you will get an error saying that the file couldn't be found:</div>  <div><div class="wsite-image wsite-image-border-none " style="padding-top:10px;padding-bottom:10px;margin-left:0;margin-right:0;text-align:center"> <a> <img src="https://www.gietal.net/uploads/2/6/4/8/26484310/screen-shot-2018-10-07-at-2-44-53-pm_orig.png" alt="Picture" style="width:auto;max-width:100%" /> </a> <div style="display:block;font-size:90%"></div> </div></div>  <div class="paragraph">&#8203;When you try to check if the file was there, you will be hit with confusion as the file is generated properly. So what's up with that?<br /><br />According to Xcode 10&nbsp;release notes, you now have to explicitly add the generated files name in the Output Files field of the phase, otherwise the build system might try to search for the files before they are generated.&#8203;&nbsp;</div>  <div><div class="wsite-image wsite-image-border-none " style="padding-top:10px;padding-bottom:10px;margin-left:0;margin-right:0;text-align:center"> <a> <img src="https://www.gietal.net/uploads/2/6/4/8/26484310/screen-shot-2018-10-07-at-2-34-18-pm_orig.png" alt="Picture" style="width:auto;max-width:100%" /> </a> <div style="display:block;font-size:90%"></div> </div></div>  <div class="paragraph">If you have several generated files that are being used by multiple targets and don't want to duplicate your efforts, you can use the new <font color="#d5d5d5">xcfilelist</font> file that is available for XCode 10. Simply list the generated files inside the xcfilelist, and assign the xcfilelist as an Output File Lists of the phase</div>  <div><div class="wsite-image wsite-image-border-none " style="padding-top:10px;padding-bottom:10px;margin-left:0;margin-right:0;text-align:center"> <a> <img src="https://www.gietal.net/uploads/2/6/4/8/26484310/screen-shot-2018-10-07-at-2-37-15-pm_orig.png" alt="Picture" style="width:auto;max-width:100%" /> </a> <div style="display:block;font-size:90%"></div> </div></div>  <div><div class="wsite-image wsite-image-border-none " style="padding-top:10px;padding-bottom:10px;margin-left:0;margin-right:0;text-align:center"> <a> <img src="https://www.gietal.net/uploads/2/6/4/8/26484310/screen-shot-2018-10-07-at-2-37-50-pm_orig.png" alt="Picture" style="width:auto;max-width:100%" /> </a> <div style="display:block;font-size:90%"></div> </div></div>  <div class="paragraph"><span>aand voila, the build system should now find your file correctly</span><br /><br />Here's the full Xcode 10 release notes:<br />&#8203;<br /><a href="https://developer.apple.com/documentation/xcode_release_notes/xcode_10_release_notes/build_system_release_notes_for_xcode_10" target="_blank">https://developer.apple.com/documentation/xcode_release_notes/xcode_10_release_notes/build_system_release_notes_for_xcode_10</a><br /><br /></div>]]></content:encoded></item><item><title><![CDATA[CoreData on macOS Mojave (10.14.0) shenanigans]]></title><link><![CDATA[https://www.gietal.net/blog/coredata-on-macos-mojave-10140-shenanigans]]></link><comments><![CDATA[https://www.gietal.net/blog/coredata-on-macos-mojave-10140-shenanigans#comments]]></comments><pubDate>Wed, 26 Sep 2018 21:18:11 GMT</pubDate><category><![CDATA[shenanigans]]></category><category><![CDATA[software engineering]]></category><category><![CDATA[swift]]></category><guid isPermaLink="false">https://www.gietal.net/blog/coredata-on-macos-mojave-10140-shenanigans</guid><description><![CDATA[UPDATE (10/16/2018): Apple has closed my bug report about this as resolved. So hopefully the fix will be out on Mojave 10.14.1tldr: overwriting a binary blob greater than 100kb will unnecessarily create extra files on each save with CoreData on macOS Mojave (10.14.0)​Hookay, I was pretty excited to try out macOS Mojave and their dark mode. Instead I found a bug in CoreDataIf you'd like to follow along the code, the code is available at my github:https://github.com/gietal/AppleSandbox/tree/mast [...] ]]></description><content:encoded><![CDATA[<div class="paragraph"><strong><font color="#D5D5D5">UPDATE (10/16/2018): Apple has closed my bug report about this as resolved. So hopefully the fix will be out on Mojave 10.14.1</font><br><br>tldr: overwriting a binary blob greater than 100kb will unnecessarily create extra files on each save with CoreData on macOS Mojave (10.14.0)</strong></div><div class="paragraph">&#8203;Hookay, I was pretty excited to try out macOS Mojave and their dark mode. Instead I found a bug in CoreData<br><br>If you'd like to follow along the code, the code is available at my github:<br><a href="https://github.com/gietal/AppleSandbox/tree/master/CoreData/CoreDataPlayground">https://github.com/gietal/AppleSandbox/tree/master/CoreData/CoreDataPlayground</a><br><br>Quick overview of CoreData, it stores your data in a sqlite database which live in your App's "Application Support" folder under ~/Library/&lt;Your app bundle identifier&gt; or ~/Library/Containers/&lt;Your app bundle identifier&gt;/Data/Library for sandboxed apps. You can store different types of data with CoreData such as string, int, float, bool, and even binary blob. When storing binary blob, you have an option to store it on an external storage:</div><div><div class="wsite-image wsite-image-border-none" style="padding-top:10px;padding-bottom:10px;margin-left:0;margin-right:0;text-align:center"><a><img src="https://www.gietal.net/uploads/2/6/4/8/26484310/screen-shot-2018-10-06-at-7-11-12-pm_orig.png" alt="Picture" style="width:auto;max-width:100%"></a><div style="display:block;font-size:90%"></div></div></div><div class="paragraph">&#8203;This is useful for bigger binary blob, as it&rsquo;s less efficient to store and fetch a big binary blob form the sqlite database. If you try to store a big binary blob (bigger than 100kb), and you have that option enabled, CoreData will automatically decide to store your blob into a hidden folder called &lt;Your DB name&gt;_Support/_EXTERNAL_DATA</div><div><div class="wsite-image wsite-image-border-none" style="padding-top:10px;padding-bottom:10px;margin-left:0;margin-right:0;text-align:center"><a><img src="https://www.gietal.net/uploads/2/6/4/8/26484310/screen-shot-2018-10-06-at-7-18-43-pm_orig.png" alt="Picture" style="width:auto;max-width:100%"></a><div style="display:block;font-size:90%"></div></div></div><div class="paragraph">&#8203;The blob will be stored as a file named with a random UUID, and that UUID is what&rsquo;s then stored in the sqlite database. You can examine your sqlite database content with DB Browser for SQLite (free from https://sqlitebrowser.org). You can see that the value for my binary blob attribute is the UUID of the file under _EXTERNAL_DATA. This is how CoreData manages your big binary blob.</div><div><div class="wsite-image wsite-image-border-none" style="padding-top:10px;padding-bottom:10px;margin-left:0;margin-right:0;text-align:center"><a><img src="https://www.gietal.net/uploads/2/6/4/8/26484310/screen-shot-2018-10-06-at-11-40-51-pm_1_orig.png" alt="Picture" style="width:auto;max-width:100%"></a><div style="display:block;font-size:90%"></div></div></div><div><div class="wsite-image wsite-image-border-none" style="padding-top:10px;padding-bottom:10px;margin-left:0px;margin-right:0px;text-align:center"><a><img src="https://www.gietal.net/uploads/2/6/4/8/26484310/screen-shot-2018-10-06-at-11-41-28-pm_orig.png" alt="Picture" style="width:auto;max-width:100%"></a><div style="display:block;font-size:90%">The value of the binary attribute in the sqlite DB is actually the UUID name of the file on the _EXTERNAL_DATA folder</div></div></div><div class="paragraph">&#8203;When you update your binary blob from your code, then the blob file under _EXTERNAL_DATA is also overwritten with the new blob. However, this is not the case in macOS Mojave 10.14.0, which is demonstrated by my sample project<br><br>The sample project is quite simple, I have have an Entity with 2 simple attributes: an id (string) and an image (binary blob) with &ldquo;Allows External Storage&rdquo; selected. The id is so that I can fetch the same instance of the entity. When you run the app, you will see a window with a save button.&nbsp;</div><div><div class="wsite-image wsite-image-border-none" style="padding-top:10px;padding-bottom:10px;margin-left:0;margin-right:0;text-align:center"><a><img src="https://www.gietal.net/uploads/2/6/4/8/26484310/screen-shot-2018-10-06-at-7-11-46-pm_orig.png" alt="Picture" style="width:auto;max-width:100%"></a><div style="display:block;font-size:90%"></div></div></div><div><div class="wsite-image wsite-image-border-none" style="padding-top:10px;padding-bottom:10px;margin-left:0;margin-right:0;text-align:center"><a><img src="https://www.gietal.net/uploads/2/6/4/8/26484310/screen-shot-2018-10-07-at-2-13-34-pm_orig.png" alt="Picture" style="width:auto;max-width:100%"></a><div style="display:block;font-size:90%"></div></div></div><div class="paragraph"><span>Each time you hit the save button, it will try to save the displayed image as a binary blob to the entity&rsquo;s instance in the sqlite database. Since the binary blob is greater than 100kb, it will store it under:</span><br><span>~/Library/Containers/com.gietal.sandbox.CoreDataPlayground/Data/Library/Application Support/CoreDataPlayground/.CoreDataPlayground_SUPPORT/_EXTERNAL_DATA</span><br><br><span>If you hit the save button multiple times, it will try to overwrite the binary blob with the same image every time. Now here&rsquo;s where the problem lies. On macOS High Sierra (10.13.6) there is no issue with this, the binary blob is overwritten correctly. On macOS Mojave (10.14.0) however, this is not the case.</span><br><br><span>When you try running the same app on macOS Mojave, and start hitting the save button multiple times, you will observe that a new file keeps getting added under the _EXTERNAL_DATA folder. This is a serious problem as overtime the amount of useless files keep getting piled up inside this hidden folder. Normal non-savvy users would never know how their mac ran out of space so quickly due to this issue.</span><br><br><span>I submitted this issue to Apple&rsquo;s Bug Reporter, and they acknowledged that it was a bug and are working on a fix. Hopefully macOS Mojave 10.14.1 come out soon with a fix for this.</span><br><br><span>A workaround you can do at the moment is to save the entity&rsquo;s instance with a nil value for the binary attribute, and save it so that CoreData delete the external file. Then, you can save the instance again with the proper binary blob.</span><br></div><div><div id="789555083997078585" align="left" style="width: 100%; overflow-y: hidden;" class="wcustomhtml"><pre style='color:#000000;background:#ffffff;'><span style='color:#696969;'>// magic functions to get the CoreData context and entity's instance</span>let context <span style='color:#808030;'>=</span> getContext<span style='color:#808030;'>(</span><span style='color:#808030;'>)</span>let entity <span style='color:#808030;'>=</span> getEntity<span style='color:#808030;'>(</span><span style='color:#808030;'>)</span><span style='color:#696969;'>// nil out the binary blob, so CoreData erases the file in _EXTERNAL_DATA</span>entity<span style='color:#808030;'>.</span>setValue<span style='color:#808030;'>(</span>nil<span style='color:#808030;'>,</span> forKey<span style='color:#800080;'>:</span> <span style='color:#800000;'>"</span><span style='color:#0000e6;'>image</span><span style='color:#800000;'>"</span><span style='color:#808030;'>)</span>context<span style='color:#808030;'>.</span>save<span style='color:#808030;'>(</span><span style='color:#808030;'>)</span><span style='color:#696969;'>// then actually save your new blob</span>entity<span style='color:#808030;'>.</span>setValue<span style='color:#808030;'>(</span>blob<span style='color:#808030;'>,</span> forKey<span style='color:#800080;'>:</span> <span style='color:#800000;'>"</span><span style='color:#0000e6;'>image</span><span style='color:#800000;'>"</span><span style='color:#808030;'>)</span>context<span style='color:#808030;'>.</span>save<span style='color:#808030;'>(</span><span style='color:#808030;'>)</span></pre></div></div>]]></content:encoded></item><item><title><![CDATA[custom NSOutlineView disclosure button]]></title><link><![CDATA[https://www.gietal.net/blog/custom-nsoutlineview-disclosure-button]]></link><comments><![CDATA[https://www.gietal.net/blog/custom-nsoutlineview-disclosure-button#comments]]></comments><pubDate>Sat, 01 Sep 2018 22:00:00 GMT</pubDate><category><![CDATA[swift]]></category><guid isPermaLink="false">https://www.gietal.net/blog/custom-nsoutlineview-disclosure-button</guid><description><![CDATA[NSOutlineView is a very nice template to create a Finder-like table view of your collection. However, as any other things Cocoa, it is very easy to create UI that looks "standard", but it's not that straight forward to customize it.For instance, right out of the box, NSOutlineView already looks like the Finder app, complete with the collapse button (disclosure button is what they call it).​This is great to start with, but now what if I don't like the default triangle disclosure button? What if [...] ]]></description><content:encoded><![CDATA[<div class="paragraph">NSOutlineView is a very nice template to create a Finder-like table view of your collection. However, as any other things Cocoa, it is very easy to create UI that looks "standard", but it's not that straight forward to customize it.<br><br>For instance, right out of the box, NSOutlineView already looks like the Finder app, complete with the collapse button (disclosure button is what they call it).</div><div><div class="wsite-image wsite-image-border-none" style="padding-top:10px;padding-bottom:10px;margin-left:0;margin-right:0;text-align:center"><a><img src="https://www.gietal.net/uploads/2/6/4/8/26484310/screen-shot-2018-07-18-at-11-15-58-pm_orig.png" alt="Picture" style="width:auto;max-width:100%"></a><div style="display:block;font-size:90%"></div></div></div><div class="paragraph">&#8203;This is great to start with, but now what if I don't like the default triangle disclosure button? What if I want to use my own image for the button? One would think that there must be an image/alternate attribute for the disclosure button or something, but no... there isn't.<br><br>So we have to devise a roundabout way to customize the button..<br><br><strong><font color="#D5D5D5" size="4">Here's how you can customize the disclosure button</font></strong><br><br>&#8203;First,&nbsp;we have to add a new button to the expandable column of your outline view, usually the first (left-most) column. In my case, it's the "Hostname" column.</div><div><div class="wsite-image wsite-image-border-none" style="padding-top:10px;padding-bottom:10px;margin-left:0;margin-right:0;text-align:center"><a><img src="https://www.gietal.net/uploads/2/6/4/8/26484310/screen-shot-2018-07-22-at-5-58-01-pm_orig.png" alt="Picture" style="width:auto;max-width:100%"></a><div style="display:block;font-size:90%"></div></div></div><div class="paragraph"><br>Change the button type to "Toggle"<br></div><div><div class="wsite-image wsite-image-border-none" style="padding-top:10px;padding-bottom:10px;margin-left:0;margin-right:0;text-align:center"><a><img src="https://www.gietal.net/uploads/2/6/4/8/26484310/screen-shot-2018-07-22-at-10-25-24-pm_orig.png" alt="Picture" style="width:auto;max-width:100%"></a><div style="display:block;font-size:90%"></div></div></div><div class="paragraph"><br>Put your desired images on these fields:<ul><li>Image: The image when the disclosure button is expanded (down arrow)</li><li>Alternate: The image when the disclosure button is closed (right arrow)</li></ul>I'm using what the framework provides here, but you can put whatever image you want from your asset catalog</div><div><div class="wsite-image wsite-image-border-none" style="padding-top:10px;padding-bottom:10px;margin-left:0;margin-right:0;text-align:center"><a><img src="https://www.gietal.net/uploads/2/6/4/8/26484310/screen-shot-2018-07-22-at-10-16-42-pm_orig.png" alt="Picture" style="width:auto;max-width:100%"></a><div style="display:block;font-size:90%"></div></div></div><div class="paragraph"><br>&#8203;Now, add an identifier to this button so that we can create this button with the identifier. Let's name it as&nbsp;"<font color="#818181">MyDisclosureButton".</font></div><div><div class="wsite-image wsite-image-border-none" style="padding-top:10px;padding-bottom:10px;margin-left:0;margin-right:0;text-align:center"><a><img src="https://www.gietal.net/uploads/2/6/4/8/26484310/screen-shot-2018-07-22-at-6-00-33-pm_orig.png" alt="Picture" style="width:auto;max-width:100%"></a><div style="display:block;font-size:90%"></div></div></div><div class="paragraph">&#8203;<br>&#8203;Now,&nbsp;NSOutlineView create its views by calling makeView(), providing the appropriate identifier for each elements on the table. In order to create our own button, we have to subclass NSOutlineView and override this function. When NSOutlineView is about to make the disclosure button, we can intercept this call by checking the identifier that it sent.</div><div><div id="440540490122897596" align="left" style="width: 100%; overflow-y: hidden;" class="wcustomhtml"><pre style='color:#000000;background:#ffffff;'><span style='color:#800000; font-weight:bold;'>class</span> GNLOutlineView<span style='color:#800080;'>:</span> NSOutlineView <span style='color:#800080;'>{</span>  override func makeView<span style='color:#808030;'>(</span>withIdentifier identifier<span style='color:#800080;'>:</span> NSUserInterfaceItemIdentifier<span style='color:#808030;'>,</span> owner<span style='color:#800080;'>:</span> Any<span style='color:#800080;'>?</span><span style='color:#808030;'>)</span> <span style='color:#808030;'>-</span><span style='color:#808030;'>&gt;</span> NSView<span style='color:#800080;'>?</span> <span style='color:#800080;'>{</span>    <span style='color:#696969;'>// intercept disclosure button creation</span>    <span style='color:#800000; font-weight:bold;'>if</span> identifier <span style='color:#808030;'>==</span> NSOutlineView<span style='color:#808030;'>.</span>disclosureButtonIdentifier <span style='color:#800080;'>{</span>      <span style='color:#696969;'>// then create our custom button</span>      <span style='color:#800000; font-weight:bold;'>let</span> myView <span style='color:#808030;'>=</span> <span style='color:#800000; font-weight:bold;'>super</span><span style='color:#808030;'>.</span>makeView<span style='color:#808030;'>(</span>withIdentifier<span style='color:#800080;'>:</span> NSUserInterfaceItemIdentifier<span style='color:#808030;'>(</span>rawValue<span style='color:#800080;'>:</span> <span style='color:#800000;'>"</span><span style='color:#0000e6;'>MyDisclosureButton</span><span style='color:#800000;'>"</span><span style='color:#808030;'>)</span><span style='color:#808030;'>,</span> owner<span style='color:#800080;'>:</span> owner<span style='color:#808030;'>)</span> as<span style='color:#808030;'>!</span> NSButton            <span style='color:#696969;'>// we need to change the identifier so that the outline view knows to use this view as the disclosure button</span>      myView<span style='color:#808030;'>.</span>identifier <span style='color:#808030;'>=</span> identifier            <span style='color:#800000; font-weight:bold;'>return</span> myView    <span style='color:#800080;'>}</span>    <span style='color:#696969;'>// for everything else, use the default function</span>    <span style='color:#800000; font-weight:bold;'>return</span> <span style='color:#800000; font-weight:bold;'>super</span><span style='color:#808030;'>.</span>makeView<span style='color:#808030;'>(</span>withIdentifier<span style='color:#800080;'>:</span> identifier<span style='color:#808030;'>,</span> owner<span style='color:#800080;'>:</span> owner<span style='color:#808030;'>)</span>  <span style='color:#800080;'>}</span><span style='color:#800080;'>}</span></pre></div></div><div class="paragraph"><br>&#8203;Change the outline view to use GNLOutlineView as the custom class from the interface builder. When we build and run we should get this:</div><div><div class="wsite-image wsite-image-border-none" style="padding-top:10px;padding-bottom:10px;margin-left:0;margin-right:0;text-align:center"><a><img src="https://www.gietal.net/uploads/2/6/4/8/26484310/screen-shot-2018-07-22-at-10-27-30-pm_orig.png" alt="Picture" style="width:auto;max-width:100%"></a><div style="display:block;font-size:90%"></div></div></div><div class="paragraph"><br>&#8203;&#8203;Great! We can now display custom disclosure button for our outline view!&nbsp;<br><br>But wait a second... when we click on our disclosure button, nothing happen! The group doesn't collapse, and the button doesn't change its image.&nbsp;It would seem like we didn't set the target+action properties on our button, so the button doesn't do anything when it's clicked.&nbsp;<br><br>Where should we point the target+action of our button to? Let's cheat and take a look at where the original disclosure button's target+action pointed to. After all, they were already working without us explicitly modifying anything, so it must be pointing to the correct target+action!<br><br>We can create the original disclosure button by calling the super's implementation of the makeView function</div><div><div id="172263349964283032" align="left" style="width: 100%; overflow-y: hidden;" class="wcustomhtml"><pre style='color:#000000;background:#ffffff;'><span style='color:#696969;'>// get the original disclosure button</span><span style='color:#800000; font-weight:bold;'>let</span> originalButton <span style='color:#808030;'>=</span> <span style='color:#800000; font-weight:bold;'>super</span><span style='color:#808030;'>.</span>makeView<span style='color:#808030;'>(</span>withIdentifier<span style='color:#800080;'>:</span> identifier<span style='color:#808030;'>,</span> owner<span style='color:#800080;'>:</span> owner<span style='color:#808030;'>)</span> as<span style='color:#808030;'>!</span> NSButton</pre></div></div><div class="paragraph">If we stop the debugger after the creation of the original disclosure button, we can inspect the values of the button's target+action (if you drill down enough)</div><div><div class="wsite-image wsite-image-border-none" style="padding-top:10px;padding-bottom:10px;margin-left:0;margin-right:0;text-align:center"><a><img src="https://www.gietal.net/uploads/2/6/4/8/26484310/screen-shot-2018-07-22-at-10-49-48-pm_orig.png" alt="Picture" style="width:auto;max-width:100%"></a><div style="display:block;font-size:90%"></div></div></div><div class="paragraph">It would appear that the target is just our outline view, but the action is more interesting. The action points to a function called _outlineControlClicked. Since we don't see this function on NSOutlineView AND it starts with an underscore, it is highly likely that it is a private function (an Apple engineer I met at WWDC 2018 told me about the underscore prefixes on private functions and properties).<br><br>A simple solution to this is to assign our button's target+action to the target+action of the original button.</div><div><div id="761649752751674903" align="left" style="width: 100%; overflow-y: hidden;" class="wcustomhtml"><pre style='color:#000000;background:#ffffff;'>myView<span style='color:#808030;'>.</span>target <span style='color:#808030;'>=</span> originalButton<span style='color:#808030;'>.</span>targetmyView<span style='color:#808030;'>.</span>action <span style='color:#808030;'>=</span> originalButton<span style='color:#808030;'>.</span>action</pre></div></div><div class="paragraph" style="text-align:justify;"><br>Now, after we hook our button's target+action, we can see that our disclosure button now works perfectly!<br></div><div class="wsite-youtube" style="margin-bottom:10px;margin-top:10px;"><div class="wsite-youtube-wrapper wsite-youtube-size-auto wsite-youtube-align-center"><div class="wsite-youtube-container"><iframe src="//www.youtube.com/embed/pNvb4NCouPs?wmode=opaque" frameborder="0" allowfullscreen=""></iframe></div></div></div>]]></content:encoded></item><item><title><![CDATA[Main and Key Windows Shenanigans]]></title><link><![CDATA[https://www.gietal.net/blog/main-and-key-windows-shenanigans]]></link><comments><![CDATA[https://www.gietal.net/blog/main-and-key-windows-shenanigans#comments]]></comments><pubDate>Sun, 19 Aug 2018 00:00:00 GMT</pubDate><category><![CDATA[shenanigans]]></category><guid isPermaLink="false">https://www.gietal.net/blog/main-and-key-windows-shenanigans</guid><description><![CDATA[Not sure if this is the case in general, or just some corner case that I hit while being unlucky.What I found is that when an app becomes active, there has to be 1 main window on the same space as the current key window. However, this only happens to me when Displays Have Separate spaces is enabled while having multi monitor setup:         &#8203;My specific scenario:Have 2 monitors A and BCreate an app with 2 windows:Window 1: can become main window and key windowWindow 2: can become key window [...] ]]></description><content:encoded><![CDATA[<div class="paragraph">Not sure if this is the case in general, or just some corner case that I hit while being unlucky.<br /><br />What I found is that when an app becomes active, there has to be 1 main window on the same space as the current key window. However, this only happens to me when Displays Have Separate spaces is enabled while having multi monitor setup:</div>  <div><div class="wsite-image wsite-image-border-none " style="padding-top:10px;padding-bottom:10px;margin-left:0;margin-right:0;text-align:center"> <a> <img src="https://www.gietal.net/uploads/2/6/4/8/26484310/screen-shot-2018-07-08-at-8-11-59-pm_orig.png" alt="Picture" style="width:auto;max-width:100%" /> </a> <div style="display:block;font-size:90%"></div> </div></div>  <div class="paragraph"><font color="#d5d5d5" size="3">&#8203;My specific scenario:</font><ul><li>Have 2 monitors A and B</li><li>Create an app with 2 windows:<ul><li>Window 1: can become main window and key window</li><li>Window 2: can become key window, <font color="#d5d5d5">cannot become main window</font></li></ul></li><li>Move Window 1 to Monitor A</li><li>Move Window 2 to Monitor B</li><li>Deactivate the app by going to another app (Finder or something)</li><li>Click Window 2 on Monitor B to activate the app</li></ul><br /><font color="#d5d5d5" size="3">Expectation:</font><ul><li>Window 2 is activated and is the key window (have highlight on the window title bar)</li></ul> <font color="#d5d5d5" size="3">Actual observed behavior:</font><ul><li>Window 2 is activated</li><li>Then immediately after that,&nbsp;Window 1 is activated</li></ul><br />This produce a jarring effect where clicking on a window actually activates another window and shift the active window to that window instead. <br /><br />One solution is to make Window 2 to be able to become main window, but there might be a case where you might not want that.<br /></div>]]></content:encoded></item><item><title><![CDATA[NSWindow positioning shenanigans]]></title><link><![CDATA[https://www.gietal.net/blog/nswindow-positioning-shenanigans]]></link><comments><![CDATA[https://www.gietal.net/blog/nswindow-positioning-shenanigans#comments]]></comments><pubDate>Sun, 05 Aug 2018 01:00:00 GMT</pubDate><category><![CDATA[shenanigans]]></category><category><![CDATA[software engineering]]></category><category><![CDATA[swift]]></category><guid isPermaLink="false">https://www.gietal.net/blog/nswindow-positioning-shenanigans</guid><description><![CDATA[You're playing around with NSWindow, and you find this function called setFrame, setFrameOrigin, and setFrameTopLeftPoint. You feel like you are the king of the world when the thought of being able to move your window anywhere programmatically consume you. Except that when you realized that Cocoa stops you from doing that.Cocoa allows you to move the window anywhere using those functions, except when your window starts going above the menu bar.For instance, consider the following scenario:Screen [...] ]]></description><content:encoded><![CDATA[<div class="paragraph">You're playing around with NSWindow, and you find this function called <font color="#d5d5d5">setFrame</font>, <font color="#d5d5d5">setFrameOrigin</font>, and <font color="#d5d5d5">setFrameTopLeftPoint</font>. You feel like you are the king of the world when the thought of being able to move your window anywhere programmatically consume you. Except that when you realized that Cocoa stops you from doing that.<br /><br /><font color="#d5d5d5">Cocoa allows you to move the window anywhere using those functions, except when your window starts going above the menu bar.</font><br /><br />For instance, consider the following scenario:<ul><li>Screen Configuration:<ul><li>Resolution at&nbsp;1280 x 800</li><li>Menu bar height = 22 pixel</li><li>Which means, the menu bar starts at y = 778 (Cocoa coordinate start at the bottom left)</li></ul></li><li>Your Window:<ul><li>Size is 100 x 100</li></ul></li></ul><br />When you call <font color="#d5d5d5">window.setFrameTopLeftPoint</font> with the position of (x: 100, y: 800)&nbsp;your window's top left will actually be positioned at (x: 100, y: 778), right under the menu bar.<br /><br />Same goes with the other setFrame* variants, your window will be pushed down until no part of your window is above the menu bar.<br /><br />This is of course unless your window is the size (or bigger) than the screen, in which case it has no choice.</div>]]></content:encoded></item><item><title><![CDATA[Launch macos app from URL]]></title><link><![CDATA[https://www.gietal.net/blog/launch-macos-app-from-url]]></link><comments><![CDATA[https://www.gietal.net/blog/launch-macos-app-from-url#comments]]></comments><pubDate>Sat, 21 Jul 2018 07:00:00 GMT</pubDate><category><![CDATA[Uncategorized]]></category><guid isPermaLink="false">https://www.gietal.net/blog/launch-macos-app-from-url</guid><description><![CDATA[If you want to launch your app from a URL, Cocoa provided a nice way of doing it.&nbsp;First, you have to register for the event. You can do it anytime, but I put this code on my AppDelegate class:open func applicationWillFinishLaunching(_ notification: Notification) {    initializeURIOptions()}fileprivate func initializeURIOptions() {    // register to listen to the url event    let appleEventManager = NSAppleEventManager.shared()    appleEventManager.setEventHandler(self, andSelector: #selecto [...] ]]></description><content:encoded><![CDATA[<div class="paragraph">If you want to launch your app from a URL, Cocoa provided a nice way of doing it.&nbsp;<br><br>First, you have to register for the event. You can do it anytime, but I put this code on my AppDelegate class:</div><div><div id="556379436652625242" align="left" style="width: 100%; overflow-y: hidden;" class="wcustomhtml"><pre style='color:#000000;background:#ffffff;'>open func applicationWillFinishLaunching<span style='color:#808030;'>(</span>_ notification<span style='color:#800080;'>:</span> Notification<span style='color:#808030;'>)</span> <span style='color:#800080;'>{</span>    initializeURIOptions<span style='color:#808030;'>(</span><span style='color:#808030;'>)</span><span style='color:#800080;'>}</span>fileprivate func initializeURIOptions<span style='color:#808030;'>(</span><span style='color:#808030;'>)</span> <span style='color:#800080;'>{</span>    <span style='color:#696969;'>// register to listen to the url event</span>    <span style='color:#800000; font-weight:bold;'>let</span> appleEventManager <span style='color:#808030;'>=</span> NSAppleEventManager<span style='color:#808030;'>.</span>shared<span style='color:#808030;'>(</span><span style='color:#808030;'>)</span>    appleEventManager<span style='color:#808030;'>.</span>setEventHandler<span style='color:#808030;'>(</span>self<span style='color:#808030;'>,</span> andSelector<span style='color:#800080;'>:</span> #selector<span style='color:#808030;'>(</span>handleGetURLEvent<span style='color:#808030;'>(</span>event<span style='color:#800080;'>:</span>withReplyEvent<span style='color:#800080;'>:</span><span style='color:#808030;'>)</span><span style='color:#808030;'>)</span><span style='color:#808030;'>,</span> forEventClass<span style='color:#800080;'>:</span> AEEventClass<span style='color:#808030;'>(</span>kInternetEventClass<span style='color:#808030;'>)</span><span style='color:#808030;'>,</span> andEventID<span style='color:#800080;'>:</span> AEEventID<span style='color:#808030;'>(</span>kAEGetURL<span style='color:#808030;'>)</span><span style='color:#808030;'>)</span><span style='color:#800080;'>}</span></pre></div></div><div class="paragraph">Then, we have to actually handle the URL parameters. In this example, we assume that the URL is of the form <font color="#D5D5D5">myapp://param1=val1&amp;param2=val2</font><br><br>So we must parse the URL and extract the <font color="#D5D5D5">"param=value"</font> pairs</div><div><div id="488863086608189667" align="left" style="width: 100%; overflow-y: hidden;" class="wcustomhtml"><pre style='color:#000000;background:#ffffff;'>@objc fileprivate func handleGetURLEvent<span style='color:#808030;'>(</span>event<span style='color:#800080;'>:</span> NSAppleEventDescriptor<span style='color:#800080;'>?</span><span style='color:#808030;'>,</span> withReplyEvent replyEvent<span style='color:#800080;'>:</span> NSAppleEventDescriptor<span style='color:#800080;'>?</span><span style='color:#808030;'>)</span> <span style='color:#800080;'>{</span>    guard <span style='color:#800000; font-weight:bold;'>let</span> event <span style='color:#808030;'>=</span> event <span style='color:#800000; font-weight:bold;'>else</span> <span style='color:#800080;'>{</span>        <span style='color:#800000; font-weight:bold;'>return</span>    <span style='color:#800080;'>}</span>    <span style='color:#696969;'>// our URL event is in this format:</span>    <span style='color:#696969;'>// myapp://param1=val1&amp;param2=val2&amp;paramN=valN</span>        <span style='color:#696969;'>// grab the query pairs, that is the pairs separated by '&amp;'</span>    guard <span style='color:#800000; font-weight:bold;'>let</span> paramDesc <span style='color:#808030;'>=</span> event<span style='color:#808030;'>.</span>paramDescriptor<span style='color:#808030;'>(</span>forKeyword<span style='color:#800080;'>:</span> AEKeyword<span style='color:#808030;'>(</span>keyDirectObject<span style='color:#808030;'>)</span><span style='color:#808030;'>)</span><span style='color:#800080;'>?</span><span style='color:#808030;'>.</span>stringValue<span style='color:#808030;'>,</span>        <span style='color:#800000; font-weight:bold;'>let</span> url <span style='color:#808030;'>=</span> NSURL<span style='color:#808030;'>(</span>string<span style='color:#800080;'>:</span> paramDesc<span style='color:#808030;'>)</span><span style='color:#808030;'>,</span>        <span style='color:#800000; font-weight:bold;'>let</span> queryPairs <span style='color:#808030;'>=</span> url<span style='color:#808030;'>.</span>query<span style='color:#800080;'>?</span><span style='color:#808030;'>.</span>components<span style='color:#808030;'>(</span>separatedBy<span style='color:#800080;'>:</span> <span style='color:#800000;'>"</span><span style='color:#0000e6;'>&amp;</span><span style='color:#800000;'>"</span><span style='color:#808030;'>)</span> <span style='color:#800000; font-weight:bold;'>else</span> <span style='color:#800080;'>{</span>            <span style='color:#800000; font-weight:bold;'>return</span>    <span style='color:#800080;'>}</span>        <span style='color:#696969;'>// parse the key/value pair</span>    <span style='color:#696969;'>// querypairs is assumed to be in the form of "key=value"</span>    <span style='color:#800000; font-weight:bold;'>var</span> settingPairs <span style='color:#808030;'>=</span> <span style='color:#808030;'>[</span><span style='color:#797997;'>String</span><span style='color:#800080;'>:</span> <span style='color:#797997;'>String</span><span style='color:#808030;'>]</span><span style='color:#808030;'>(</span><span style='color:#808030;'>)</span>    <span style='color:#800000; font-weight:bold;'>for</span> query <span style='color:#800000; font-weight:bold;'>in</span> queryPairs <span style='color:#800080;'>{</span>        <span style='color:#800000; font-weight:bold;'>let</span> kvp <span style='color:#808030;'>=</span> query<span style='color:#808030;'>.</span>components<span style='color:#808030;'>(</span>separatedBy<span style='color:#800080;'>:</span> <span style='color:#800000;'>"</span><span style='color:#0000e6;'>=</span><span style='color:#800000;'>"</span><span style='color:#808030;'>)</span>        <span style='color:#800000; font-weight:bold;'>if</span> kvp<span style='color:#808030;'>.</span>count <span style='color:#808030;'>!=</span> <span style='color:#008c00;'>2</span> <span style='color:#800080;'>{</span>            <span style='color:#800000; font-weight:bold;'>continue</span>        <span style='color:#800080;'>}</span>                <span style='color:#800000; font-weight:bold;'>let</span> key <span style='color:#808030;'>=</span> kvp<span style='color:#808030;'>[</span><span style='color:#008c00;'>0</span><span style='color:#808030;'>]</span><span style='color:#808030;'>.</span>lowercased<span style='color:#808030;'>(</span><span style='color:#808030;'>)</span>        <span style='color:#800000; font-weight:bold;'>let</span> value <span style='color:#808030;'>=</span> kvp<span style='color:#808030;'>[</span><span style='color:#008c00;'>1</span><span style='color:#808030;'>]</span><span style='color:#808030;'>.</span>lowercased<span style='color:#808030;'>(</span><span style='color:#808030;'>)</span>        settingPairs<span style='color:#808030;'>[</span>key<span style='color:#808030;'>]</span> <span style='color:#808030;'>=</span> value    <span style='color:#800080;'>}</span>        <span style='color:#696969;'>// do stuff with settingPairs</span><span style='color:#800080;'>}</span></pre></div></div><div class="paragraph">Finally, we have to let the OS know to associate the <font color="#D5D5D5">"myapp"</font> URL scheme with our app.&nbsp;<br><br>&#8203;We can do this by editing the app's <font color="#D5D5D5">info.plist</font> and adding a <font color="#D5D5D5">URL Schemes</font> item under the <font color="#D5D5D5">URL types</font> item. The value for this key is the scheme that the OS will associate with your app.<br></div><div><div class="wsite-image wsite-image-border-none" style="padding-top:10px;padding-bottom:10px;margin-left:0;margin-right:0;text-align:center"><a><img src="https://www.gietal.net/uploads/2/6/4/8/26484310/screen-shot-2018-07-08-at-6-06-04-pm_orig.png" alt="Picture" style="width:auto;max-width:100%"></a><div style="display:block;font-size:90%"></div></div></div><div class="paragraph">Now, you should be able to launch your app by going to Safari (or any web browser and Terminal), and typing <font color="#D5D5D5">myapp://</font><br><br>If you want to pass parameters to the app you can simply add them to the URL <font color="#D5D5D5">myapp://?param1=val1&amp;param2=val2<br></font><br>When you do this from Safari, you will get a notification such as this:</div><div><div class="wsite-image wsite-image-border-none" style="padding-top:10px;padding-bottom:10px;margin-left:0;margin-right:0;text-align:center"><a><img src="https://www.gietal.net/uploads/2/6/4/8/26484310/screen-shot-2018-07-08-at-6-57-09-pm_orig.png" alt="Picture" style="width:auto;max-width:100%"></a><div style="display:block;font-size:90%"></div></div></div><div class="paragraph">To debug an app that is launched this way, you can modify XCode's setting to wait until your app is launched before attaching the debugger to the app.<br></div><div><div class="wsite-image wsite-image-border-none" style="padding-top:10px;padding-bottom:10px;margin-left:0;margin-right:0;text-align:center"><a><img src="https://www.gietal.net/uploads/2/6/4/8/26484310/screen-shot-2018-07-08-at-7-05-46-pm_1_orig.png" alt="Picture" style="width:auto;max-width:100%"></a><div style="display:block;font-size:90%"></div></div></div><div><div class="wsite-image wsite-image-border-none" style="padding-top:10px;padding-bottom:10px;margin-left:0;margin-right:0;text-align:center"><a><img src="https://www.gietal.net/uploads/2/6/4/8/26484310/screen-shot-2018-07-08-at-7-05-55-pm_orig.png" alt="Picture" style="width:auto;max-width:100%"></a><div style="display:block;font-size:90%"></div></div></div><div><div class="wsite-image wsite-image-border-none" style="padding-top:10px;padding-bottom:10px;margin-left:0;margin-right:0;text-align:center"><a><img src="https://www.gietal.net/uploads/2/6/4/8/26484310/screen-shot-2018-07-08-at-7-04-26-pm_orig.png" alt="Picture" style="width:auto;max-width:100%"></a><div style="display:block;font-size:90%"></div></div></div><div class="paragraph">XCode will now automatically attach the debugger to your app when you launch your app via the URL&nbsp;<font color="#D5D5D5">myapp://</font></div>]]></content:encoded></item><item><title><![CDATA[NSSecureTextField Shenanigans]]></title><link><![CDATA[https://www.gietal.net/blog/nssecuretextfield-shenanigans]]></link><comments><![CDATA[https://www.gietal.net/blog/nssecuretextfield-shenanigans#comments]]></comments><pubDate>Sat, 14 Jul 2018 21:30:00 GMT</pubDate><category><![CDATA[shenanigans]]></category><guid isPermaLink="false">https://www.gietal.net/blog/nssecuretextfield-shenanigans</guid><description><![CDATA[Interesting finding:From the get go, you're not able to input accented characters with keyboard shortcut (alt+e e, alt+u o, etc) on a NSSecureTextField.But I find this interesting "feature"&nbsp;(maybe a bug or loophole in Apple's implementation of secure text field?) which allows you to do just that.Here's what to do:Make sure key repeat is on at System Preference &gt; Keyboard &gt; Keyboard         I created a simple app with a basic NSSecureTextField and a label to display the content of the  [...] ]]></description><content:encoded><![CDATA[<div class="paragraph" style="text-align:left;"><font color="#a1a1a1">Interesting finding:<br /><br />From the get go, you're not able to input accented characters with keyboard shortcut (alt+e e, alt+u o, etc) on a NSSecureTextField.<br />But I find this interesting "feature"&nbsp;(maybe a bug or loophole in Apple's implementation of secure text field?) which allows you to do just that.<br /><br />Here's what to do:<br /><br />Make sure key repeat is on at System Preference &gt; Keyboard &gt; Keyboard</font></div>  <div><div class="wsite-image wsite-image-border-none " style="padding-top:10px;padding-bottom:10px;margin-left:0;margin-right:0;text-align:right"> <a> <img src="https://www.gietal.net/uploads/2/6/4/8/26484310/screen-shot-2017-05-03-at-2-10-34-pm-orig_orig.png" alt="Picture" style="width:auto;max-width:100%" /> </a> <div style="display:block;font-size:90%"></div> </div></div>  <div class="paragraph"><font color="#a1a1a1">I created a simple app with a basic NSSecureTextField and a label to display the content of the secure text field.</font><br /><br /><font color="#a1a1a1">&#8203;Go to the NSSecureTextField</font><br /><font color="#d5d5d5">&#8203;Hold e (or any letter that has accented character), until the key repeats</font></div>  <div><div class="wsite-image wsite-image-border-none " style="padding-top:10px;padding-bottom:10px;margin-left:0;margin-right:0;text-align:center"> <a> <img src="https://www.gietal.net/uploads/2/6/4/8/26484310/screen-shot-2017-05-03-at-2-17-05-pm_orig.png" alt="Picture" style="width:auto;max-width:100%" /> </a> <div style="display:block;font-size:90%"></div> </div></div>  <div class="paragraph" style="text-align:left;"><font color="#a1a1a1">After this point, key combinations </font><font color="#d5d5d5">(alt+e e, alt+y, alt+u o, etc) will work</font><font color="#a1a1a1"> as expected&nbsp;&#8203;</font></div>  <div><div class="wsite-image wsite-image-border-none " style="padding-top:10px;padding-bottom:10px;margin-left:0;margin-right:0;text-align:left"> <a> <img src="https://www.gietal.net/uploads/2/6/4/8/26484310/screen-shot-2017-05-03-at-2-17-30-pm_orig.png" alt="Picture" style="width:auto;max-width:100%" /> </a> <div style="display:block;font-size:90%"></div> </div></div>]]></content:encoded></item><item><title><![CDATA[NSPopUpButton shenanigans]]></title><link><![CDATA[https://www.gietal.net/blog/nspopupbutton-shenanigans]]></link><comments><![CDATA[https://www.gietal.net/blog/nspopupbutton-shenanigans#comments]]></comments><pubDate>Sun, 08 Jul 2018 07:00:00 GMT</pubDate><category><![CDATA[shenanigans]]></category><category><![CDATA[software engineering]]></category><category><![CDATA[swift]]></category><guid isPermaLink="false">https://www.gietal.net/blog/nspopupbutton-shenanigans</guid><description><![CDATA[​action/value bound to NSPopupButton is only triggered when user changes the value from the UI. It doesnt get triggered when you change the value programmatically.For example, if we bind the NSPopupButton's selected index property:​internal var selectedIndex: AnyObject! {    didSet {        let oldIndex = oldValue as? Int        let newIndex = selectedIndex as? Int        print("selectedIndex didSet, old: \(oldIndex), new: \(newIndex)")    }}changing the selected value via the UI will trigge [...] ]]></description><content:encoded><![CDATA[<div class="paragraph">&#8203;action/value bound to NSPopupButton is only triggered when user changes the value from the UI. It doesnt get triggered when you change the value programmatically.<br><br>For example, if we bind the NSPopupButton's selected index property:<br>&#8203;</div><div><div class="wsite-image wsite-image-border-none" style="padding-top:10px;padding-bottom:10px;margin-left:0;margin-right:0;text-align:center"><a><img src="https://www.gietal.net/uploads/2/6/4/8/26484310/published/screen-shot-2018-07-08-at-4-09-29-pm.png?1531091489" alt="Picture" style="width:auto;max-width:100%"></a><div style="display:block;font-size:90%"></div></div></div><div><div id="407216966197911800" align="left" style="width: 100%; overflow-y: hidden;" class="wcustomhtml"><pre style='color:#000000;background:#ffffff;'>internal <span style='color:#800000; font-weight:bold;'>var</span> selectedIndex<span style='color:#800080;'>:</span> AnyObject<span style='color:#808030;'>!</span> <span style='color:#800080;'>{</span>    didSet <span style='color:#800080;'>{</span>        <span style='color:#800000; font-weight:bold;'>let</span> oldIndex <span style='color:#808030;'>=</span> oldValue as<span style='color:#800080;'>?</span> Int        <span style='color:#800000; font-weight:bold;'>let</span> newIndex <span style='color:#808030;'>=</span> selectedIndex as<span style='color:#800080;'>?</span> Int        print<span style='color:#808030;'>(</span><span style='color:#800000;'>"</span><span style='color:#0000e6;'>selectedIndex didSet, old: \(oldIndex), new: \(newIndex)</span><span style='color:#800000;'>"</span><span style='color:#808030;'>)</span>    <span style='color:#800080;'>}</span><span style='color:#800080;'>}</span></pre></div></div><div class="paragraph">changing the selected value via the UI will trigger selectedIndex.didSet as expected</div><div><div class="wsite-image wsite-image-border-none" style="padding-top:10px;padding-bottom:10px;margin-left:0;margin-right:0;text-align:center"><a><img src="https://www.gietal.net/uploads/2/6/4/8/26484310/published/screen-shot-2018-07-08-at-4-26-09-pm.png?1531092485" alt="Picture" style="width:191;max-width:100%"></a><div style="display:block;font-size:90%"></div></div></div><div class="paragraph">However, when we change the index programmatically such as this:</div><div><div id="758274777310521662" align="left" style="width: 100%; overflow-y: hidden;" class="wcustomhtml"><pre style='color:#000000;background:#ffffff;'>popUpButton<span style='color:#808030;'>.</span>selectItem<span style='color:#808030;'>(</span>at<span style='color:#800080;'>:</span> <span style='color:#008c00;'>2</span><span style='color:#808030;'>)</span></pre></div></div><div class="paragraph" style="text-align:left;">Doing so will change the value in the UI, but it won't trigger selectedIndex.didSet as expected.<br><br>A bigger issue happens when we have this scenario:<ul><li>&#8203;User selects index 1 from the UI</li><li>We programmatically call popupButton.selectItem(at: 2), the UI changed to show that index 2 is selected</li><li>User reselects index 1 from the UI</li><li>selectedIndex.didset is not called for the user action!!</li></ul>&nbsp; &nbsp; &nbsp; &nbsp;<br>This happens because when we change the selected item programmatically to 2, selectedIndex's value doesn't actually change, it stayed at 1. So when the user change the index back to 1 via the UI, Cocoa realized that the value of selectedIndex is still the same (1), so it decided not to call the didset function.<br></div>]]></content:encoded></item><item><title><![CDATA[UserDefaults shenanigans]]></title><link><![CDATA[https://www.gietal.net/blog/userdefaults-shenanigans]]></link><comments><![CDATA[https://www.gietal.net/blog/userdefaults-shenanigans#comments]]></comments><pubDate>Fri, 08 Sep 2017 06:21:14 GMT</pubDate><category><![CDATA[shenanigans]]></category><category><![CDATA[swift]]></category><guid isPermaLink="false">https://www.gietal.net/blog/userdefaults-shenanigans</guid><description><![CDATA[It seems like the UserDefaults or at least the shared group UserDefaults&nbsp;is being cached somewhere, and it can put you in a confused debugging state.To highlight what I meant,&nbsp;create 2 sandboxed apps with the same app group, i.e:&nbsp;com.gietal.sandbox.groupOn the first app, do the following:// App 1if let defaults = UserDefaults(suiteName: "com.gietal.sandbox.group") {    defaults.set(123, forKey: "myKey")}When you run the first app, it should create this file&nbsp;~/Library/Group Co [...] ]]></description><content:encoded><![CDATA[<div class="paragraph"><span>It seems like the UserDefaults or at least the shared group UserDefaults&nbsp;is being cached somewhere, and it can put you in a confused debugging state.</span><br><br><span>To highlight what I meant,&nbsp;create 2 sandboxed apps with the same app group, i.e:&nbsp;</span><font color="#D5D5D5">com.gietal.sandbox.group</font><br><br><span>On the first app, do the following:</span></div><div><div id="583486060286239850" align="left" style="width: 100%; overflow-y: hidden;" class="wcustomhtml"><pre style='color:#000000;background:#ffffff;'><span style='color:#696969;'>// App 1</span><span style='color:#800000; font-weight:bold;'>if</span> <span style='color:#800000; font-weight:bold;'>let</span> defaults <span style='color:#808030;'>=</span> UserDefaults<span style='color:#808030;'>(</span>suiteName<span style='color:#800080;'>:</span> <span style='color:#800000;'>"</span><span style='color:#0000e6;'>com.gietal.sandbox.group</span><span style='color:#800000;'>"</span><span style='color:#808030;'>)</span> <span style='color:#800080;'>{</span>    defaults<span style='color:#808030;'>.</span>set<span style='color:#808030;'>(</span><span style='color:#008c00;'>123</span><span style='color:#808030;'>,</span> forKey<span style='color:#800080;'>:</span> <span style='color:#800000;'>"</span><span style='color:#0000e6;'>myKey</span><span style='color:#800000;'>"</span><span style='color:#808030;'>)</span><span style='color:#800080;'>}</span></pre></div></div><div class="paragraph">When you run the first app, it should create this file&nbsp;<span><font color="#D5D5D5">~/Library/Group Containers/com.gietal.sandbox.group/Library/Preferences/com.gietal.sandbox.group.plist</font> where the setting <font color="#D5D5D5">"myKey = 123"</font> is stored as xml.<br></span><br>&#8203;Now on the second app, try to read the value from the shared group UserDefaults. At this point, it should return the expected value of 123</div><div><div id="372412165352966976" align="left" style="width: 100%; overflow-y: hidden;" class="wcustomhtml"><pre style='color:#000000;background:#ffffff;'><span style='color:#696969;'>// App 2</span><span style='color:#800000; font-weight:bold;'>if</span> <span style='color:#800000; font-weight:bold;'>let</span> defaults <span style='color:#808030;'>=</span> UserDefaults<span style='color:#808030;'>(</span>suiteName<span style='color:#800080;'>:</span> <span style='color:#800000;'>"</span><span style='color:#0000e6;'>com.gietal.sandbox.group</span><span style='color:#800000;'>"</span><span style='color:#808030;'>)</span> <span style='color:#800080;'>{</span>    <span style='color:#800000; font-weight:bold;'>let</span> value <span style='color:#808030;'>=</span> defaults<span style='color:#808030;'>.</span>value<span style='color:#808030;'>(</span>forKey<span style='color:#800080;'>:</span> <span style='color:#800000;'>"</span><span style='color:#0000e6;'>myKey</span><span style='color:#800000;'>"</span><span style='color:#808030;'>)</span>    print<span style='color:#808030;'>(</span><span style='color:#800000;'>"</span><span style='color:#0000e6;'>value: \(value)</span><span style='color:#800000;'>"</span><span style='color:#808030;'>)</span><span style='color:#800080;'>}</span></pre></div></div><div class="paragraph" style="text-align:left;">Now <font color="#D5D5D5">delete</font> the plist file <font color="#D5D5D5">~/Library/Group Containers/com.gietal.sandbox.group/Library/Preferences/com.gietal.sandbox.group.plist</font><br><br>And try reading the value again from app 2. You would be surprised that it would <font color="#D5D5D5">still returns 123 instead of the expected nil.</font><br><br>However, if you <font color="#D5D5D5">reboot your mac</font> and try reading the value of "myKey" from app 2 again, <font color="#D5D5D5">it will correctly returns nil&nbsp;</font><span style="color:rgb(213, 213, 213)">this time!</span><br><br>So this made me believe that <font color="#D5D5D5">UserDefaults is being cached</font> somewhere in the system and could get out of sync with the actual plist file where the values are stored.</div>]]></content:encoded></item><item><title><![CDATA[xcodebuild couldn't posix_spawn: error 7]]></title><link><![CDATA[https://www.gietal.net/blog/xcodebuild-couldnt-posix_spawn-error-7]]></link><comments><![CDATA[https://www.gietal.net/blog/xcodebuild-couldnt-posix_spawn-error-7#comments]]></comments><pubDate>Sat, 08 Jul 2017 07:00:00 GMT</pubDate><category><![CDATA[Uncategorized]]></category><guid isPermaLink="false">https://www.gietal.net/blog/xcodebuild-couldnt-posix_spawn-error-7</guid><description><![CDATA[&#8203;Tldr: path to the working directory was too long&nbsp;When building an older project with xcodebuild, I suddenly started getting this error:** INTERNAL ERROR: Uncaught exception **Uncaught Exception: Couldn't posix_spawn: error 7Stack:&nbsp; 0&nbsp;&nbsp; __exceptionPreprocess (in CoreFoundation)&nbsp; 1&nbsp;&nbsp; objc_exception_throw (in libobjc.A.dylib)&nbsp; 2&nbsp;&nbsp; +[NSException raise:format:] (in CoreFoundation)&nbsp; 3&nbsp;&nbsp; -[NSConcreteTask launchWithDictionary:] (in  [...] ]]></description><content:encoded><![CDATA[<div class="paragraph" style="text-align:left;">&#8203;<strong><font color="#c9f8a9">Tldr: path to the working directory was too long</font></strong><br />&nbsp;<br />When building an older project with xcodebuild, I suddenly started getting this error:<br /><br /><font color="#d5d5d5">** INTERNAL ERROR: Uncaught exception **</font><br /><font color="#d5d5d5">Uncaught Exception: Couldn't posix_spawn: error 7</font><br /><font color="#d5d5d5">Stack:</font><br /><font color="#d5d5d5">&nbsp; 0&nbsp;&nbsp; __exceptionPreprocess (in CoreFoundation)</font><br /><font color="#d5d5d5">&nbsp; 1&nbsp;&nbsp; objc_exception_throw (in libobjc.A.dylib)</font><br /><font color="#d5d5d5">&nbsp; 2&nbsp;&nbsp; +[NSException raise:format:] (in CoreFoundation)</font><br /><font color="#d5d5d5">&nbsp; 3&nbsp;&nbsp; -[NSConcreteTask launchWithDictionary:] (in Foundation)</font><br /><font color="#d5d5d5">&nbsp; 4&nbsp;&nbsp; __46-[IDEShellScriptExecutionActionOperation main]_block_invoke_2.229 (in IDEStandardExecutionActionsCore)</font><br /><font color="#d5d5d5">&nbsp; 5&nbsp;&nbsp; ___DVTAsyncPerformBlockOnMainRunLoop_block_invoke (in DVTFoundation)</font><br /><font color="#d5d5d5">&nbsp; 6&nbsp;&nbsp; __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ (in CoreFoundation)</font><br /><font color="#d5d5d5">&nbsp; 7&nbsp;&nbsp; __CFRunLoopDoBlocks (in CoreFoundation)</font><br /><font color="#d5d5d5">&nbsp; 8&nbsp;&nbsp; __CFRunLoopRun (in CoreFoundation)</font><br /><font color="#d5d5d5">&nbsp; 9&nbsp;&nbsp; CFRunLoopRunSpecific (in CoreFoundation)</font><br /><font color="#d5d5d5">10&nbsp;&nbsp; CFRunLoopRun (in CoreFoundation)</font><br /><font color="#d5d5d5">11&nbsp;&nbsp; -[Xcode3CommandLineBuildTool _buildWithTimingSection:] (in Xcode3Core)</font><br /><font color="#d5d5d5">12&nbsp;&nbsp; -[Xcode3CommandLineBuildTool run] (in Xcode3Core)</font><br /><font color="#d5d5d5">13&nbsp; 0x000000010fe00202 (in xcodebuild)</font><br /><font color="#d5d5d5">14&nbsp;&nbsp; start (in libdyld.dylib)</font><br /><br />After much googling and investigating, I found that:<ul><li>xcodebuild calls posix_spawn()</li><li>posix_spawn() calls exec()</li><li>exec() fail with error 7 &ndash; E2BIG: Argument list too long</li><li>running <font color="#d5d5d5">getconf ARG_MAX</font> from the terminal shows that the&nbsp;maximum argument list was&nbsp;262144 bytes</li></ul> &nbsp;<br />Originally I ran the script from&nbsp;<strong><font color="#d5d5d5">~/jenkinsroot/some/very/long/path/to/the/project/directory</font><br /></strong><font color="#818181">and the individual files that are being compiled lies way deeper on the folder structure. Which made me to believe that when xcodebuild tries to give the files full path as an argument to posix_spawn, the length exceeds&nbsp;262144&nbsp;bytes<br /></font><br />It works when I move the project root directory to&nbsp;<strong><font color="#d5d5d5">~/shorter/path</font></strong><br />&nbsp;<br />helpful links:<br /><font color="#5cbce0"><a href="http://lxr.free-electrons.com/source/include/uapi/asm-generic/errno-base.h#L14">http://lxr.free-electrons.com/source/include/uapi/asm-generic/errno-base.h#L14</a><br /><a href="http://www.in-ulm.de/~mascheck/various/argmax/">http://www.in-ulm.de/~mascheck/various/argmax/</a><br /><a href="http://pubs.opengroup.org/onlinepubs/009695399/functions/posix_spawn.html">http://pubs.opengroup.org/onlinepubs/009695399/functions/posix_spawn.html</a><br /><a href="http://pubs.opengroup.org/onlinepubs/009695399/functions/exec.html">http://pubs.opengroup.org/onlinepubs/009695399/functions/exec.html</a></font><br />&nbsp;<br />now I can have a peaceful weekend :)</div>]]></content:encoded></item></channel></rss>