{
    "version": "https://jsonfeed.org/version/1",
    "user_comment": "This feed allows you to read the posts from this site in any feed reader that supports the JSON Feed format. To add this feed to your reader, copy the following URL -- https://indiestack.com/feed/json/ -- and add it your reader.",
    "home_page_url": "https://indiestack.com",
    "feed_url": "https://indiestack.com/feed/json/",
    "title": "Indie Stack",
    "description": "Hacking the Mac, iOS, and more with Daniel Jalkut",
    "items": [
        {
            "id": "https://indiestack.com/2025/11/attach-to-multiple-processes/",
            "url": "https://indiestack.com/2025/11/attach-to-multiple-processes/",
            "title": "Attach to Multiple Processes",
            "content_html": "<p>For the vast majority of developers of software for Apple products, the process (har, har) of debugging involves attaching to and inspecting only one process: the main application binary. This is particularly true on iOS-based systems, where spawning subprocesses is not allowed, and arbitrary XPC services are limited. But developers of &#8220;app extensions&#8221;, a specialized form of XPC service, may well need to attach to at least two processes.</p>\n<p>Mac developers, on the other hand, are more likely to encounter situations where attaching to multiple subprocesss is either necessary or very convenient. In particular, the use of custom XPC services allows a Mac app to subdivide the work it performs into separate components that run with potentially different security entitlements from the main application.</p>\n<p>For these scenarios, Xcode provides a handy checkbox that can be used to automatically attach when one of an app&#8217;s XPC services is launched. Look deep in the &#8220;Options&#8221; tab of the scheme editor&#8217;s &#8220;Run Action&#8221; page:</p>\n<p><img decoding=\"async\" src=\"https://indiestack.com/wp-content/uploads/2025/11/DebugXPC.png\" alt=\"Screenshot of a checkbox labeled &quot;Debug XPC services used by app&quot;\" title=\"DebugXPC.png\" style=\"border: 1px solid;\" width=\"284\" height=\"35\" /></p>\n<p>This is handy, for example, if you need to attach to components of the open source Sparkle project, which uses XPC services to compartmentalize some parts of the software update process. Here, Xcode automatically attached to the service that handles relaunching the freshly-updated application:</p>\n<p><img fetchpriority=\"high\" decoding=\"async\" src=\"https://indiestack.com/wp-content/uploads/2025/11/InstallerLauncher.png\" alt=\"Screenshot of Xcode&#39;s debug interface listing processes that are being debugged. It shows the main app, named MarsEdit, and a secondary process from the Sparkle library called &quot;org.sparkle-project.InstallerLauncher&quot;.\" title=\"InstallerLauncher.png\" border=\"0\" width=\"448\" height=\"383\" /></p>\n<p>While this feature is great for XPC services in particular, there are many caveats. For example, Xcode will not automatically attach to XPC services that you didn&#8217;t build yourself. So, while an app that uses WebKit will employ many XPC services for accessing network resources or rendering web page content, Xcode will not attach to those processes automatically unless you built the WebKit project locally and are running against that version.</p>\n<p>Another shortcoming of Xcode&#8217;s default behavior is that it will only attach to XPC processes specifically. If your app spawns other subprocesses that are not XPC services, you have to laboriously ask it to attach to your process by name or by process ID. My app <a href=\"https://redsweater.com/fastscripts/\">FastScripts</a>, an AppleScript utility, uses subprocesses to run scripts in isolation, both for resilience against crashing scripts, and to accommodate running an arbitrary number of scripts in parallel. When I&#8217;m debugging an issue in the subprocess, named &#8220;RSScriptRunner&#8221; in my debug builds, I have to manually select the &#8220;Debug -> Attach to Process by PID or Name&#8221; menu item, and type in &#8220;RSScriptRunner&#8221;:</p>\n<p><img decoding=\"async\" src=\"https://indiestack.com/wp-content/uploads/2025/11/AttachToProcess.png\" alt=\"Screenshot of Xcode&#39;s &quot;Attach to Process by PID or Name&quot; panel. It shows the name of the process requested to attach to, along with other debugging options to apply.\" title=\"AttachToProcess.png\" border=\"0\" width=\"592\" height=\"323\" /></p>\n<p>But here I run into another unfortunate limitation of Xcode&#8217;s attachment functionality: Xcode only attaches to the first named process it finds. FastScripts always keeps <em>at least</em> two RSScriptRunner processes going, so that when a script is invoked there will always be a process &#8220;primed and ready&#8221;. When several scripts are running in parallel, several RSScriptRunner processes are running. How do I attach to the one I care about debugging?</p>\n<p>The solution I&#8217;ve come up with is to <em>attach to them all</em>. I&#8217;ve created an AppleScript that determines the process identifiers for every running process of a given name, and asks Xcode to attach to each one. I invoke the script (from FastScripts, but any scripting utility would work), type in the name &#8220;RSScriptRunner&#8221;, and Xcode attaches to each and every one of them:</p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https://indiestack.com/wp-content/uploads/2025/11/RSScriptRunnerDebug.png\" alt=\"Screenshot of Xcode&#39;s process debugging list, showing the main app, &quot;FastScripts&quot;, and two instances of the &quot;RSScriptRunner&quot; process all being debugged at the same time.\" title=\"RSScriptRunnerDebug.png\" border=\"0\" width=\"310\" height=\"405\" /></p>\n<p>I&#8217;ve clipped this screenshot to save space, but there are four instances of RSScriptRunner that Xcode has attached to in this example. Once you&#8217;ve attached to any number of processes in Xcode, any breakpoints you set will fire when <em>any of the processes</em> reaches them.</p>\n<p>You can <a href=\"https://indiestack.com/wp-content/uploads/2025/11/AttachToProcesses.zip\">download the script directly</a>, or copy and paste from this text into your favorite script editor: </p>\n<p><code></p>\n<pre>set processName to text returned of (display dialog \"Enter process name:\" default answer \"\")\n\nset processIDs to {}\ntell application \"System Events\"\n    set processIDs to unix id of every process whose name is processName\nend tell\n\ntell application \"Xcode\"\n    repeat with processID in processIDs\n        tell workspace document 1\n            attach to process identifier processID without suspended\n        end tell\n    end repeat\nend tell</pre>\n<p></code></p>\n<p>Ideally, I would love for Xcode to expand its &#8220;Debug XPC Processes&#8221; option so that it attaches automatically to any child process created by an app, or perhaps any child process matching a particular regular expression. In the meantime, I hope this script helps some of you manage debugging your multiprocess apps!</p>\n",
            "date_published": "2025-11-17T18:03:20-05:00",
            "date_modified": "2025-11-17T18:43:40-05:00",
            "author": {
                "name": "Daniel Jalkut"
            }
        },
        {
            "id": "https://indiestack.com/2023/10/conditional-xcode-build-settings/",
            "url": "https://indiestack.com/2023/10/conditional-xcode-build-settings/",
            "title": "Conditional Xcode Build Settings",
            "content_html": "<p>In <a href=\"https://indiestack.com/2023/10/xcode-15-duplicate-library-linker-warnings/\">the previous post</a>, I described a problematic warning introduced by the new linker in Xcode 15. In it, I shared that the warning can be effectively disabled by passing a suitable argument to the linker:</p>\n<p><code></code></p>\n<pre>OTHER_LDFLAGS = -Wl,-no_warn_duplicate_libraries\n</pre>\n<p><code></code></p>\n<p>This simple declaration will address the problem on Xcode 15, but on Xcode 14 and earlier it will cause a link error because the old linker doesn\u2019t recognize the argument. What we want to do if the project will continue to be built by both older and newer versions of Xcode, is to effectively derive a different value for <span class=\"keyword\">OTHER_LDFLAGS</span> depending on the version of Xcode itself. (Maybe more correctly, depending on the version of the linker, but for this example we\u2019ll focus on varying based on Xcode version).</p>\n<p>There\u2019s no straightforward way to avoid this problem, but Xcode build settings offer a sophisticated (albeit brain-bendingly obtuse) mechanism for varying the value of a build setting based on arbitrary conditions. Technically this technique could be used in Xcode\u2019s build settings editor, but because of the complexity of variable definitions, it\u2019s a lot easier (not to mention easier to manage with source control) if you declare such settings in an <a href=\"https://developer.apple.com/documentation/xcode/adding-a-build-configuration-file-to-your-project\">Xcode configuration file</a>. The examples below will use the declarative format used by these files.</p>\n<p>The key to applying this technique is understanding that build settings can themselves be defined in terms of other build settings. For example:</p>\n<p><code></code></p>\n<pre>OTHER_LDFLAGS = $(SUPPRESS_WARNING_FLAGS)\nSUPPRESS_WARNING_FLAGS = -Wl,-no_warn_duplicate_libraries\n</pre>\n<p><code></code></p>\n<p>These configuration directives have the same effect as the single-line definition above, because Xcode expands the <span class=\"keyword\">SUPPRESS_WARNING_FLAGS</span> setting and uses the result when setting the value of <span class=\"keyword\">OTHER_LDFLAGS</span>. Even more powerfully, you can nest build settings so that the <em>value</em> of one build setting is used to construct the <em>name</em> of another:</p>\n<p><code></code></p>\n<pre>SHOULD_SUPPRESS = YES\nOTHER_LDFLAGS = <span class=\"math\">\\((SUPPRESS_WARNING_FLAGS_\\)</span>(SHOULD_SUPPRESS))\nSUPPRESS_WARNING_FLAGS_YES = -Wl,-no_warn_duplicate_libraries\n</pre>\n<p><code></code></p>\n<p>Here, the final value for <span class=\"keyword\">OTHER_LD_FLAGS</span> will only include the specified flags if the <span class=\"keyword\">SHOULD_SUPPRESS</span> build setting is YES, because expanding <span class=\"keyword\">SHOULD_SUPPRESS</span> yields the build setting <span class=\"keyword\">SUPPRESS_WARNING_FLAGS_YES</span>. If <span class=\"keyword\">SHOULD_SUPPRESS</span> is NO, or any other value, then the expansion will lead to an undefined build setting, and thus will substitute an empty value.</p>\n<p>Side note: when editing Xcode configuration files, keep one editor pane open to the configuration file, and one pane open to the Xcode build settings interface, focused on a project or target that depends on the configuration file. As you edit and save the file, Xcode updates the derived build settings in real time so you can check your work. For example, if you were to change the value of <span class=\"keyword\">SHOULD_SUPPRESS</span> to NO, you would see the \u201cOther Linker Flags\u201d value change to empty in Xcode.</p>\n<p>Obviously, hard-coding <span class=\"keyword\">SHOULD_SUPPRESS</span> to YES as we did above isn\u2019t going to solve the problem, because these configuration settings will cause the incompatible linker parameter to be passed on Xcode 14 and earlier.</p>\n<p>The simple ability to nest build settings leads to a huge variety of clever tricks that allow you to impose a kind of declarative logic to settings. For example, here\u2019s a cool technique I learned from the <a href=\"https://github.com/WebKit/WebKit/blob/3ecd348bfff2f43d4ed087211eb8b3a56816f072/Configurations/SDKVariant.xcconfig\">WebKit project</a>:</p>\n<p><code></code></p>\n<pre>NOT_ = YES\nNOT_NO = YES\nNOT_YES = NO\n</pre>\n<p><code></code></p>\n<p><span class=\"keyword\">NOT_</span> equals YES? What does it meeeeaaan? It only makes since when you consider what happens when you combine <span class=\"keyword\">NOT_</span> with another build setting that is defined as a boolean value:</p>\n<p><code></code></p>\n<pre>SHOULDNT_SUPPRESS = <span class=\"math\">\\((NOT_\\)</span>(SHOULD_SUPPRESS))\n</pre>\n<p><code></code></p>\n<p>This expands to $(<span class=\"keyword\">NOT_YES</span>) which in turn expands to NO. You can make sense of these exotic uses of nested build settings by slowly walking through the expansion, from the inside out. Each time you expand the contents of a $() construct, you end up with text that combines with the adjacent text to yield either a new build setting name, or the final value for a setting.</p>\n<p>Finally, let\u2019s apply a similar trick to the question of whether we\u2019re running Xcode 15 or later. For this I am also leaning on an example I found in the WebKit sources. By declaring boolean values for several Xcode version tests:</p>\n<p><code></code></p>\n<pre>XCODE_BEFORE_15_1300 = YES\nXCODE_BEFORE_15_1400 = YES\nXCODE_BEFORE_15_1500 = NO\n</pre>\n<p><code></code></p>\n<p>We lay the groundwork for expanding a build setting based on the <span class=\"keyword\">XCODE_VERSION_MAJOR</span> build setting, which is built in:</p>\n<p><code></code></p>\n<pre>XCODE_BEFORE_15 = <span class=\"math\">\\((XCODE_BEFORE_15_\\)</span>(XCODE_VERSION_MAJOR))\nXCODE_AT_LEAST_15 = <span class=\"math\">\\((NOT_\\)</span>(XCODE_BEFORE_15))\n</pre>\n<p><code></code></p>\n<p>In this case, on my Mac running Xcode 15.1, <span class=\"keyword\">XCODE_BEFORE_15</span> expands to <span class=\"keyword\">XCODE_BEFORE_15_1500</span>, which expands to NO. <span class=\"keyword\">XCODE_AT_LEAST_15</span> uses the aforementioned <span class=\"keyword\">NOT_</span> setting, expanding to <span class=\"keyword\">NOT_NO</span>, which expands to YES.</p>\n<p>Easy, right?</p>\n<p>Putting it all together, we can return to the original example with <span class=\"keyword\">SHOULD_SUPPRESS</span>, and replace it with the more dynamic <span class=\"keyword\">XCODE_AT_LEAST_15</span>:</p>\n<p><code></code></p>\n<pre>OTHER_LDFLAGS = <span class=\"math\">\\((SUPPRESS_WARNING_FLAGS_\\)</span>(XCODE_AT_LEAST_15))\nSUPPRESS_WARNING_FLAGS_YES = -Wl,-no_warn_duplicate_libraries\n</pre>\n<p><code></code></p>\n<p><span class=\"keyword\">OTHER_LDFLAGS</span> expands to <span class=\"keyword\">SUPPRESS_WARNING_FLAGS_YES</span> on my Mac running Xcode 15.1, but on any version of Xcode 14 or earlier, it will expand to <span class=\"keyword\">SUPPRESS_WARNING_FLAGS_NO</span>, which expands to an empty value. No harm done.</p>\n<p>I hope you have enjoyed this somewhat elaborate journey through the powerful but difficult to grok world of nested build settings, and how they can be used to impose rudimentary logic to whichever settings require such finessing in your projects.</p>\n",
            "date_published": "2023-10-04T11:51:31-04:00",
            "date_modified": "2023-12-05T00:18:16-05:00",
            "author": {
                "name": "Daniel Jalkut"
            }
        },
        {
            "id": "https://indiestack.com/2023/10/xcode-15-duplicate-library-linker-warnings/",
            "url": "https://indiestack.com/2023/10/xcode-15-duplicate-library-linker-warnings/",
            "title": "Xcode 15 Duplicate Library Linker Warnings",
            "content_html": "<p>Apple released Xcode 15 a couple weeks ago, after debuting the beta at WWDC in June, and shipping several beta updates over the summer.</p>\n<p>I&#8217;ve been using the betas on my main work machine, and for months I&#8217;ve been mildly annoyed by warnings such as these:</p>\n<p><p><code></p>\n<pre>ld: warning: ignoring duplicate libraries: &apos;-lc++&apos;\nld: warning: ignoring duplicate libraries: &apos;-lz&apos;\nld: warning: ignoring duplicate libraries: &apos;-lxml2&apos;\nld: warning: ignoring duplicate libraries: &apos;-lsqlite3&apos;\n</pre>\n<p></code></p>\n</p>\n<p>You may have run into similar warnings with other libraries, but warnings about these libraries in particular seem to be very widespread among developers. Even though I&#8217;ve been seeing them all summer, and have been annoyed by them, I made the same mistake I often make: assuming that the problem was too obvious <em>not to be fixed</em> before Xcode 15 went public. Alas.</p>\n<p>So what happened in Xcode 15 to make these suddenly appear, and why haven&#8217;t they gone away? The root of the problem is not new. Something about the way Xcode infers library linkage dependencies has, for several years at least, led it to count dependencies from Swift packages separately from each package, and to subsequently pass the pertinent &#8220;-l&#8221; parameter to the linker redundantly for each such dependency. In other words, if you have three Swift packages that each require &#8220;-lc++&#8221;, Xcode generates a linker line that literally passes &#8220;-lc++ -lc++ -lc++&#8221; to the linker.</p>\n<p>So why have the warnings only appeared now? One of the major changes in Xcode 15 was the introduction of a &#8220;completely rewritten linker&#8221;, which has been mostly transparent to me, but which was also to blame for an issue with Xcode 15 that prevented some apps from launching on older macOS (10.12) and iOS (14) systems. That bug has been addressed in the <a href=\"https://developer.apple.com/documentation/xcode-release-notes/xcode-15_1-release-notes\">Xcode 15.1 beta 1 release</a>, which was released this week.</p>\n<p>Another change in the new linker was the introduction of a new warning flag, on by default: &#8220;-warn_duplicate_libraries&#8221;. Kinda obvious, isn&#8217;t it? It&#8217;s the new warning flag on the linker that is leading this old Xcode behavior to suddenly start spewing unwanted warnings.</p>\n<h3>Suppressing the Warnings</h3>\n<p>Luckily, in conjunction with the new warning flag, the linker also introduced a negating flag: &#8220;-no_warn_duplicate_libraries&#8221;. If you pass this flag to the linker, the warnings go away. When Xcode links your target, it actually invokes &#8220;clang&#8221;, which in turn invokes the linker (&#8220;ld&#8221;). So to see that the flag gets passed down to the lower lever linker, you need to specify it as a parameter to clang that instructs it to propagate the parameter to ld:</p>\n<p><p><code></p>\n<pre>\nOTHER_LDFLAGS = -Wl,-no_warn_duplicate_libraries\n</pre>\n<p></code></p>\n</p>\n<p><span class=\"keyword\">OTHER_LDFLAGS</span> is the raw name for the build setting that appears in Xcode as &#8220;Other Linker Flags&#8221;. The excerpt above is in the text-based <a href=\"https://developer.apple.com/documentation/xcode/adding-a-build-configuration-file-to-your-project\">Xcode configuration file</a> (.xcconfig) format. You could also just paste the &#8220;-Wl,-no_warn_duplicate_libraries&#8221; argument into the Xcode build settings for your target, but generally speaking, using Xcode configuration files is better.</p>\n<h3>Supporting Multiple Xcode Versions</h3>\n<p>One problem with pasting the <span class=\"keyword\">OTHER_LDFLAGS</span> value in to Xcode&#8217;s build settings, is you won&#8217;t be able to build the project on Xcode 14 or earlier. Maybe that is OK, but if like me, you use an older version of Xcode on your build machine (or your dedicated continuous integration service does), you&#8217;ll run into a build error when the older linker fails to recognize the new option:</p>\n<p><p><code></p>\n<pre>\nld: unknown option: -no_warn_duplicate_libraries\n</pre>\n<p></code></p>\n</p>\n<p>So how can we suppress the warnings while using Xcode 15, while continuing to build without errors on older versions of Xcode? Xcode configuration files to the rescue! Because of the general utility of the method used to conditionalize build settings based on Xcode version, I have written a separate blog post describing this technique. Read <a href=\"https://indiestack.com/2023/10/conditional-xcode-build-settings/\">Conditional Xcode Build Settings</a> to learn more.</p>\n<h3>Addressing the Underlying Issue</h3>\n<p>I&#8217;m not going to fret too much about disabling the &#8220;warn_duplicate_libraries&#8221; option on the linker, because I don&#8217;t foresee it protecting me from many real-world pitfalls. However, all else being equal I would leave the warning on, because you never know.</p>\n<p>I filed FB13229994 with a sample project demonstrating the problem. Hopefully at some point in the future Apple will update Xcode so that it effectively removes duplicated library names from its list of derived dependencies, alleviating the problem and allowing the warning to be enabled again.</p>\n",
            "date_published": "2023-10-04T11:50:53-04:00",
            "date_modified": "2023-10-04T14:46:27-04:00",
            "author": {
                "name": "Daniel Jalkut"
            }
        },
        {
            "id": "https://indiestack.com/2023/06/view-clipping-sonoma/",
            "url": "https://indiestack.com/2023/06/view-clipping-sonoma/",
            "title": "View Clipping Changes in macOS 14 Sonoma",
            "content_html": "<p>One of the most impactful changes to AppKit in the forthcoming macOS 14 Sonoma update is a change to the default clipping behavior for views. Apple announced that a long-present internal property, &#8220;clipsToBounds&#8221;, is now public. In tandem with this change, they are changing the default value for this property to <em>false</em> for apps that link against the macOS 14 SDK.</p>\n<p>What does it mean for a view to &#8220;clip to bounds&#8221;? It simply means that no matter what the view does, it will not succeed in drawing outside its own bounds. This sounds like a reasonable thing, but it has historically been a headache for views with shadowed borders, for example, or views that render text that might extend slightly outside the bounds of the view.</p>\n<p>Apple acknowledges in the <a href=\"https://developer.apple.com/documentation/macos-release-notes/appkit-release-notes-for-macos-14#NSView\">AppKit Release Notes</a> that this change will pose problems for some custom views. One example has to do with the &#8220;drawRect:&#8221; method and the value of the &#8220;dirtyRect&#8221; parameter:</p>\n<blockquote><p>\nFilling the dirty rect of a view inside of -drawRect. A fairly common pattern is to simply rect fill the dirty rect passed into an override of NSView.draw(). The dirty rect can now extend outside of your view\u2019s bounds.\n</p></blockquote>\n<p>I ran up against this with my own app, <a href=\"https://redsweater.com/marsedit/\">MarsEdit</a>, where I noticed the date editor panel was missing the &#8220;OK&#8221; button:</p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https://indiestack.com/wp-content/uploads/2023/06/CalendarClipping.png\" alt=\"CalendarClipping\" title=\"CalendarClipping.png\" border=\"0\" width=\"342\" height=\"406\" /></p>\n<p>What&#8217;s happening here is my custom calendar view is filling the &#8220;dirtyRect&#8221; with its background color before continuing to draw the rest of its content. Unfortunately, what Apple promised in the excerpt above has come to pass: the dirtyRect encompasses nearly the entire window! So when my calendar view redraws, it is evidently overwriting the &#8220;OK&#8221; button, as well as a date picker that is supposed to appear below the calendar.</p>\n<p>The fix is relatively simple in this case: because I don&#8217;t anticipate the view being very large, and filling a rect is a pretty cheap operation, I simply changed it to fill &#8220;self.bounds&#8221; instead of &#8220;dirtyRect&#8221;.</p>\n<p>Filling the dirty rect is such a pervasive pattern that I expect many apps will see problems like this. It also seems odd that views such as mine are being passed such a large dirtyRect. It makes me wonder if, during the beta testing phase, Apple is intentionally passing extra-large dirty rects to views, to expose issues like this.</p>\n<p>The takeaway is you probably want to do a global search in your projects for &#8220;dirtyRect&#8221; and evaluate whether the pertinent code in each case assumes the rect is constrained to your view&#8217;s bounds. As soon as you start compiling and linking against the macOS 14 SDK, it won&#8217;t be.</p>\n",
            "date_published": "2023-06-27T10:18:40-04:00",
            "date_modified": "2023-06-27T11:41:17-04:00",
            "author": {
                "name": "Daniel Jalkut"
            }
        },
        {
            "id": "https://indiestack.com/2023/06/xcode-build-script-sandboxing/",
            "url": "https://indiestack.com/2023/06/xcode-build-script-sandboxing/",
            "title": "Xcode Build Script Sandboxing",
            "content_html": "<p>Apple added a new build setting to Xcode last year, ENABLE_USER_SCRIPT_SANDBOXING, which controls whether any &#8220;Run Script&#8221; build phases will be run in a sandbox or not. From the <a href=\"https://developer.apple.com/documentation/xcode-release-notes/xcode-14-release-notes\">Xcode 14 Release Notes</a>:</p>\n<blockquote><p>\nYou can now enable sandboxing for shell script build phases using the ENABLE_USER_SCRIPT_SANDBOXING build setting. Sandboxing blocks access to files inside the source root of the project as well as the Derived Data directory unless you list those files as inputs or outputs. When enabled, the build fails with a sandbox violation if a script phase attempts to read from or write to an undeclared dependency, preventing incorrect builds.\n</p></blockquote>\n<p>If I noticed it last year I had already forgotten about it, but I was reminded today while putting together a sample app to demonstrate a bug I was reporting. How was I reminded? Because evidently, starting in Xcode 15, the build setting now defaults to YES. I had added a custom Run Script phase to my project in order to finesse the contents of the built product, but when the script ran I was greeted with this error:</p>\n<blockquote><p>\nerror: Sandbox: cp(25322) deny(1) file-read-data /Users/daniel/Project/File.txt\n</p></blockquote>\n<p>Luckily when I searched the build settings for the word &#8220;sandbox&#8221; it turned up the setting, and I was able to turn it off. If you run into this with your projects, it sounds like a better fix is to specify the specific input and output files so that the script phase is allowed access only to the files you think it should be working with.</p>\n",
            "date_published": "2023-06-11T16:41:03-04:00",
            "date_modified": "2023-06-11T16:41:03-04:00",
            "author": {
                "name": "Daniel Jalkut"
            }
        },
        {
            "id": "https://indiestack.com/2023/04/magic-loading-property-wrappers/",
            "url": "https://indiestack.com/2023/04/magic-loading-property-wrappers/",
            "title": "Magic Loading Property Wrappers",
            "content_html": "<p>tldr: <a href=\"https://github.com/danielpunkass/MagicLoading\">MagicLoading</a> is a reference implementation of a @ViewLoading-style property wrapper.</p>\n<p>I hadn&#8217;t really paid too close attention to Swift&#8217;s <a href=\"https://github.com/apple/swift-evolution/blob/main/proposals/0258-property-wrappers.md\">property wrapper features</a> until my curiosity was piqued earlier this year by Apple&#8217;s introduction of some very interesting wrappers designed to work with <a href=\"https://developer.apple.com/documentation/uikit/uiviewcontroller/viewloading\">UIViewController</a>, <a href=\"https://developer.apple.com/documentation/appkit/nsviewcontroller/viewloading\">NSViewController</a>, and <a href=\"https://developer.apple.com/documentation/appkit/nswindowcontroller/windowloading\">NSWindowController</a>. The aim in each case is to address this vexing situation:</p>\n<p><code></p>\n<pre>\n// Will be non-nil after loadView\nvar important: Thingy! = nil\n</pre>\n<p></code></p>\n<p>By wrapping in such a way that guarantees the <em>view will get loaded</em> if you access the property:</p>\n<p><code></p>\n<pre>\n@ViewLoading var important: Thingy\n</pre>\n<p></code></p>\n<p>Anybody who has done substantial work on iOS or Mac platforms can appreciate how helpful this is, to convert an otherwise fragile implicitly unwrapped optional into a totally predictable non-optional property. Apple&#8217;s new property wrappers make this possible by essentially rewriting the &#8220;important&#8221; property with boiler-plate code that first loads the view if needed, and then returns the underlying wrapped value. As Apple says in their documentation, this stands to prove particularly useful for @IBOutlet properties, which can all be converted to using this mechanism.</p>\n<p>Unfortunately, Apple&#8217;s new property wrappers are only available for pretty recent deployment targets: iOS 16.4 and macOS 13.3. I am excited to start using these, but I still need to deploy to earlier targets. So I set out to re-implement something similar on my own.</p>\n<p>The magic in Apple&#8217;s wrappers is an under-documented but widely used alternative mechanism for property wrappers: the ability to define getters and setters with knowledge of the containing object&#8217;s type, and access to the specific instance. The &#8220;subscript&#8221; variant of property wrappers is described in the <a href=\"https://github.com/apple/swift-evolution/blob/main/proposals/0258-property-wrappers.md\">original proposal</a>, but has never been publicly endorsed, as far as I know, by Apple or the Swift team.</p>\n<p>Usually I would shy away from undocumented features, but in this situation I believe it&#8217;s safe to use the undocumented subscript functionality because doing so only instructs the compiler to generate wrapper code that is compiled into the resulting binary. In other words: there are no private runtime dependencies that are being assumed by opting into this more sophisticated form of property wrapper. It&#8217;s just a way of getting the Swift compiler to write the pertinent code for us.</p>\n<p>There are <a href=\"https://www.swiftbysundell.com/articles/accessing-a-swift-property-wrappers-enclosing-instance/\">plenty of tutorials</a> about how to use these subscript-based property wrappers, but I thought it would be useful to share a reference implementation that boils it down to how you might write one of these @ViewLoading style property wrappers yourself. <a href=\"https://github.com/danielpunkass/MagicLoading\">MagicLoading</a> is a GitHub repository that aims to do that. It implements only one such wrapper: MagicViewLoading, which is intended to replicate UIViewController.ViewLoading.</p>\n<p>For my own purposes, I&#8217;d like to add other wrappers to handle the NSWindowController and NSViewController cases, but I&#8217;m also a little annoyed by the prospect of having to replicate that ugly &#8220;subscript&#8221; code everywhere. I was curious about whether I could somehow factor out the subscript wrapper and allow other wrappers to be declared by just providing the &#8220;getter logic&#8221; and &#8220;setter logic&#8221;.</p>\n<p>I made a few attempts at declaring a more generic property wrapper that exposed var properties for getting and setting, but I ran into issues figuring out how to declare concrete types that could take advantage of the more general wrapper without introducing complexity at the property declaration site. If anybody has clever ideas about how to approach that, I&#8217;d love to be able to have @MagicLoading be a property wrapper type that other wrappers could inherit from or compose in some way.</p>\n",
            "date_published": "2023-04-17T12:49:33-04:00",
            "date_modified": "2023-04-18T01:29:12-04:00",
            "author": {
                "name": "Daniel Jalkut"
            }
        },
        {
            "id": "https://indiestack.com/2023/01/inline-applescript-documentation/",
            "url": "https://indiestack.com/2023/01/inline-applescript-documentation/",
            "title": "Inline AppleScript Documentation",
            "content_html": "<p>While perusing Xcode&#8217;s AppleScript scripting dictionary, I was surprised to discover a rather robust &#8220;example code&#8221; section included right there among the usually spartan reference of the app&#8217;s scriptable entities:</p>\n<p><img decoding=\"async\" style=\"display:block; margin-left:auto; margin-right:auto;\" src=\"https://indiestack.com/wp-content/uploads/2023/01/XcodeBuildCommand.png\" alt=\"Screenshot of Xcode&#39;s scripting dictionary, including a section with example script code for the &#39;build&#39; command\" title=\"XcodeBuildCommand.png\" border=\"0\" width=\"500\" /></p>\n<p>Curious to learn more, I used a relatively little-known trick for examining the raw source code of a scripting dictionary. Simply click and drag from Script Editor&#8217;s document proxy icon, into a text editor such as TextEdit, Xcode, or <a href=\"https://www.barebones.com/products/bbedit/index.html\">BBEdit</a>:</p>\n<p><img decoding=\"async\" style=\"display:block; margin-left:auto; margin-right:auto;\" src=\"https://indiestack.com/wp-content/uploads/2023/01/DragProxyScriptEditor.png\" alt=\"Screenshot of Script Editor window for a scripting dictionary, with annotations to show where the document proxy icon is\" title=\"DragProxyScriptEditor.png\" border=\"0\" width=\"500\" /></p>\n<p>This trick is especially handy because even if the app in question <em>doesn&#8217;t have</em> a standard scripting definition (.sdef) file representing its interface, Script Editor will generate one dynamically for you. It&#8217;s a quick-and-dirty way to learn how specific outcomes are achieved, and how you might incorporate similar features in your own app&#8217;s scripting definition file. In this case, I discovered a new (to me) &#8220;documentation&#8221; element in the file:</p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"display:block; margin-left:auto; margin-right:auto;\" src=\"https://indiestack.com/wp-content/uploads/2023/01/DocumentationElementXcode.png\" alt=\"Screenshot of source code reflecting the example script inline documentation pictured above\" title=\"DocumentationElementXcode.png\" border=\"0\" width=\"500\" height=\"133\" /></p>\n<p>I was not aware of the feature until a few weeks ago, but apparently it&#8217;s been there since at least Mac OS 10.5. <a href=\"https://latenightsw.com\">Script Debugger</a> supports it, too! You can read more about the &#8220;documentation&#8221; element by invoking &#8220;man 5 sdef&#8221; from the Terminal:</p>\n<blockquote><p>When an element needs more exposition than a simple \u2018description\u2019 attribute can provide, use a documentation element.  A documentation element may contain any number of html elements, which contain text that will be displayed at that point in the dictionary.</p></blockquote>\n<p>Given the sad state of support for AppleScript by Apple, and the continued low level of adoption by 3rd-party developers, a feature like this will probably never be widely used or celebrated. But at least in <a href=\"https://redsweater.com//fastscripts/\">FastScripts</a> 3.2.4, which I just released this morning, I&#8217;m now taking advantage of it:</p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"display:block; margin-left:auto; margin-right:auto;\" src=\"https://indiestack.com/wp-content/uploads/2023/01/SearchTextDictionary.png\" alt=\"Screenshot showing FastScripts &#39;search text&#39; command with an inline documentation block\" title=\"SearchTextDictionary.png\" border=\"0\" width=\"500\" height=\"179\" /></p>\n<p>If you&#8217;re among the few remaining Mac developers who is investing time and effort into your AppleScript scripting definitions, hopefully you&#8217;ll find this feature useful!</p>\n",
            "date_published": "2023-01-02T11:15:37-05:00",
            "date_modified": "2023-01-02T11:32:05-05:00",
            "author": {
                "name": "Daniel Jalkut"
            }
        },
        {
            "id": "https://indiestack.com/2022/11/opting-out-of-textkit2-in-nstextview/",
            "url": "https://indiestack.com/2022/11/opting-out-of-textkit2-in-nstextview/",
            "title": "Opting Out of TextKit&nbsp;2 in NSTextView",
            "content_html": "<p>Starting in macOS 13 Ventura, Apple is automatically opting-in most NSTextView instances to use TextKit&nbsp;2, a modern replacement for the traditional NSLayoutManager based text system that has been part of Mac OS X since its debut.</p>\n<p>This change may bring a variety of surprises, so it&#8217;s important to test carefully if you use NSTextView. Somewhat unintuitively, you are more likely to be affected by the changes <em>if you do little customization</em> of the default NSTextView behavior.</p>\n<p>Apple explained the new opt-in behavior and some of the consequences in the 2022 WWDC session titled <a href=\"https://developer.apple.com/videos/play/wwdc2022-10090/?time=557\">&#8220;What&#8217;s New in TextKit and text views&#8221;</a>. They also explain that the decision to use TextKit&nbsp;2 can be explicitly opted out of:</p>\n<blockquote>\n<p>When you explicitly call an NSLayoutManager API, the text view replaces its NSTextLayoutManager with an NSLayoutManager and reconfigures itself to use TextKit&nbsp;1.</p>\n</blockquote>\n<p>Perhaps the biggest risk for malfunction lies in scenarios where some significant customization is expected to work, but not in a way that affects the text view&#8217;s decision to carry on using TextKit&nbsp;2. One such example is when it comes to customizing the drawing of the insertion point cursor. Since &#8220;the dawn of time&#8221; Apple has offered an overridable method on NSTextView:</p>\n<pre>open func drawInsertionPoint(in rect: NSRect, color: NSColor, turnedOn flag: Bool)\n</pre>\n<p>A custom NSTextView subclass that thinks it can do better than Apple&#8217;s default text-colored vertical bar can override the method to impose its own dubious design choices:</p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https://indiestack.com/wp-content/uploads/2022/11/RedGreenCaret.png\" alt=\"Screenshot of text editor text with an insertion point colored red and green\" title=\"RedGreenCaret.png\" style=\"border:2px solid #CCC;\" width=\"121\" height=\"38\" /></p>\n<p>By default, starting in macOS 13 Ventura, the above customization will fail, because it is evidently not supported by TextKit&nbsp;2. The simple workaround, for the time being anyway, is to force your text view to use TextKit&nbsp;1. As explained in the WWDC excerpt above, this is as simple as asking it once for its layout manager, which will cause it to rebuild its entire text architecture to suit the TextKit&nbsp;1 way of functioning:</p>\n<pre>\nlet _ = myTextView.layoutManager\n</pre>\n<p>I&#8217;ve filed FB11771261 with Apple, requesting that the functionality either be restored, or the method in question be overtly documented as non-functioning.</p>\n<p><strong>Update:</strong> The insertion point behavior described here is among many other bugs documented on Marcin Krzyzanowski&#8217;s <a href=\"https://github.com/krzyzanowskim/STTextView\">STTextView project on GitHub</a>. Looks like a good resource for folks who are curious about possible issues, and possibly a good alternative to NSTextView until/unless Apple fixes NSTextView to be more functional in TextKit 2 mode. Thanks to <a href=\"https://agiletortoise.com\">Greg Pierce</a> for the link.</p>\n",
            "date_published": "2022-11-09T09:57:02-05:00",
            "date_modified": "2022-11-09T10:43:09-05:00",
            "author": {
                "name": "Daniel Jalkut"
            }
        },
        {
            "id": "https://indiestack.com/2022/04/designing-macos-menu-bar-extras/",
            "url": "https://indiestack.com/2022/04/designing-macos-menu-bar-extras/",
            "title": "Designing macOS Menu Bar Extras",
            "content_html": "<p>A great article by Marc Edwards, essentially the <a href=\"https://bjango.com/articles/designingmenubarextras/\">&#8220;missing manual&#8221;</a> for macOS menu bar extras: </p>\n<blockquote><p>Apple\u2019s HIG is great, but it doesn\u2018t contain much information related to designing menu bar extras. This article aims to provide additional details and context needed to create icons for macOS menu bar extras.</p></blockquote>\n<p>There are a lot of subtleties to get right, and this will help you if you are unfamiliar with the conventions!</p>\n",
            "date_published": "2022-04-26T10:00:19-04:00",
            "date_modified": "2022-04-26T10:00:34-04:00",
            "author": {
                "name": "Daniel Jalkut"
            }
        },
        {
            "id": "https://indiestack.com/2022/03/quieting-cvdisplaylink-logging/",
            "url": "https://indiestack.com/2022/03/quieting-cvdisplaylink-logging/",
            "title": "Quieting CVDisplayLink Logging",
            "content_html": "<p>In recent months I&#8217;ve noticed an accumulation of garbage log messages when I&#8217;m debugging an app in Xcode. Line after line along the lines of:</p>\n<pre>\n[] [0x124858a00] CVDisplayLinkStart\n[] [0x124858a20] CVDisplayLink::start\n[] [0x600003c3cee0] CVXTime::reset\n</pre>\n<p>Today I went digging to find the source of these log messages, and in the process I discovered a workaround that disables them. Just pass &#8220;-cv_note 0&#8221; as a parameter to the Run task in the Xcode scheme. Alternatively, you could disable them across all of your apps by setting this global default:</p>\n<pre>\ndefaults write com.apple.corevideo cv_note 0\n</pre>\n<p>The only downside to disabling the messages globally is that you will have to remember you disabled it if you ever decide you <em>want</em> to see massive quantities of Core Video debugging logs!</p>\n<p>I discovered this user default by spelunking the system frameworks code from which they originate. After setting a breakpoint early in my app&#8217;s launch, I set a breakpoint on a variety of logging related methods until I discovered that these messages are all originating from a function called cv_note() in the CoreVideo framework. Within that function, there is a call to another function called &#8220;cv_note_init_logging_once&#8221;, and within that is a check for a user default value along with this tasty morsel:</p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https://indiestack.com/wp-content/uploads/2022/03/ThanksForSettingCVNote.png\" alt=\"Screenshot of Xcode disassembly showing a log message: Thanks for setting defaults write com.apple.corevideo cv_note -int %d\" title=\"ThanksForSettingCVNote.png\" border=\"0\" width=\"730\" height=\"93\" /></p>\n<p>And thank you, Apple, for providing such a mechanism, even if it&#8217;s unfortunately configured to log by default. I filed FB9960090: &#8220;CoreVideo logging should default to 0&#8221;, requesting that Apple change the behavior of this initialization function so that if a user <em>has not</em> set the cv_note value to anything particular, it defaults to 0.</p>\n",
            "date_published": "2022-03-17T10:08:19-04:00",
            "date_modified": "2022-03-17T10:08:19-04:00",
            "author": {
                "name": "Daniel Jalkut"
            }
        }
    ]
}