<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Blogs on Robert Harrison</title>
    <link>https://robertharrison.ca/blog/</link>
    <description>Recent content in Blogs on Robert Harrison</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <lastBuildDate>Fri, 18 Jul 2025 18:00:00 -0700</lastBuildDate>
    <atom:link href="https://robertharrison.ca/blog/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Swift tip: Properly deprecating code</title>
      <link>https://robertharrison.ca/blog/swift-deprecating-code/</link>
      <pubDate>Fri, 18 Jul 2025 18:00:00 -0700</pubDate>
      <guid>https://robertharrison.ca/blog/swift-deprecating-code/</guid>
      <description>&lt;p&gt;As codebases evolve, we inevitably accumulate functions, classes, and APIs that need to be removed or replaced. Use &lt;code&gt;@available(*, deprecated, message: &amp;quot;...&amp;quot;)&lt;/code&gt; to mark functions as deprecated in your Swift projects:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;@available(*, deprecated, message: &amp;#34;This function will be removed in a future release.&amp;#34;)&#xA;func oldFunction() {&#xA;    // legacy code&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This gives developers, including your future self, a clear heads-up about upcoming changes while keeping code functional during the transition period. The compiler will show warnings but won&amp;rsquo;t break existing builds.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Swift Singleton with @unchecked Sendable</title>
      <link>https://robertharrison.ca/blog/swift-singleton-with-unchecked-sendable/</link>
      <pubDate>Sat, 01 Mar 2025 14:35:00 -0700</pubDate>
      <guid>https://robertharrison.ca/blog/swift-singleton-with-unchecked-sendable/</guid>
      <description>&lt;p&gt;A &lt;strong&gt;singleton&lt;/strong&gt; is a design pattern that ensures there is only one instance of a class. While convenient, there are drawbacks to using singletons, which are well documented elsewhere. Swift 6 provides some approaches to replacing Singletons, such as Actor. Sometimes, you run into a situation, such as re-using legacy code, where using a Singleton is preferable over refactoring to modern Swift techniques.&lt;/p&gt;&#xA;&lt;p&gt;Pre-Swift 6, a singleton could be written like so:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Performance of SwiftUI Views with Conditional Branching</title>
      <link>https://robertharrison.ca/blog/swiftui-conditional-branching-performance/</link>
      <pubDate>Fri, 22 Nov 2024 13:03:00 -0700</pubDate>
      <guid>https://robertharrison.ca/blog/swiftui-conditional-branching-performance/</guid>
      <description>&lt;p&gt;Improve the performance of your SwiftUI views by replacing &lt;strong&gt;if-else&lt;/strong&gt; and &lt;strong&gt;switch&lt;/strong&gt; statements with the &lt;strong&gt;ternary&lt;/strong&gt; operator. &lt;/p&gt;&#xA;&lt;p&gt;To illustrate the issue, let’s start with the following code that uses an if-else statement to set the foreground color of an image:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;struct ContentView: View {&#xA;    @State private var isFavorite = true&#xA;&#xA;    var body: some View {&#xA;        if isFavorite {&#xA;            Image(systemName: &amp;#34;star.fill&amp;#34;)&#xA;                .foregroundStyle(Color.yellow)&#xA;        } else {&#xA;            Image(systemName: &amp;#34;star.fill&amp;#34;)&#xA;                .foregroundStyle(Color.black)&#xA;        }&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The above code has two issues. First, there is some duplicate code. Second, toggling &lt;strong&gt;isFavorite&lt;/strong&gt; between true and false causes SwiftUI to tear down and recreate the entire view. SwiftUI treats the if-else paths as separate Views and will do extra work to process the if and else paths. The same performance issue occurs with switch statements.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Voice Cloning using Tortoise-TTS on Apple Silicon</title>
      <link>https://robertharrison.ca/blog/voice-cloning-tortoise-tts-apple-silicon/</link>
      <pubDate>Sun, 17 Nov 2024 14:48:00 -0700</pubDate>
      <guid>https://robertharrison.ca/blog/voice-cloning-tortoise-tts-apple-silicon/</guid>
      <description>&lt;p&gt;Voice cloning is a process that uses AI to replicate a person&amp;rsquo;s voice. The AI is trained on audio samples of a person&amp;rsquo;s voice to learn their speaking patterns. Once trained, the AI can generate speech that sounds like the original person.&lt;/p&gt;&#xA;&lt;p&gt;Here are five practical uses of voice cloning:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Digital Assistants.&lt;/li&gt;&#xA;&lt;li&gt;Helping people with speech disabilities.&lt;/li&gt;&#xA;&lt;li&gt;Voiceovers in different languages.&lt;/li&gt;&#xA;&lt;li&gt;Aid in voice acting for TV, film, commercials, and video games.&lt;/li&gt;&#xA;&lt;li&gt;Interactive educational content.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;There is a lot of power that comes with using voice cloning technology. Please use it responsibly.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Organize Code with Local Swift Packages</title>
      <link>https://robertharrison.ca/blog/organize-code-local-swift-packages/</link>
      <pubDate>Wed, 25 Sep 2024 09:17:00 -0700</pubDate>
      <guid>https://robertharrison.ca/blog/organize-code-local-swift-packages/</guid>
      <description>&lt;p&gt;There are several benefits to organizing your code into modules:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Readability&lt;/li&gt;&#xA;&lt;li&gt;Testability&lt;/li&gt;&#xA;&lt;li&gt;Reusability&lt;/li&gt;&#xA;&lt;li&gt;Maintainability&lt;/li&gt;&#xA;&lt;li&gt;And more &amp;hellip;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;By using an Xcode Workspace and Swift Packages, a monolithic project can be split up and organized, into smaller modules or packages. Utilities, for example, can go in one package, and the Data Layer can go in another package.&lt;/p&gt;&#xA;&lt;p&gt;Swift Packages can be local or remote. If the module can be used by other projects or teams, then consider using a &lt;strong&gt;remote&lt;/strong&gt; package. In which case, the remote package will require its own git repository. If the module is only usable by the main application, then use a &lt;strong&gt;local&lt;/strong&gt; package. The local package will live within the git repository of the main application. In this article, we’re going to use a &lt;strong&gt;local&lt;/strong&gt; package.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Manage Multiple Projects with an Xcode Workspace</title>
      <link>https://robertharrison.ca/blog/manage-multiple-projects-xcode-workspace/</link>
      <pubDate>Mon, 23 Sep 2024 15:38:00 -0700</pubDate>
      <guid>https://robertharrison.ca/blog/manage-multiple-projects-xcode-workspace/</guid>
      <description>&lt;p&gt;By default, Xcode projects use an &lt;code&gt;.xcodeproj&lt;/code&gt; file to organize and structure the project. The project file contains code, resources, settings and targets for building a product.&lt;/p&gt;&#xA;&lt;p&gt;What if your project needs to reference another project? For example, prior to building your main app, you must first compile and link a library. Use an &lt;strong&gt;Xcode Workspace&lt;/strong&gt; (&lt;code&gt;.xcworkspace&lt;/code&gt;) to manage the dependencies between multiple projects. Xcode can use the workspace to compile the library first, then link it to your app. If your project uses &lt;a href=&#34;https://cocoapods.org&#34;  class=&#34;external-link&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Cocoapods&lt;/a&gt;, then it’s using a Workspace.&lt;/p&gt;</description>
    </item>
    <item>
      <title>SwiftUI Toggle</title>
      <link>https://robertharrison.ca/blog/swiftui-toggle/</link>
      <pubDate>Tue, 22 Feb 2022 11:53:00 -0800</pubDate>
      <guid>https://robertharrison.ca/blog/swiftui-toggle/</guid>
      <description>&lt;p&gt;This article describes how to use the SwiftUI &lt;a href=&#34;https://developer.apple.com/documentation/swiftui/toggle&#34;  class=&#34;external-link&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Toggle&lt;/a&gt;. By the end of the article you will have learned how to embed Toggle in a child View and perform the Toggle&amp;rsquo;s action in a parent View.&lt;/p&gt;&#xA;&lt;p&gt;Let&amp;rsquo;s start with the basics. Here is a variation of the example in the official &lt;a href=&#34;https://developer.apple.com/documentation/swiftui/toggle&#34;  class=&#34;external-link&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;documentation&lt;/a&gt;:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;@State private var faceIdEnabled = false&#xA;var body: some View {&#xA;    Toggle(isOn: $faceIdEnabled) {&#xA;        Text(&amp;#34;Face ID&amp;#34;)&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The above code will show a toggle control with &amp;ldquo;Face ID&amp;rdquo; for the title. By using a two-way binding on &lt;strong&gt;faceIdEnabled&lt;/strong&gt;, we control if the toggle is on or off.&lt;/p&gt;</description>
    </item>
    <item>
      <title>How to read data from BigQuery using Firebase Functions</title>
      <link>https://robertharrison.ca/blog/bigquery-firebase-functions-read-data/</link>
      <pubDate>Thu, 27 Jan 2022 09:00:00 -0800</pubDate>
      <guid>https://robertharrison.ca/blog/bigquery-firebase-functions-read-data/</guid>
      <description>&lt;p&gt;An alternative title to this article could have been, &amp;ldquo;How to Access BigQuery from iOS&amp;rdquo;. I&amp;rsquo;m working on a SwiftUI app that needs to read data from BigQuery. There are several &lt;a href=&#34;https://cloud.google.com/bigquery/docs/reference/libraries&#34;  class=&#34;external-link&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;BigQuery API Client Libraries&lt;/a&gt;, but none are in Swift or Objective-C. There is a Node.js library. My SwiftUI app happens to use Firebase, which supports hosting Node.js code. So the decision is easy. I&amp;rsquo;ll use Node.js and Firebase.&lt;/p&gt;&#xA;&lt;p&gt;&lt;em&gt;A different approach could use the &lt;a href=&#34;https://cloud.google.com/bigquery/docs/reference/rest&#34;  class=&#34;external-link&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;BigQuery REST API&lt;/a&gt;. There are couple of reasons why I chose to take the Node.js/Firebase Functions approach. (1) using a pre-built library can make development easier/quicker (2) In my use case, I want to do some data processing on the results, which makes sense to do on the backend, before returning to the frontend.&lt;/em&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>Unit Test CLLocationManager with a Mock</title>
      <link>https://robertharrison.ca/blog/unit-test-cllocationmanager-with-mock/</link>
      <pubDate>Mon, 10 Jun 2019 14:47:00 -0800</pubDate>
      <guid>https://robertharrison.ca/blog/unit-test-cllocationmanager-with-mock/</guid>
      <description>&lt;p&gt;In this article, I’ll describe how to mock &lt;code&gt;CLLocationManager&lt;/code&gt;, so it can be used in unit tests.&lt;/p&gt;&#xA;&lt;p&gt;Imagine that you are building a fitness app. To track the user’s running distance, you use &lt;code&gt;CLLocationManager&lt;/code&gt;. Instances of &lt;code&gt;CLLocationManager&lt;/code&gt; are used to configure, start and stop Core Location services in your app.&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;CLLocationManager&lt;/code&gt; has some characteristics, which make it not very friendly to unit test. For example, calling &lt;code&gt;CLLocationManager.authorizationStatus()&lt;/code&gt; for the first time will trigger a request for user authorization to be displayed. A unit test that is dependent on that call will fail.&lt;/p&gt;</description>
    </item>
    <item>
      <title>8 Tips for Migrating a Salesforce Mobile SDK Project from Objective-C to Swift</title>
      <link>https://robertharrison.ca/blog/migrating-salesforce-mobile-sdk-objc-swift/</link>
      <pubDate>Fri, 26 Apr 2019 14:43:00 -0800</pubDate>
      <guid>https://robertharrison.ca/blog/migrating-salesforce-mobile-sdk-objc-swift/</guid>
      <description>&lt;p&gt;Recently, I migrated parts of an iOS app from Objective-C to Swift. The app is for checking in attendees at events and uses the &lt;a href=&#34;https://github.com/forcedotcom/SalesforceMobileSDK-iOS&#34;  class=&#34;external-link&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Salesforce Mobile SDK&lt;/a&gt;.  I would like to share with you, some things I learned from the migration to Swift and updating to the latest Salesforce Mobile SDK.&lt;/p&gt;&#xA;&lt;p&gt;First, the reasons (some are subjective) why I migrated parts of the app from Objective-C to Swift.&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;The existing Objective-C code base contained a lot of &lt;a href=&#34;https://en.wikipedia.org/wiki/Technical_debt&#34;  class=&#34;external-link&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;technical debt&lt;/a&gt;.&lt;/li&gt;&#xA;&lt;li&gt;Salesforce Mobile SDK, which the app is tightly integrate with, is moving to Swift.&lt;/li&gt;&#xA;&lt;li&gt;Swift is a joy to write.&lt;/li&gt;&#xA;&lt;li&gt;Swift is easier to read.&lt;/li&gt;&#xA;&lt;li&gt;Swift is safer to use.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;h3 id=&#34;tip-1&#34;&gt;&#xA;  Tip 1&#xA;  &lt;a class=&#34;heading-link&#34; href=&#34;#tip-1&#34;&gt;&#xA;    &lt;i class=&#34;fa-solid fa-link&#34; aria-hidden=&#34;true&#34; title=&#34;Link to heading&#34;&gt;&lt;/i&gt;&#xA;    &lt;span class=&#34;sr-only&#34;&gt;Link to heading&lt;/span&gt;&#xA;  &lt;/a&gt;&#xA;&lt;/h3&gt;&#xA;&lt;p&gt;Before you migrate to Swift, update your Objective-C code to modern syntax and practices. Xcode can really help you, by suggesting changes or making the changes automatically.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Salesforce Einstein ChatBot Development Process</title>
      <link>https://robertharrison.ca/blog/salesforce-einstein-chatbot/</link>
      <pubDate>Mon, 25 Mar 2019 14:08:00 -0800</pubDate>
      <guid>https://robertharrison.ca/blog/salesforce-einstein-chatbot/</guid>
      <description>&lt;p&gt;On March 5, 2019, I participated in a &lt;a href=&#34;https://salesforce.org&#34;  class=&#34;external-link&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Salesforce.org&lt;/a&gt; ChatBot Hackathon at &lt;a href=&#34;https://www.csueastbay.edu/&#34;  class=&#34;external-link&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;California State University East Bay&lt;/a&gt;. There were participants from all over the Cal State University system, as well as the &lt;a href=&#34;https://www.sandiego.edu/&#34;  class=&#34;external-link&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;University of San Diego&lt;/a&gt;, which I and a colleague represented. The main objective of the event was to create intents and utterances that could be shared within the Higher-Ed community. The secondary objective was to create a chatbot using &lt;a href=&#34;https://www.salesforce.com/products/einstein/overview/&#34;  class=&#34;external-link&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Salesforce Einstein&lt;/a&gt;.  It was great to see the chatbots that all the groups had created. I was really impressed!&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
