mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2024-12-20 14:33:04 +01:00
715 lines
65 KiB
HTML
715 lines
65 KiB
HTML
<!DOCTYPE html>
|
||
<!--[if IE 7]>
|
||
<html class="ie ie7" lang="en-US">
|
||
<![endif]-->
|
||
<!--[if IE 8]>
|
||
<html class="ie ie8" lang="en-US">
|
||
<![endif]-->
|
||
<!--[if !(IE 7) & !(IE 8)]><!-->
|
||
<html lang="en-US">
|
||
<!--<![endif]-->
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width">
|
||
<title>Indie Stack | Hacking the Mac, iOS, and more with Daniel Jalkut</title>
|
||
<link rel="profile" href="http://gmpg.org/xfn/11">
|
||
<link rel="pingback" href="http://indiestack.com/xmlrpc.php">
|
||
<!--[if lt IE 9]>
|
||
<script src="http://indiestack.com/wp-content/themes/twentythirteen/js/html5.js"></script>
|
||
<![endif]-->
|
||
<link rel='dns-prefetch' href='//fonts.googleapis.com' />
|
||
<link rel='dns-prefetch' href='//s.w.org' />
|
||
<link href='https://fonts.gstatic.com' crossorigin rel='preconnect' />
|
||
<link rel="alternate" type="application/rss+xml" title="Indie Stack » Feed" href="http://indiestack.com/feed/" />
|
||
<script type="text/javascript">
|
||
window._wpemojiSettings = {"baseUrl":"https:\/\/s.w.org\/images\/core\/emoji\/2.3\/72x72\/","ext":".png","svgUrl":"https:\/\/s.w.org\/images\/core\/emoji\/2.3\/svg\/","svgExt":".svg","source":{"concatemoji":"http:\/\/indiestack.com\/wp-includes\/js\/wp-emoji-release.min.js?ver=4.8.3"}};
|
||
!function(a,b,c){function d(a){var b,c,d,e,f=String.fromCharCode;if(!k||!k.fillText)return!1;switch(k.clearRect(0,0,j.width,j.height),k.textBaseline="top",k.font="600 32px Arial",a){case"flag":return k.fillText(f(55356,56826,55356,56819),0,0),b=j.toDataURL(),k.clearRect(0,0,j.width,j.height),k.fillText(f(55356,56826,8203,55356,56819),0,0),c=j.toDataURL(),b!==c&&(k.clearRect(0,0,j.width,j.height),k.fillText(f(55356,57332,56128,56423,56128,56418,56128,56421,56128,56430,56128,56423,56128,56447),0,0),b=j.toDataURL(),k.clearRect(0,0,j.width,j.height),k.fillText(f(55356,57332,8203,56128,56423,8203,56128,56418,8203,56128,56421,8203,56128,56430,8203,56128,56423,8203,56128,56447),0,0),c=j.toDataURL(),b!==c);case"emoji4":return k.fillText(f(55358,56794,8205,9794,65039),0,0),d=j.toDataURL(),k.clearRect(0,0,j.width,j.height),k.fillText(f(55358,56794,8203,9794,65039),0,0),e=j.toDataURL(),d!==e}return!1}function e(a){var c=b.createElement("script");c.src=a,c.defer=c.type="text/javascript",b.getElementsByTagName("head")[0].appendChild(c)}var f,g,h,i,j=b.createElement("canvas"),k=j.getContext&&j.getContext("2d");for(i=Array("flag","emoji4"),c.supports={everything:!0,everythingExceptFlag:!0},h=0;h<i.length;h++)c.supports[i[h]]=d(i[h]),c.supports.everything=c.supports.everything&&c.supports[i[h]],"flag"!==i[h]&&(c.supports.everythingExceptFlag=c.supports.everythingExceptFlag&&c.supports[i[h]]);c.supports.everythingExceptFlag=c.supports.everythingExceptFlag&&!c.supports.flag,c.DOMReady=!1,c.readyCallback=function(){c.DOMReady=!0},c.supports.everything||(g=function(){c.readyCallback()},b.addEventListener?(b.addEventListener("DOMContentLoaded",g,!1),a.addEventListener("load",g,!1)):(a.attachEvent("onload",g),b.attachEvent("onreadystatechange",function(){"complete"===b.readyState&&c.readyCallback()})),f=c.source||{},f.concatemoji?e(f.concatemoji):f.wpemoji&&f.twemoji&&(e(f.twemoji),e(f.wpemoji)))}(window,document,window._wpemojiSettings);
|
||
</script>
|
||
<style type="text/css">
|
||
img.wp-smiley,
|
||
img.emoji {
|
||
display: inline !important;
|
||
border: none !important;
|
||
box-shadow: none !important;
|
||
height: 1em !important;
|
||
width: 1em !important;
|
||
margin: 0 .07em !important;
|
||
vertical-align: -0.1em !important;
|
||
background: none !important;
|
||
padding: 0 !important;
|
||
}
|
||
</style>
|
||
<link rel='stylesheet' id='parent-style-css' href='http://indiestack.com/wp-content/themes/twentythirteen/style.css?ver=4.8.3' type='text/css' media='all' />
|
||
<link rel='stylesheet' id='twentythirteen-fonts-css' href='https://fonts.googleapis.com/css?family=Source+Sans+Pro%3A300%2C400%2C700%2C300italic%2C400italic%2C700italic%7CBitter%3A400%2C700&subset=latin%2Clatin-ext' type='text/css' media='all' />
|
||
<link rel='stylesheet' id='genericons-css' href='http://indiestack.com/wp-content/themes/twentythirteen/genericons/genericons.css?ver=3.03' type='text/css' media='all' />
|
||
<link rel='stylesheet' id='twentythirteen-style-css' href='http://indiestack.com/wp-content/themes/indiestack-new/style.css?ver=2013-07-18' type='text/css' media='all' />
|
||
<!--[if lt IE 9]>
|
||
<link rel='stylesheet' id='twentythirteen-ie-css' href='http://indiestack.com/wp-content/themes/twentythirteen/css/ie.css?ver=2013-07-18' type='text/css' media='all' />
|
||
<![endif]-->
|
||
<script type='text/javascript' src='http://indiestack.com/wp-includes/js/jquery/jquery.js?ver=1.12.4'></script>
|
||
<script type='text/javascript' src='http://indiestack.com/wp-includes/js/jquery/jquery-migrate.min.js?ver=1.4.1'></script>
|
||
<link rel='https://api.w.org/' href='http://indiestack.com/wp-json/' />
|
||
<link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://indiestack.com/xmlrpc.php?rsd" />
|
||
<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://indiestack.com/wp-includes/wlwmanifest.xml" />
|
||
<meta name="generator" content="WordPress 4.8.3" />
|
||
<link rel="alternate" type="application/json" title="JSON Feed" href="http://indiestack.com/feed/json/" /> <style type="text/css">.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}</style>
|
||
|
||
<script type="text/javascript">
|
||
//QuickLogin by Red Sweater Software
|
||
|
||
document['onkeyup'] = function(event){
|
||
var e = event || window.event;
|
||
|
||
var triggerKeyCode = 27;
|
||
var loginPageURL = "http://indiestack.com/wp-login.php?redirect_to=http%3A%2F%2Findiestack.com%2F";
|
||
|
||
if ( e.keyCode == triggerKeyCode ) {
|
||
document.location.href=loginPageURL;
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style type="text/css" id="twentythirteen-header-css">
|
||
.site-header {
|
||
background: url(http://indiestack.com/wp-content/themes/twentythirteen/images/headers/star.png) no-repeat scroll top;
|
||
background-size: 1600px auto;
|
||
}
|
||
@media (max-width: 767px) {
|
||
.site-header {
|
||
background-size: 768px auto;
|
||
}
|
||
}
|
||
@media (max-width: 359px) {
|
||
.site-header {
|
||
background-size: 360px auto;
|
||
}
|
||
}
|
||
</style>
|
||
</head>
|
||
|
||
<body class="home blog single-author">
|
||
<div id="page" class="hfeed site">
|
||
<header id="masthead" class="site-header" role="banner">
|
||
<a class="home-link" href="http://indiestack.com/" title="Indie Stack" rel="home">
|
||
<h1 class="site-title">Indie Stack</h1>
|
||
<h2 class="site-description">Hacking the Mac, iOS, and more with Daniel Jalkut</h2>
|
||
</a>
|
||
|
||
<div id="navbar" class="navbar">
|
||
<nav id="site-navigation" class="navigation main-navigation" role="navigation">
|
||
<button class="menu-toggle">Menu</button>
|
||
<a class="screen-reader-text skip-link" href="#content" title="Skip to content">Skip to content</a>
|
||
<div class="menu-daniels-other-stuff-container"><ul id="primary-menu" class="nav-menu"><li id="menu-item-124" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-124"><a href="http://www.red-sweater.com/">Red Sweater Software</a></li>
|
||
<li id="menu-item-125" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-125"><a href="http://coreint.org/">Core Intuition Podcast</a></li>
|
||
<li id="menu-item-126" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-126"><a href="http://bitsplitting.org/">Bitsplitting Blog</a></li>
|
||
<li id="menu-item-127" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-127"><a href="http://punkitup.com/twitpop/">TwitPOP</a></li>
|
||
</ul></div> <form role="search" method="get" class="search-form" action="http://indiestack.com/">
|
||
<label>
|
||
<span class="screen-reader-text">Search for:</span>
|
||
<input type="search" class="search-field" placeholder="Search …" value="" name="s" />
|
||
</label>
|
||
<input type="submit" class="search-submit" value="Search" />
|
||
</form> </nav><!-- #site-navigation -->
|
||
</div><!-- #navbar -->
|
||
</header><!-- #masthead -->
|
||
|
||
<div id="main" class="site-main">
|
||
|
||
<div id="primary" class="content-area">
|
||
<div id="content" class="site-content" role="main">
|
||
|
||
|
||
<article id="post-581" class="post-581 post type-post status-publish format-standard hentry category-bug-reports category-xcode">
|
||
<header class="entry-header">
|
||
|
||
<h1 class="entry-title">
|
||
<a href="http://indiestack.com/2017/11/treat-warnings-as-errors-in-swift/" rel="bookmark">Treat Warnings as Errors in Swift</a>
|
||
</h1>
|
||
|
||
<div class="entry-meta">
|
||
<span class="date"><a href="http://indiestack.com/2017/11/treat-warnings-as-errors-in-swift/" title="Permalink to Treat Warnings as Errors in Swift" rel="bookmark"><time class="entry-date" datetime="2017-11-04T17:57:50+00:00">November 4, 2017</time></a></span><span class="categories-links"><a href="http://indiestack.com/category/bug-reports/" rel="category tag">Bug Reports</a>, <a href="http://indiestack.com/category/xcode/" rel="category tag">Xcode</a></span><span class="author vcard"><a class="url fn n" href="http://indiestack.com/author/admin/" title="View all posts by Daniel Jalkut" rel="author">Daniel Jalkut</a></span> </div><!-- .entry-meta -->
|
||
</header><!-- .entry-header -->
|
||
|
||
<div class="entry-content">
|
||
<p>For years I have maintained a zero-tolerance policy for warnings in shipping code. To help me enforce this, my “Release” build configurations define the build setting that induces Xcode to “treat warnings as errors”:</p>
|
||
<pre>GCC_TREAT_WARNINGS_AS_ERRORS = YES
|
||
</pre>
|
||
<p>The comedy of this build setting is that it references “GCC,” a compiler that increasingly few of us even remember Apple ever using for macOS or iOS development. Apple’s fork of the popular open-source compiler was the standard for years, until Apple debuted clang, which is built on the LLVM framework.</p>
|
||
<p>It’s always been kind of annoying that, as time moved on, we were stuck specifying important build settings with names that included “GCC,” but I accepted it. After all, I configure the vast majority of these settings in “.xcconfig” files that I reuse in all my projects, so I almost never interact with them directly.</p>
|
||
<p>As I’ve started to shift some of my code from Objective-C to Swift, I assumed that my ancient GCC build setting would ensure that I don’t ship any builds with warnings. But today I realized that I had built a release build that <em>didn’t treat a warning as an error</em>. What’s the deal?</p>
|
||
<p>It looks like Apple has decided to break with tradition and establish a new build setting for Swift:</p>
|
||
<pre>SWIFT_TREAT_WARNINGS_AS_ERRORS = YES
|
||
</pre>
|
||
<p>Adding this to my .xcconfig file breaks the build when a warning is generated, and prevents me from accidentally shipping code that is known to be vulnerable to unexpected behavior. I think it would have been a nice touch if Apple had inferred SWIFT_TREAT_WARNINGS_AS_ERRORS when GCC_TREAT_WARNINGS_AS_ERRORS is set, so I’ve filed a bug requesting that it does. Radar #35352318.</p>
|
||
</div><!-- .entry-content -->
|
||
|
||
<footer class="entry-meta">
|
||
|
||
</footer><!-- .entry-meta -->
|
||
</article><!-- #post -->
|
||
|
||
<article id="post-574" class="post-574 post type-post status-publish format-standard hentry category-cocoa category-os-x category-swift">
|
||
<header class="entry-header">
|
||
|
||
<h1 class="entry-title">
|
||
<a href="http://indiestack.com/2017/10/selective-selector-mapping/" rel="bookmark">Selective Selector Mapping</a>
|
||
</h1>
|
||
|
||
<div class="entry-meta">
|
||
<span class="date"><a href="http://indiestack.com/2017/10/selective-selector-mapping/" title="Permalink to Selective Selector Mapping" rel="bookmark"><time class="entry-date" datetime="2017-10-31T10:41:41+00:00">October 31, 2017</time></a></span><span class="categories-links"><a href="http://indiestack.com/category/cocoa/" rel="category tag">Cocoa</a>, <a href="http://indiestack.com/category/os-x/" rel="category tag">OS X</a>, <a href="http://indiestack.com/category/swift/" rel="category tag">Swift</a></span><span class="author vcard"><a class="url fn n" href="http://indiestack.com/author/admin/" title="View all posts by Daniel Jalkut" rel="author">Daniel Jalkut</a></span> </div><!-- .entry-meta -->
|
||
</header><!-- .entry-header -->
|
||
|
||
<div class="entry-content">
|
||
<p>I ran into an interesting challenge while porting some Objective-C code to Swift. The class in question served both as an NSTableView delegate and data source, meaning that it implemented methods both for controlling the table view’s behavior and for supplying its content.</p>
|
||
<p>Historically in Cocoa, most delegate relationships were established as <em>informal</em> protocols. If you wanted a particular class to <em>be a table view data source</em>, you simply implemented the required methods. For example, to populate a cell based table view, a data source would implement various methods, including one to indicate how many rows the view should have:</p>
|
||
<pre>
|
||
- (NSInteger) numberOfRowsInTableView:(NSTableView *)tableView;
|
||
</pre>
|
||
<p>In recent years, Apple has increasingly converted these informal protocols to <em>formal</em> Objective-C protocols. These give the compiler the opportunity to generate errors if a particular class declares compliance, but neglects to implement a required method. At runtime, however, the compliance-checking is still pretty loose. NSTableView consults its data source, checks to see that it implements a required subset of methods, and dynamically dispatches to them if it does.</p>
|
||
<p>The dynamic nature of NSTableView hasn’t changed with Swift. An @objc class in Swift that complies with NSTableViewDataSource must still implement the required methods such that Apple’s Objective-C based NSTableView can dynamically look up and dispatch to the required delegate methods. Swift’s method rewriting “magic” even ensures that a delegate method can be written in modern Swift style, yet still appear identically to older Objective-C code:</p>
|
||
<pre>
|
||
class MyDataSource: NSObject {
|
||
@objc func numberOfRows(in tableView: NSTableView) -> Int {
|
||
return 0
|
||
}
|
||
}
|
||
</pre>
|
||
<p>Given an instance of MyDataSource, I can use the Objective-C runtime to confirm that a the legacy “numberOfRowsInTableView:” selector is actually implemented by the class above:</p>
|
||
<pre>
|
||
let thisSource = MyDataSource()
|
||
thisSource.responds(to: Selector("numberOfRowsInTableView:")) // false
|
||
</pre>
|
||
<p>Or can I? False? That’s no good. I’m using the discouraged “Selector” initializer here to ensure I get Swift to look for a very specific Selector, even if it doesn’t appear to be correct to the Swift-adapted side of the runtime.</p>
|
||
<p>I was scratching my head, trying to figure out why Objective-C could not <em>see</em> my method. Did I forget an @objc marker? No. Did I forget to make MyDataSource a subclass of NSObject? No. I finally discovered that I could second-guess the default Swift selector mapping to obtain a result that “worked”:</p>
|
||
<pre>
|
||
class MyDataSource: NSObject {
|
||
@objc func numberOfRowsInTableView(_ tableView: NSTableView) -> Int {
|
||
return 0
|
||
}
|
||
}
|
||
|
||
let thisSource = MyDataSource()
|
||
thisSource.responds(to: Selector("numberOfRowsInTableView:")) // true
|
||
</pre>
|
||
<p>Instances of MyDataSource will get the job done for Objective-C calls to “numberOfRowsInTableView:”, but I’ve lost all the pretty formatting that I expected to be able to use in Swift.</p>
|
||
<p>There’s something else I’m missing out in my Swift implementation: type checking of MyDataSource’s compliance with the NSTableViewDataSource protocol. Old habits die hard, and I had initially ported my class over with an old-fashioned, informal approach to complying with NSTableViewDataSource: I declared a plain NSObject that <em>happens to implement</em> the informal protocol.</p>
|
||
<p>It turns that adding that protocol conformance onto my class declaration not only gains me Swift’s protocol type checking, but <em>changes</em> the way key functions are mapped from Swift to Objective-C:</p>
|
||
<pre>
|
||
class MyDataSource: NSObject, NSTableViewDataSource {
|
||
func numberOfRows(in tableView: NSTableView) -> Int {
|
||
return 0
|
||
}
|
||
}
|
||
|
||
let thisSource = MyDataSource()
|
||
thisSource.responds(to: Selector("numberOfRowsInTableView:")) // true
|
||
</pre>
|
||
<p>Armed with the knowledge that my class <em>intends to comply</em> with NSTableViewDataSource, Swift generates the expected mapping to Objective-C. Notice in this final case, I don’t even have to remember to mark the function as @objc. I guess when Swift is creating the selector mapping for a function, it does so in a few phases, prioritizing more explicit scenarios over more general:</p>
|
||
<ol>
|
||
<li>First, it defers to any explicit annotation with the @objc attribute. If I tag my “numberOfRows…” func above with “@objc(numberOfDoodads:)” then the method will be made available to Objective-C code dynamically looking for “numberOfDoodads:”.</li>
|
||
<li>If there’s no @objc specialization, it tries to match function implementations with declarations in superclasses or protocols the class complies with. This is what gives us the automatic mapping of Swift’s “numberOfRows(in:)” to Objective-C’s “numberOfRowsInTableView:”.</li>
|
||
<li>Finally it resorts to a default mapping based on <a href="https://swift.org/documentation/api-design-guidelines/">Swift API Design Guidelines</a>. This is what yielded the default “numberOfRowsIn:” mapping that I first encountered.</li>
|
||
</ol>
|
||
<p>This is an example of a Swift growing pain that is particularly likely to affect folks who are adapting older source bases (and older programming mindsets!) to Swift. If you run across a completely vexing failure of Objective-C to acknowledge your Swift class’s protocol compliance, start by making sure that you’ve actually declared the compliance in your class declaration!</p>
|
||
</div><!-- .entry-content -->
|
||
|
||
<footer class="entry-meta">
|
||
|
||
</footer><!-- .entry-meta -->
|
||
</article><!-- #post -->
|
||
|
||
<article id="post-570" class="post-570 post type-post status-publish format-standard hentry category-bug-reports category-cocoa category-mac category-os-x">
|
||
<header class="entry-header">
|
||
|
||
<h1 class="entry-title">
|
||
<a href="http://indiestack.com/2017/09/swatch-your-step/" rel="bookmark">Swatch Your Step</a>
|
||
</h1>
|
||
|
||
<div class="entry-meta">
|
||
<span class="date"><a href="http://indiestack.com/2017/09/swatch-your-step/" title="Permalink to Swatch Your Step" rel="bookmark"><time class="entry-date" datetime="2017-09-30T20:46:59+00:00">September 30, 2017</time></a></span><span class="categories-links"><a href="http://indiestack.com/category/bug-reports/" rel="category tag">Bug Reports</a>, <a href="http://indiestack.com/category/cocoa/" rel="category tag">Cocoa</a>, <a href="http://indiestack.com/category/mac/" rel="category tag">Mac</a>, <a href="http://indiestack.com/category/os-x/" rel="category tag">OS X</a></span><span class="author vcard"><a class="url fn n" href="http://indiestack.com/author/admin/" title="View all posts by Daniel Jalkut" rel="author">Daniel Jalkut</a></span> </div><!-- .entry-meta -->
|
||
</header><!-- .entry-header -->
|
||
|
||
<div class="entry-content">
|
||
<p>Shortly after macOS 10.13 was released, I received an oddly specific bug report from a customer, who observed that the little square “swatches” in the standard Mac color panel no longer had any effect on <a href="http://red-sweater.com/marsedit">MarsEdit’s</a> rich text editor.</p>
|
||
<p><img title="Colors.png" src="http://indiestack.com/wp-content/uploads/2017/09/Colors.png" alt="Screenshot of the macOS standard color panel." width="236" height="341" border="0" /></p>
|
||
<p>I was able to reproduce the problem in the shipping 3.7.11 version of MarsEdit, which for various reasons is still built using an older version of Xcode, against the 10.6 SDK. The <a href="https://red-sweater.com/blog/3244/marsedit-4-public-beta">MarsEdit 4 Beta</a>, which is built against the 10.12 SDK, <em>does not exhibit the problem.</em></p>
|
||
<p>It’s not unusual for the behavior of Apple’s frameworks to vary based on the version of SDK an application was built against. The idea is usually to preserve the old behaviors of frameworks, so that any changes do not defy the expectations of a developer who has not been able to build and test their app against a later SDK. Sometimes, the variations in behavior lead to bugs like this one.</p>
|
||
<p>Using a totally straightforward demo app, consisting only of an NSTextView and a button to bring up the color panel, I was able to confirm that the bug affects an app that links against the macOS 10.9 SDK, but does not affect an app that links against the 10.10 SDK.</p>
|
||
<p>I filed Radar #34757710: “NSColorPanel swatches don’t work on apps linked against 10.9 or earlier.” I don’t know of a workaround yet, other than compiling against a later SDK.</p>
|
||
</div><!-- .entry-content -->
|
||
|
||
<footer class="entry-meta">
|
||
|
||
</footer><!-- .entry-meta -->
|
||
</article><!-- #post -->
|
||
|
||
<article id="post-560" class="post-560 post type-post status-publish format-standard hentry category-apple category-xcode">
|
||
<header class="entry-header">
|
||
|
||
<h1 class="entry-title">
|
||
<a href="http://indiestack.com/2017/09/xcode-9-signing-workarounds/" rel="bookmark">Xcode 9 Signing Workarounds</a>
|
||
</h1>
|
||
|
||
<div class="entry-meta">
|
||
<span class="date"><a href="http://indiestack.com/2017/09/xcode-9-signing-workarounds/" title="Permalink to Xcode 9 Signing Workarounds" rel="bookmark"><time class="entry-date" datetime="2017-09-27T16:08:14+00:00">September 27, 2017</time></a></span><span class="categories-links"><a href="http://indiestack.com/category/apple/" rel="category tag">Apple</a>, <a href="http://indiestack.com/category/xcode/" rel="category tag">Xcode</a></span><span class="author vcard"><a class="url fn n" href="http://indiestack.com/author/admin/" title="View all posts by Daniel Jalkut" rel="author">Daniel Jalkut</a></span> </div><!-- .entry-meta -->
|
||
</header><!-- .entry-header -->
|
||
|
||
<div class="entry-content">
|
||
<p>I wrote on Monday about <a href="http://indiestack.com/2017/09/sandbox-inheritance-tax/">issues with Xcode 9</a> relating to code signing. Although the gist of that post involved sandboxed Mac applications that launch sandboxed child processes, the fundamental issue is a bit broader: Xcode 9 adds a “com.apple.security.get-task-allow” entitlement to any binary it signs. For the majority of developers, this is probably not an issue, because the entitlement <em>is removed</em> when an Xcode archive is exported for distribution. <em>Most</em> developers, and particularly iOS developers, use Xcode archives.</p>
|
||
<p>For folks who don’t, side effects of this additional entitlement include, but may not be limited to:</p>
|
||
<ol>
|
||
<li>Inability to launch sandboxed child processes.</li>
|
||
<li>Rejection from the Mac App Store.</li>
|
||
<li>Unknown consequences of shipping with an unintended entitlement.</li>
|
||
</ol>
|
||
<p>So, if you’re a developer who doesn’t use archives, what are your options? I’ve come up with four workarounds, and I present them here, roughly sorted by advisability and level of tedium:</p>
|
||
<ol>
|
||
<li>
|
||
<p><strong>Use Xcode 8.</strong> The simplest solution is to not upgrade to Xcode 9 unless and until you need to. Xcode 8’s signing process <em>does not impose</em> the unintended entitlement, so there is no risk of shipping a product that has it, unless you add it yourself. The downside to sticking with Xcode 8 is you won’t enjoy any of the new features of Xcode 9, you’ll have to work to support either Swift 4, macOS 10.13, or iOS 11 SDK features in your app.</p>
|
||
</li>
|
||
<li>
|
||
<p><strong>Manually re-sign the built-product.</strong> Code signing is code signing, and you’re free to sign anything you like to suit your needs, using the “codesign” command line tool. It frankly sounds like a pain in the neck to recursively re-sign every binary in the app bundle, ensuring that the suitable entitlements (minus the unwanted one) are preserved, but I’m sure it can be done.</p>
|
||
</li>
|
||
<li>
|
||
<p><strong>Use Xcode archives.</strong> It strikes me as a little obnoxious to have to use Xcode archives when they don’t offer any added benefits for my dibstrution workflow. But as a long term solution, this is probably the safest bet. The new behavior in Xcode 9 strongly suggests that Apple expects most developers to use archives, and joining the crowd is usually a good idea when it comes to avoiding trouble with Apple’s developer tools.</p>
|
||
<p>If you are using Xcode archives for the first time, particularly with a complex project, you might discover that the resulting archives are not suitable for exporting a signed application. If you get a “Generic Xcode Archive” after running Build -> Archive, you know you’ve got a problem. By default the archive process builds all targets with an “install” option, rendering their built products into a file hierarchy that will be used to build the archive. If your project includes helper apps, for example, they will be “installed” alongside your main app, resulting in a generic archive of two apps, instead of the expected archive of a single app.</p>
|
||
<p>The solution for this problem is to ensure that the “SKIP_INSTALL” build setting is set to YES for any such helper app. Just archive your main app, export the “Built Products” from the resulting archive, and look at the file hierarchy to determine whether you have subtargets that need to have installation disabled.</p>
|
||
</li>
|
||
<li>
|
||
<p><strong>Hack Xcode 9.</strong> In a hurry to ship an update to your app, and you’ve only got Xcode 9 handy? It turns out the imposition of this “com.apple.security.get-task-allow” entitlement is controlled by a single property list file inside Xcode’s application bundle. As a test, I edited the file:</p>
|
||
<pre>
|
||
Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Xcode/PrivatePlugIns/IDEOSXSupportCore.ideplugin/Contents/Resources/BaseEntitlements.plist
|
||
</pre>
|
||
<p>It contains a single entitlement, the one that’s causing our grief. I deleted the entitlement from the list, saved the file, and relaunched Xcode. After doing so, everything is “back to normal.”</p>
|
||
<p>I can’t strongly encourage you to hack your copy of Xcode because I don’t know what the consequences might be. “It seems fine,” but you’re on your own if you decide to do this.
|
||
</li>
|
||
</ol>
|
||
<p>This small change in Xcode 9 causes a lot of unexpected grief for folks who don’t use Xcode archives. I am curious to know how widespread the problem is, and enthusiastic to get the word out about it so that affected folks can work around the problem, or at least be aware of it. Myself, I’ll probably end up adopting the workaround of using Xcode archives, but I’m hopeful that Apple will see the merit of providing an option in an update to Xcode 9 that supports disabling the addition of this entitlement without archiving and exporting a built product.</p>
|
||
</div><!-- .entry-content -->
|
||
|
||
<footer class="entry-meta">
|
||
|
||
</footer><!-- .entry-meta -->
|
||
</article><!-- #post -->
|
||
|
||
<article id="post-556" class="post-556 post type-post status-publish format-standard hentry category-cocoa category-os-x">
|
||
<header class="entry-header">
|
||
|
||
<h1 class="entry-title">
|
||
<a href="http://indiestack.com/2017/09/unordered-directory-contents/" rel="bookmark">Unordered Directory Contents</a>
|
||
</h1>
|
||
|
||
<div class="entry-meta">
|
||
<span class="date"><a href="http://indiestack.com/2017/09/unordered-directory-contents/" title="Permalink to Unordered Directory Contents" rel="bookmark"><time class="entry-date" datetime="2017-09-27T14:10:59+00:00">September 27, 2017</time></a></span><span class="categories-links"><a href="http://indiestack.com/category/cocoa/" rel="category tag">Cocoa</a>, <a href="http://indiestack.com/category/os-x/" rel="category tag">OS X</a></span><span class="author vcard"><a class="url fn n" href="http://indiestack.com/author/admin/" title="View all posts by Daniel Jalkut" rel="author">Daniel Jalkut</a></span> </div><!-- .entry-meta -->
|
||
</header><!-- .entry-header -->
|
||
|
||
<div class="entry-content">
|
||
<p>Since I updated to macOS 10.13 High Sierra, some of my unit tests broke. Examining the failures more carefully, I discovered that they were making assumptions about the order that Foundation’s FileManager.contentsOfDirectory(atPath:) would return items.</p>
|
||
<p>I wrote a quick playground to test the behavior on a 10.12 machine:</p>
|
||
<pre>
|
||
import Foundation
|
||
|
||
let array = try! FileManager.default.contentsOfDirectory(atPath: "/Applications/Utilities")
|
||
print("\(array.debugDescription)")
|
||
</pre>
|
||
<p>The results come back alphabetically ordered by file name:</p>
|
||
<pre>
|
||
[".DS_Store", ".localized", "Activity Monitor.app", "Adobe Flash Player Install Manager.app", "AirPort Utility.app", "Audio MIDI Setup.app", "Bluetooth File Exchange.app", "Boot Camp Assistant.app", "ColorSync Utility.app", "Console.app", "Digital Color Meter.app", "Disk Utility.app", "Grab.app", "Grapher.app", "Keychain Access.app", "Migration Assistant.app", "Script Editor.app", "System Information.app", "Terminal.app", "VoiceOver Utility.app"]
|
||
</pre>
|
||
<p>The same playground on 10.13 tells a different story:</p>
|
||
<pre>
|
||
["AirPort Utility.app", "VoiceOver Utility.app", "Terminal.app", "Activity Monitor.app", ".DS_Store", "Grapher.app", "Audio MIDI Setup.app", ".localized", "System Information.app", "Keychain Access.app", "Grab.app", "Migration Assistant.app", "Script Editor.app", "ColorSync Utility.app", "Console.app", "Disk Utility.app", "Bluetooth File Exchange.app", "Boot Camp Assistant.app", "Digital Color Meter.app"]
|
||
</pre>
|
||
<p>I thought at first this might have been related to the APFS conversion that 10.13 applied to my boot volume, but the same ordering discrepancy occurs for items on my HFS+ volumes as well.</p>
|
||
<p>After checking the <a href="https://developer.apple.com/library/content/releasenotes/Foundation/RN-Foundation/index.html">10.13 release notes</a> for clues, and finding none, I consulted the <a href="https://developer.apple.com/documentation/foundation/nsfilemanager/1414584-contentsofdirectoryatpath?language=objc">documentation</a>. Well, what do you know?</p>
|
||
<blockquote><p>The order of the files in the returned array is undefined.</p></blockquote>
|
||
<p>So, mea culpa. The test code in question probably <em>shouldn’t</em> have ever made assumptions about the ordering of items returned from this method. While it has evidently always been <em>undefined</em>, it appears they are only making good on that promise in 10.13. You have been warned!</p>
|
||
<p><strong>Update:</strong> It turns out I have some real bugs in my apps, not just in my tests, because of assuming the results of this call will be reasonably sorted. Luckily I use a bottleneck method for obtaining the list of files, and I can impose my own sorting right at the source. If you’re looking to make the same kinds of changes to your app, be sure to heed <a href="https://twitter.com/petermaurer/status/913109782378291207">Peter Maurer’s advice</a> and use “localizedStandardCompare” (available since macOS10.6/iOS4) to obtain Finder-like ordering of the results.</p>
|
||
</div><!-- .entry-content -->
|
||
|
||
<footer class="entry-meta">
|
||
|
||
</footer><!-- .entry-meta -->
|
||
</article><!-- #post -->
|
||
|
||
<article id="post-551" class="post-551 post type-post status-publish format-standard hentry category-apple category-bug-reports category-xcode">
|
||
<header class="entry-header">
|
||
|
||
<h1 class="entry-title">
|
||
<a href="http://indiestack.com/2017/09/sandbox-inheritance-tax/" rel="bookmark">Sandbox Inheritance Tax</a>
|
||
</h1>
|
||
|
||
<div class="entry-meta">
|
||
<span class="date"><a href="http://indiestack.com/2017/09/sandbox-inheritance-tax/" title="Permalink to Sandbox Inheritance Tax" rel="bookmark"><time class="entry-date" datetime="2017-09-25T17:21:30+00:00">September 25, 2017</time></a></span><span class="categories-links"><a href="http://indiestack.com/category/apple/" rel="category tag">Apple</a>, <a href="http://indiestack.com/category/bug-reports/" rel="category tag">Bug Reports</a>, <a href="http://indiestack.com/category/xcode/" rel="category tag">Xcode</a></span><span class="author vcard"><a class="url fn n" href="http://indiestack.com/author/admin/" title="View all posts by Daniel Jalkut" rel="author">Daniel Jalkut</a></span> </div><!-- .entry-meta -->
|
||
</header><!-- .entry-header -->
|
||
|
||
<div class="entry-content">
|
||
<p>I ran into a subtle bug with Xcode 9 that I think is worth sharing. Specifically, this bug affects Mac applications that:</p>
|
||
<ol>
|
||
<li>Are sandboxed.</li>
|
||
<li>Launch a sandboxed subprocess with NSTask (or posix_spawn).</li>
|
||
<li>Configure the subprocess to inherit the parent’s sandbox.</li>
|
||
</ol>
|
||
<p>When such an app is compiled with Xcode 9, the subprocess will crash whenever the parent process launches it. A canonical example of something that might suffer from this problem is a bundled crash-monitor. I embed one with my apps to keep an eye on the running status of the parent process, and to present a crash-reporting interface to users if the host app terminates prematurely. When I build and run my app with Xcode 9, the bundled crash monitor dies instantly upon being launched.</p>
|
||
<p>It took me a while to realize that the subprocess is dying because it fails to satisfy the contract for inheriting a sandbox. From Apple’s “<a href="https://developer.apple.com/library/content/documentation/Miscellaneous/Reference/EntitlementKeyReference/Chapters/EnablingAppSandbox.html#//apple_ref/doc/uid/TP40011195-CH4-SW15">Enabling App Sandbox Inheritance</a>“:</p>
|
||
<blockquote><p>
|
||
To enable sandbox inheritance, a child target must use exactly two App Sandbox entitlement keys: com.apple.security.app-sandbox and com.apple.security.inherit. If you specify any other App Sandbox entitlement, the system aborts the child process.
|
||
</p></blockquote>
|
||
<p>Well, that’s funny because my child process <em>does specify only those two keys</em>, but the system is aborting it anyway. It turns out that Xcode 9 is <em>inserting a third entitlement</em> without my permission. Clicking on the detail of the “Process Product Packaging” build phase in Xcode’s log navigator, I can see that there are <em>three entitlements</em> for my target:</p>
|
||
<p><img src="http://indiestack.com/wp-content/uploads/2017/09/ProductPackaging.png" alt="Xcode build log detail showing the wrong entitlements." title="ProductPackaging.png" border="0" width="595" height="246" /></p>
|
||
<p>When my subprocess is launched, the system sees that extra “com.apple.security.get-task-allow” entitlement in the context of “com.apple.security.inherit”, and unceremoniously crashes my the child process.</p>
|
||
<p>I’m not sure what Apple’s reasoning is for imposing this entitlement on sandboxed targets, but it appears to be doing so across the board, for literally every sandboxed target in my app. I confirmed that all of my apps, XPC processes, helper tools, etc., are all getting this bonus entitlement.</p>
|
||
<p>I searched Xcode’s files, and discovered the entitlement listed in this file inside the Xcode app bundle:</p>
|
||
<pre>
|
||
Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Xcode/PrivatePlugIns/IDEOSXSupportCore.ideplugin/Contents/Resources/BaseEntitlements.plist
|
||
</pre>
|
||
<p>Putting aside the question of whether it’s appropriate for Xcode to <em>surreptitiously</em> add entitlements that are not specified by the developer’s own list of permissions, the addition of the entitlement <em>for these particular targets</em>, ones that inherit their parent’s sandbox, turns out to be a fatal move.</p>
|
||
<p>Ideally I would be able to work around this by adding a custom build phase to manually tweak the generated entitlements file, removing the unwanted key. But the “Process Product Packaging” build phase happens so late in the build process that it’s after the last user-specified custom build phase. There’s no room in Xcode’s current design for fixing up the problematic entitlements before they are incorporated into the signed product. As far as I can tell the only clean workaround would be to redundantly re-sign the child app with a custom script, and corrected entitlements, after Xcode’s build process is completed.</p>
|
||
<p>I filed Radar #34628449, “Sandboxed project build with Xcode 9 cannot launch child process.”</p>
|
||
<p><strong>Update:</strong> Colin Barrett <a href="https://twitter.com/cbarrett/status/912427986254692353">pointed out on Twitter</a> that the entitlement in question here, “com.apple.security.get-task-allow”, may be required in order to attach to and debug a process. If true, then I think this is something that was handled in a different way in Xcode 8. I can confirm that my apps do not have the entitlement imposed on them by Xcode 8, yet I am able to attach to and debug them.</p>
|
||
<p>If Apple changed the debugger infrastructure in Xcode 9 so that the relationship between the debugger and target processes is more locked down, requiring a specific entitlement, then that’s probably a good thing. But if this change was made without thinking about the implications for the above-cited “strict two entitlement” rule for sandbox inheritance, then probably some flexibility needs to be applied to that rule.</p>
|
||
<p>Finally, as I noted above the entitlement is being applied to <em>all my targets</em>. What I didn’t clarify is that the entitlement is added even when Building and Archiving. A release build’s binaries are endowed with this additional entitlement, which may also bring additional security vulnerabilities to the app.</p>
|
||
<p>I would not ship a sandboxed Mac app that is built with Xcode 9, until we understand more about when Xcode applies this entitlement, and whether it can be prevented for Release builds at the very least.</p>
|
||
<p><strong>Update 2:</strong> I’ve learned that Xcode’s “Export Archive” functionality causes the unwanted entitlement to be removed. Apparently the assumption is that everybody creates Xcode archives as part of their build and release process. I am sure this is true for most (all?) iOS deployments, but for Developer-ID signed apps on the Mac, there has traditionally been less of an incentive to do this. Got a properly signed Mac application? Zip it up, put it on a web server, and you’re done.</p>
|
||
<p>I’m not sure yet whether I’ll switch my build process to use archiving, or whether I’ll pull some other stunt to redo the code signing with corrected entitlements. In any case this has been quite an adventure today getting to the bottom of this. I updated my bug report with Apple to request that they provide some standard build flag that would prevent the problematic entitlement from being added from the start. In the mean time, I’ll explore one of the workarounds and get my builds back to fully functional!</p>
|
||
</div><!-- .entry-content -->
|
||
|
||
<footer class="entry-meta">
|
||
|
||
</footer><!-- .entry-meta -->
|
||
</article><!-- #post -->
|
||
|
||
<article id="post-547" class="post-547 post type-post status-publish format-standard hentry category-bug-reports category-objc category-swift category-xcode">
|
||
<header class="entry-header">
|
||
|
||
<h1 class="entry-title">
|
||
<a href="http://indiestack.com/2017/09/better-swift-completion/" rel="bookmark">Better Swift Completion</a>
|
||
</h1>
|
||
|
||
<div class="entry-meta">
|
||
<span class="date"><a href="http://indiestack.com/2017/09/better-swift-completion/" title="Permalink to Better Swift Completion" rel="bookmark"><time class="entry-date" datetime="2017-09-22T11:33:18+00:00">September 22, 2017</time></a></span><span class="categories-links"><a href="http://indiestack.com/category/bug-reports/" rel="category tag">Bug Reports</a>, <a href="http://indiestack.com/category/objc/" rel="category tag">ObjC</a>, <a href="http://indiestack.com/category/swift/" rel="category tag">Swift</a>, <a href="http://indiestack.com/category/xcode/" rel="category tag">Xcode</a></span><span class="author vcard"><a class="url fn n" href="http://indiestack.com/author/admin/" title="View all posts by Daniel Jalkut" rel="author">Daniel Jalkut</a></span> </div><!-- .entry-meta -->
|
||
</header><!-- .entry-header -->
|
||
|
||
<div class="entry-content">
|
||
<p>Apple released <a href="https://developer.apple.com/xcode/">Xcode 9</a> earlier this week, and in spite of a few glitches here and there, I have found the update to be an overall improvement over Xcode 8. It’s nice that Apple continues to invest in the core tools for Mac and iOS developers.</p>
|
||
<p>I’ve been dabbling in more and more Swift development lately, and it’s brought to light a shortcoming in Xcode’s code completion which has unfortunately <em>not improved</em> in Xcode 9: completion of Swift function calls when there is a large quantity of candidates.</p>
|
||
<p>Take for example NSAttributedString. If I want to initialize a new instance in Swift, I type “NSAttributedString(” to bring up the list of compatible init methods I can choose from:</p>
|
||
<p><img src="http://indiestack.com/wp-content/uploads/2017/09/SwiftCompletion-1.png" alt="SwiftCompletion" title="SwiftCompletion.png" border="0" width="452" height="225" /></p>
|
||
<p>The problem at this point is that I have to navigate the menu by hand. I can’t narrow down the list of completions any further by typing, because the very next character I type will be interpreted as the manual filling out of parameters of the NSAttributedString initializer.</p>
|
||
<p><img src="http://indiestack.com/wp-content/uploads/2017/09/BadCompletion-1.png" alt="BadCompletion" title="BadCompletion.png" border="0" width="437" height="232" /></p>
|
||
<p>This is a situation where Objective-C gets much nicer treatment in the editor. Because completion in Objective-C begins when I start typing “init”, and because the named first parameter is <em>part of the init</em> message name, I can winnow down the results quite a bit:</p>
|
||
<p><img src="http://indiestack.com/wp-content/uploads/2017/09/Pasted_Image_9_22_17__11_24_AM.png" alt="Pasted Image 9 22 17 11 24 AM" title="Pasted_Image_9_22_17__11_24_AM.png" border="0" width="438" height="146" /></p>
|
||
<p>Better still, because Xcode performs a fuzzy match on the typing, I can proceed to type the names of <em>additional</em> parameters to zero in completely on the variation I want:</p>
|
||
<p><img src="http://indiestack.com/wp-content/uploads/2017/09/MEAppController_AppDelegate_m_—_Edited.png" alt="MEAppController AppDelegate m Edited" title="MEAppController_AppDelegate_m_—_Edited.png" border="0" width="649" height="124" /></p>
|
||
<p>When I accept the completion, all of my typing is replaced with the expected, templated parameter placeholders for the chose initializer.</p>
|
||
<p>I filed Radar #34594940 requesting better completion for Swift.</p>
|
||
</div><!-- .entry-content -->
|
||
|
||
<footer class="entry-meta">
|
||
|
||
</footer><!-- .entry-meta -->
|
||
</article><!-- #post -->
|
||
|
||
<article id="post-534" class="post-534 post type-post status-publish format-standard hentry category-apple category-automation category-bug-reports category-os-x">
|
||
<header class="entry-header">
|
||
|
||
<h1 class="entry-title">
|
||
<a href="http://indiestack.com/2017/08/javascript-osa-handler-invocation/" rel="bookmark">JavaScript OSA Handler Invocation</a>
|
||
</h1>
|
||
|
||
<div class="entry-meta">
|
||
<span class="date"><a href="http://indiestack.com/2017/08/javascript-osa-handler-invocation/" title="Permalink to JavaScript OSA Handler Invocation" rel="bookmark"><time class="entry-date" datetime="2017-08-18T11:40:36+00:00">August 18, 2017</time></a></span><span class="categories-links"><a href="http://indiestack.com/category/apple/" rel="category tag">Apple</a>, <a href="http://indiestack.com/category/automation/" rel="category tag">Automation</a>, <a href="http://indiestack.com/category/bug-reports/" rel="category tag">Bug Reports</a>, <a href="http://indiestack.com/category/os-x/" rel="category tag">OS X</a></span><span class="author vcard"><a class="url fn n" href="http://indiestack.com/author/admin/" title="View all posts by Daniel Jalkut" rel="author">Daniel Jalkut</a></span> </div><!-- .entry-meta -->
|
||
</header><!-- .entry-header -->
|
||
|
||
<div class="entry-content">
|
||
<p>When Apple added support to macOS to support <a href="https://developer.apple.com/library/content/releasenotes/InterapplicationCommunication/RN-JavaScriptForAutomation/Articles/OSX10-10.html#//apple_ref/doc/uid/TP40014508-CH109-SW1">JavaScript for Automation</a>, they did so in a way that more or less allows folks who invoke AppleScripts to invoke JavaScript for Automation scripts as if they were exactly the same. An abstraction in Apple’s Open Script Architecture (OSA) makes it easy for script-running tools to theoretically handle any number of scripting languages without concern for the implementation details of those languages.</p>
|
||
<p>This mostly works, but I recently received a bug report that shed light on a problem with Apple’s implementation of JavaScript with respect to <em>invoking a specific named handler.</em> The OSA provides a mechanism for loading and running a specific handler, or function, within a script. My app <a href="http://red-sweater.com/fastscripts/">FastScripts</a> takes advantage of this to query a script about whether it would prefer to be invoked in another process or not. Unfortunately, when it comes to JavaScript, Apple’s implementation <em>runs the whole script</em> in addition to running just the specific, named handler.</p>
|
||
<p>If you’ve got Xcode handy, you can use this simple playground content to observe the problem:</p>
|
||
<pre>
|
||
import OSAKit
|
||
|
||
if let javaScriptLanguage = OSALanguage(forName: "JavaScript") {
|
||
let scriptSource = "Application('Safari').activate();" +
|
||
"function boo() { ObjC.import('Cocoa'); $.NSBeep(); }"
|
||
let myScript = OSAScript(source: scriptSource, language: javaScriptLanguage)
|
||
|
||
// Only the behavior of boo should be observed
|
||
myScript.executeHandler(withName: "boo", arguments: [], error: nil)
|
||
}
|
||
|
||
// Give time for the beep to sound
|
||
RunLoop.current.run(until: Date(timeIntervalSinceNow:5))
|
||
</pre>
|
||
<p>The named function “boo()” only invokes NSBeep, so when this playground is run, all that should happen is a beep should be emitted from the Mac. Instead, when it runs Safari becomes the active application. This is because in addition to running the “boo()” handler, it also runs the whole script at the top level.</p>
|
||
<p>A workaround to the bug is to wrap the top level functionality of a script in a “run()” handler, so where the scriptSource is declared above, instead use:</p>
|
||
<pre>
|
||
let scriptSource = "function run() { Application('Safari').activate(); }" +
|
||
"function boo() { ObjC.import('Cocoa'); $.NSBeep(); }"
|
||
</pre>
|
||
<p>I hope this helps the one other person on earth who cares about invoking JavaScript for Automation methods indvidually! (Radar #33962901, though I’m not holding my breath on this one!)</p>
|
||
</div><!-- .entry-content -->
|
||
|
||
<footer class="entry-meta">
|
||
|
||
</footer><!-- .entry-meta -->
|
||
</article><!-- #post -->
|
||
|
||
<article id="post-529" class="post-529 post type-post status-publish format-standard hentry category-apple category-bug-reports category-open-source category-xcode">
|
||
<header class="entry-header">
|
||
|
||
<h1 class="entry-title">
|
||
<a href="http://indiestack.com/2017/06/xcode-github-integration/" rel="bookmark">Xcode GitHub Integration</a>
|
||
</h1>
|
||
|
||
<div class="entry-meta">
|
||
<span class="date"><a href="http://indiestack.com/2017/06/xcode-github-integration/" title="Permalink to Xcode GitHub Integration" rel="bookmark"><time class="entry-date" datetime="2017-06-07T10:34:59+00:00">June 7, 2017</time></a></span><span class="categories-links"><a href="http://indiestack.com/category/apple/" rel="category tag">Apple</a>, <a href="http://indiestack.com/category/bug-reports/" rel="category tag">Bug Reports</a>, <a href="http://indiestack.com/category/open-source/" rel="category tag">Open Source</a>, <a href="http://indiestack.com/category/xcode/" rel="category tag">Xcode</a></span><span class="author vcard"><a class="url fn n" href="http://indiestack.com/author/admin/" title="View all posts by Daniel Jalkut" rel="author">Daniel Jalkut</a></span> </div><!-- .entry-meta -->
|
||
</header><!-- .entry-header -->
|
||
|
||
<div class="entry-content">
|
||
<p>Apple’s <a href="http://adcdownload.apple.com/WWDC_2017/Xcode_9_beta/Xcode_9_beta_Release_Notes.pdf">beta release of Xcode 9</a> features impressive improvements to its source control features, including streamlined integration with GitHub. There’s even a fancy “Open in Xcode” button when you go to clone a project:</p>
|
||
<p><img src="http://indiestack.com/wp-content/uploads/2017/06/OpenInXcode.png" alt="Screen capture of the GitHub interface for cloning a project" title="OpenInXcode.png" border="0" width="432" height="254" /></p>
|
||
<p>This integration is amazing. You just click the button, specify a save folder in Xcode, and boom! You’re off and …</p>
|
||
<p><img src="http://indiestack.com/wp-content/uploads/2017/06/MacDevelopment.png" alt="Screen capture of build failure indicating a missing signing certificate" title="MacDevelopment.png" border="0" width="515" height="229" /></p>
|
||
<p>Oh, right. Code signing. The otherwise stellar GitHub integration in Xcode underscores a longstanding deficiency in how it manages code signing identities for multi-team, collaborative projects. Precisely the kinds of projects you’re liable to find on GitHub.</p>
|
||
<p>The problem could be solved, or at least diminished greatly, by providing some mechanism for declaring that a project should be code signed “with the user’s own default developer team.” The default branch of any open source project targeting Apple platforms, would specify the DEVELOPMENT_TEAM as something like:</p>
|
||
<pre>
|
||
DEVELOPMENT_TEAM = Automatic
|
||
</pre>
|
||
<p>Xcode would provide a user-level setting for “Default Development Team”, and in the absence of any overriding setting, <em>that team would be used</em> whenever a project was configured as above.</p>
|
||
<p>I <a href="http://indiestack.com/2016/06/dynamic-development-team/">wrote about this problem</a> once before, but with all the work being put into streamlining the experience of cloning from and pushing to GitHub, now is an ideal time for Apple to embrace a fix. Radar #32614751.</p>
|
||
<p>Another issue that stops short the cloning, and immediate building and running, of open source projects, is the need to fulfill external dependencies. In some cases this might require manually downloading and installing libraries, or cloning projects, but in the vast majority of cases the dependencies will be specified using built-in Git submodule support, or a popular package manager. In each of these cases, it should be trivial for Xcode to detect that the project it has just cloned also has dependencies:</p>
|
||
<ul>
|
||
<li><strong>Git submodules</strong>: there is a .gitmodules directory.</li>
|
||
<li><strong>Carthage</strong>: there is a Cartfile file.</li>
|
||
<li><strong>CocoaPods</strong>: there is a Podfile file.</li>
|
||
<li><strong>Swift Package Manager</strong>: there is a Swift.package file.</li>
|
||
</ul>
|
||
<p>If Xcode sees evidence of any of these techniques at play, it could do the favor of checking them out immediately after cloning the project. Radar #32615265.</p>
|
||
<p>The GitHub integration coming in Xcode 9 provides a nearly effortless capability for cloning, building, and running open source projects that target Apple platforms. Ideally it would also go the extra mile and provide for variable, dynamic development teams, as well as conduct a rudimentary check for dependencies that must be checked out before commencing work on the project.</p>
|
||
</div><!-- .entry-content -->
|
||
|
||
<footer class="entry-meta">
|
||
|
||
</footer><!-- .entry-meta -->
|
||
</article><!-- #post -->
|
||
|
||
<article id="post-523" class="post-523 post type-post status-publish format-standard hentry category-cocoa category-links category-mac">
|
||
<header class="entry-header">
|
||
|
||
<h1 class="entry-title">
|
||
<a href="http://indiestack.com/2017/06/evergreen-images/" rel="bookmark">Evergreen Images</a>
|
||
</h1>
|
||
|
||
<div class="entry-meta">
|
||
<span class="date"><a href="http://indiestack.com/2017/06/evergreen-images/" title="Permalink to Evergreen Images" rel="bookmark"><time class="entry-date" datetime="2017-06-01T12:47:35+00:00">June 1, 2017</time></a></span><span class="categories-links"><a href="http://indiestack.com/category/cocoa/" rel="category tag">Cocoa</a>, <a href="http://indiestack.com/category/links/" rel="category tag">Links</a>, <a href="http://indiestack.com/category/mac/" rel="category tag">Mac</a></span><span class="author vcard"><a class="url fn n" href="http://indiestack.com/author/admin/" title="View all posts by Daniel Jalkut" rel="author">Daniel Jalkut</a></span> </div><!-- .entry-meta -->
|
||
</header><!-- .entry-header -->
|
||
|
||
<div class="entry-content">
|
||
<p>Brent Simmons, the original developer of <a href="https://red-sweater.com/marsedit/">MarsEdit</a> and <a href="http://netnewswireapp.com">NetNewsWire</a>, is building a new feed reader app called <a href="http://ranchero.com/evergreen/">Evergreen</a>:</p>
|
||
<blockquote><p>Evergreen is an open source, productivity-style feed reader for Macs.</p>
|
||
<p>It’s at a very early stage — we use it, but we don’t expect other people to use it yet.</p></blockquote>
|
||
<p>I’ve never been one to shy away from early-stage software, so of course I ran to the <a href="https://github.com/brentsimmons/Evergreen">GitHub project page</a>, cloned the repository, and built it immediately on my own Mac.</p>
|
||
<p><img src="http://indiestack.com/wp-content/uploads/2017/06/EvergreenGeneric.png" alt="Screenshot of Evergreen about box without a custom icon." title="EvergreenGeneric.png" border="0" width="284" height="198" /></p>
|
||
<p>Ahh, the tell-tale sign of a young app: the generic about box. Personally, I like to give apps-in-progress an icon, even if only a placeholder image, as soon as possible. It occurred to me that Apple has done the favor of providing a pretty-darned-suitable image for “Evergreen” in the form of its Emoji glyph of the same name:</p>
|
||
<p><span style="font-size:3em;">🌲</span></p>
|
||
<p>Since I have the source code right here, why don’t I render that tree at a large size in a graphics app, resize it to a million different resolutions, bundle it up and check it in to the Evergreen source base?</p>
|
||
<p>Because that’s not nearly as fun as doing it in code. I dove into the Evergreen application delegate class, adding the <a href="https://github.com/brentsimmons/Evergreen/blob/master/Evergreen/AppDelegate.swift#L43-L66">following function</a>:</p>
|
||
<pre>
|
||
private func evergreenImage() -> NSImage? {
|
||
var image: NSImage? = nil
|
||
let imageWidth = 1024
|
||
let imageHeight = 1024
|
||
let imageSize = NSMakeSize(CGFloat(imageWidth), CGFloat(imageHeight))
|
||
|
||
if let drawingContext = CGContext(data: nil, width: imageWidth, height: imageHeight, bitsPerComponent: 8, bytesPerRow: 0, space: CGColorSpaceCreateDeviceRGB(), bitmapInfo: CGImageAlphaInfo.premultipliedFirst.rawValue) {
|
||
|
||
let graphicsContext = NSGraphicsContext(cgContext: drawingContext, flipped: false)
|
||
NSGraphicsContext.saveGraphicsState()
|
||
NSGraphicsContext.setCurrent(graphicsContext)
|
||
|
||
let targetRect = NSRect(origin: NSZeroPoint, size: imageSize)
|
||
NSString(string: "🌲").draw(in: targetRect, withAttributes: [NSFontAttributeName: NSFont.systemFont(ofSize: 1000)])
|
||
|
||
NSGraphicsContext.restoreGraphicsState()
|
||
|
||
if let coreImage = drawingContext.makeImage() {
|
||
image = NSImage(cgImage: coreImage, size: imageSize)
|
||
}
|
||
}
|
||
|
||
return image
|
||
}
|
||
</pre>
|
||
<p>In summary this code: creates a CoreGraphics drawing context, renders a huge evergreen Emoji glyph into it, and creates an NSImage out of it.</p>
|
||
<p>Then from the “applicationDidFinishLaunching()” function:</p>
|
||
<pre>
|
||
if let appIconImage = evergreenImage() {
|
||
appIconImage.setName("NSApplicationIcon")
|
||
NSApplication.shared().applicationIconImage = appIconImage
|
||
}
|
||
</pre>
|
||
<p>Give the newly created image the canonical name, used by AppKit, for looking up the application icon, and immediately change the application’s icon image to reflect the new value. It worked a treat:</p>
|
||
<p><img src="http://indiestack.com/wp-content/uploads/2017/06/EvergreenEmoji.png" alt="EvergreenEmoji" title="EvergreenEmoji.png" border="0" width="284" height="198" /></p>
|
||
<p>In programming there is usually a hard way, an easy way, <em>and a fun way</em>. Be sure to take the third option as often as possible.</p>
|
||
</div><!-- .entry-content -->
|
||
|
||
<footer class="entry-meta">
|
||
|
||
</footer><!-- .entry-meta -->
|
||
</article><!-- #post -->
|
||
|
||
<nav class="navigation paging-navigation" role="navigation">
|
||
<h1 class="screen-reader-text">Posts navigation</h1>
|
||
<div class="nav-links">
|
||
|
||
<div class="nav-previous"><a href="http://indiestack.com/page/2/" ><span class="meta-nav">←</span> Older posts</a></div>
|
||
|
||
|
||
</div><!-- .nav-links -->
|
||
</nav><!-- .navigation -->
|
||
|
||
|
||
</div><!-- #content -->
|
||
</div><!-- #primary -->
|
||
|
||
|
||
</div><!-- #main -->
|
||
<footer id="colophon" class="site-footer" role="contentinfo">
|
||
<div id="secondary" class="sidebar-container" role="complementary">
|
||
<div class="widget-area">
|
||
<aside id="search-2" class="widget widget_search"><form role="search" method="get" class="search-form" action="http://indiestack.com/">
|
||
<label>
|
||
<span class="screen-reader-text">Search for:</span>
|
||
<input type="search" class="search-field" placeholder="Search …" value="" name="s" />
|
||
</label>
|
||
<input type="submit" class="search-submit" value="Search" />
|
||
</form></aside> <aside id="recent-posts-2" class="widget widget_recent_entries"> <h3 class="widget-title">Recent Posts</h3> <ul>
|
||
<li>
|
||
<a href="http://indiestack.com/2017/11/treat-warnings-as-errors-in-swift/">Treat Warnings as Errors in Swift</a>
|
||
</li>
|
||
<li>
|
||
<a href="http://indiestack.com/2017/10/selective-selector-mapping/">Selective Selector Mapping</a>
|
||
</li>
|
||
<li>
|
||
<a href="http://indiestack.com/2017/09/swatch-your-step/">Swatch Your Step</a>
|
||
</li>
|
||
<li>
|
||
<a href="http://indiestack.com/2017/09/xcode-9-signing-workarounds/">Xcode 9 Signing Workarounds</a>
|
||
</li>
|
||
<li>
|
||
<a href="http://indiestack.com/2017/09/unordered-directory-contents/">Unordered Directory Contents</a>
|
||
</li>
|
||
</ul>
|
||
</aside> <aside id="archives-2" class="widget widget_archive"><h3 class="widget-title">Archives</h3> <ul>
|
||
<li><a href='http://indiestack.com/2017/11/'>November 2017</a></li>
|
||
<li><a href='http://indiestack.com/2017/10/'>October 2017</a></li>
|
||
<li><a href='http://indiestack.com/2017/09/'>September 2017</a></li>
|
||
<li><a href='http://indiestack.com/2017/08/'>August 2017</a></li>
|
||
<li><a href='http://indiestack.com/2017/06/'>June 2017</a></li>
|
||
<li><a href='http://indiestack.com/2017/05/'>May 2017</a></li>
|
||
<li><a href='http://indiestack.com/2017/04/'>April 2017</a></li>
|
||
<li><a href='http://indiestack.com/2017/03/'>March 2017</a></li>
|
||
<li><a href='http://indiestack.com/2017/01/'>January 2017</a></li>
|
||
<li><a href='http://indiestack.com/2016/12/'>December 2016</a></li>
|
||
<li><a href='http://indiestack.com/2016/10/'>October 2016</a></li>
|
||
<li><a href='http://indiestack.com/2016/08/'>August 2016</a></li>
|
||
<li><a href='http://indiestack.com/2016/07/'>July 2016</a></li>
|
||
<li><a href='http://indiestack.com/2016/06/'>June 2016</a></li>
|
||
<li><a href='http://indiestack.com/2016/05/'>May 2016</a></li>
|
||
<li><a href='http://indiestack.com/2016/04/'>April 2016</a></li>
|
||
<li><a href='http://indiestack.com/2016/03/'>March 2016</a></li>
|
||
<li><a href='http://indiestack.com/2016/02/'>February 2016</a></li>
|
||
<li><a href='http://indiestack.com/2016/01/'>January 2016</a></li>
|
||
<li><a href='http://indiestack.com/2015/09/'>September 2015</a></li>
|
||
<li><a href='http://indiestack.com/2015/08/'>August 2015</a></li>
|
||
<li><a href='http://indiestack.com/2015/07/'>July 2015</a></li>
|
||
<li><a href='http://indiestack.com/2015/05/'>May 2015</a></li>
|
||
<li><a href='http://indiestack.com/2015/04/'>April 2015</a></li>
|
||
<li><a href='http://indiestack.com/2015/02/'>February 2015</a></li>
|
||
<li><a href='http://indiestack.com/2015/01/'>January 2015</a></li>
|
||
<li><a href='http://indiestack.com/2014/12/'>December 2014</a></li>
|
||
<li><a href='http://indiestack.com/2014/11/'>November 2014</a></li>
|
||
<li><a href='http://indiestack.com/2014/10/'>October 2014</a></li>
|
||
<li><a href='http://indiestack.com/2014/09/'>September 2014</a></li>
|
||
<li><a href='http://indiestack.com/2014/08/'>August 2014</a></li>
|
||
<li><a href='http://indiestack.com/2014/05/'>May 2014</a></li>
|
||
<li><a href='http://indiestack.com/2014/01/'>January 2014</a></li>
|
||
<li><a href='http://indiestack.com/2013/12/'>December 2013</a></li>
|
||
<li><a href='http://indiestack.com/2013/10/'>October 2013</a></li>
|
||
<li><a href='http://indiestack.com/2013/09/'>September 2013</a></li>
|
||
<li><a href='http://indiestack.com/2013/05/'>May 2013</a></li>
|
||
</ul>
|
||
</aside><aside id="categories-2" class="widget widget_categories"><h3 class="widget-title">Categories</h3> <ul>
|
||
<li class="cat-item cat-item-11"><a href="http://indiestack.com/category/apple/" >Apple</a>
|
||
</li>
|
||
<li class="cat-item cat-item-6"><a href="http://indiestack.com/category/automation/" >Automation</a>
|
||
</li>
|
||
<li class="cat-item cat-item-17"><a href="http://indiestack.com/category/bug-reports/" >Bug Reports</a>
|
||
</li>
|
||
<li class="cat-item cat-item-8"><a href="http://indiestack.com/category/cocoa/" >Cocoa</a>
|
||
</li>
|
||
<li class="cat-item cat-item-14"><a href="http://indiestack.com/category/debugging/" >Debugging</a>
|
||
</li>
|
||
<li class="cat-item cat-item-21"><a href="http://indiestack.com/category/hacking/" >Hacking</a>
|
||
</li>
|
||
<li class="cat-item cat-item-18"><a href="http://indiestack.com/category/humor/" >Humor</a>
|
||
</li>
|
||
<li class="cat-item cat-item-3"><a href="http://indiestack.com/category/ios/" >iOS</a>
|
||
</li>
|
||
<li class="cat-item cat-item-10"><a href="http://indiestack.com/category/links/" >Links</a>
|
||
</li>
|
||
<li class="cat-item cat-item-5"><a href="http://indiestack.com/category/mac/" >Mac</a>
|
||
</li>
|
||
<li class="cat-item cat-item-23"><a href="http://indiestack.com/category/objc/" >ObjC</a>
|
||
</li>
|
||
<li class="cat-item cat-item-4"><a href="http://indiestack.com/category/open-source/" >Open Source</a>
|
||
</li>
|
||
<li class="cat-item cat-item-15"><a href="http://indiestack.com/category/os-x/" >OS X</a>
|
||
</li>
|
||
<li class="cat-item cat-item-19"><a href="http://indiestack.com/category/swift/" >Swift</a>
|
||
</li>
|
||
<li class="cat-item cat-item-22"><a href="http://indiestack.com/category/testing/" >Testing</a>
|
||
</li>
|
||
<li class="cat-item cat-item-25"><a href="http://indiestack.com/category/tips/" >Tips</a>
|
||
</li>
|
||
<li class="cat-item cat-item-20"><a href="http://indiestack.com/category/tvos/" >tvOS</a>
|
||
</li>
|
||
<li class="cat-item cat-item-1"><a href="http://indiestack.com/category/uncategorized/" >Uncategorized</a>
|
||
</li>
|
||
<li class="cat-item cat-item-24"><a href="http://indiestack.com/category/watchos/" >watchOS</a>
|
||
</li>
|
||
<li class="cat-item cat-item-16"><a href="http://indiestack.com/category/webkit/" >WebKit</a>
|
||
</li>
|
||
<li class="cat-item cat-item-13"><a href="http://indiestack.com/category/worfklow/" >Worfklow</a>
|
||
</li>
|
||
<li class="cat-item cat-item-9"><a href="http://indiestack.com/category/workflow/" >Workflow</a>
|
||
</li>
|
||
<li class="cat-item cat-item-7"><a href="http://indiestack.com/category/xcode/" >Xcode</a>
|
||
</li>
|
||
</ul>
|
||
</aside><aside id="meta-2" class="widget widget_meta"><h3 class="widget-title">Meta</h3> <ul>
|
||
<li><a href="http://indiestack.com/wp-login.php">Log in</a></li>
|
||
<li><a href="http://indiestack.com/feed/">Entries <abbr title="Really Simple Syndication">RSS</abbr></a></li>
|
||
<li><a href="http://indiestack.com/comments/feed/">Comments <abbr title="Really Simple Syndication">RSS</abbr></a></li>
|
||
<li><a href="https://wordpress.org/" title="Powered by WordPress, state-of-the-art semantic personal publishing platform.">WordPress.org</a></li> </ul>
|
||
</aside> </div><!-- .widget-area -->
|
||
</div><!-- #secondary -->
|
||
|
||
<div class="site-info">
|
||
<a href="https://wordpress.org/">Proudly powered by WordPress</a>
|
||
</div><!-- .site-info -->
|
||
</footer><!-- #colophon -->
|
||
</div><!-- #page -->
|
||
|
||
<script type='text/javascript' src='http://indiestack.com/wp-includes/js/imagesloaded.min.js?ver=3.2.0'></script>
|
||
<script type='text/javascript' src='http://indiestack.com/wp-includes/js/masonry.min.js?ver=3.3.2'></script>
|
||
<script type='text/javascript' src='http://indiestack.com/wp-includes/js/jquery/jquery.masonry.min.js?ver=3.1.2b'></script>
|
||
<script type='text/javascript' src='http://indiestack.com/wp-content/themes/twentythirteen/js/functions.js?ver=20160717'></script>
|
||
<script type='text/javascript' src='http://indiestack.com/wp-includes/js/wp-embed.min.js?ver=4.8.3'></script>
|
||
<script> jQuery(function($){ $(".widget_meta a[href='http://indiestack.com/comments/feed/']").parent().remove(); }); </script></body>
|
||
</html>
|
||
<!-- Performance optimized by W3 Total Cache. Learn more: https://www.w3-edge.com/products/
|
||
|
||
Page Caching using disk: enhanced
|
||
|
||
Served from: indiestack.com @ 2017-11-25 18:04:31 by W3 Total Cache --> |