<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Cory D. Wiles on Medium]]></title>
        <description><![CDATA[Stories by Cory D. Wiles on Medium]]></description>
        <link>https://medium.com/@kwylez?source=rss-c51df8eee38d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*xx3wzMqZJSREgFELkWkfJQ.jpeg</url>
            <title>Stories by Cory D. Wiles on Medium</title>
            <link>https://medium.com/@kwylez?source=rss-c51df8eee38d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 20:14:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kwylez/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Implementing SensitiveContentAnalysis in SwiftUI]]></title>
            <link>https://kwylez.medium.com/implementing-sensitivecontentanalysis-in-swiftui-f39507f480ac?source=rss-c51df8eee38d------2</link>
            <guid isPermaLink="false">https://medium.com/p/f39507f480ac</guid>
            <category><![CDATA[sensitivecontentanalysis]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Cory D. Wiles]]></dc:creator>
            <pubDate>Wed, 13 Dec 2023 18:53:31 GMT</pubDate>
            <atom:updated>2023-12-13T18:53:31.666Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oNtqN1thaZrZdFAZh5sH7w.png" /></figure><p>With the release of iOS 17 came with it a new framework, SensitiveContentAnalysis, which allows developers, on device, to determine if visual content being presented to the user contains nudity.</p><blockquote>When the framework flags user-provided media as sensitive, intervene by adjusting the user interface in a way that explains the situation and gives the user options to proceed. Avoid displaying flagged content until the user makes a decision.</blockquote><p>With the private messaging app that I’m developing I wanted to leverage this functionality to keep privacy at the forefront, in addition, to the end-to-end encryption.</p><h3><strong>Setup</strong></h3><p><strong>Initialization</strong></p><p>The <strong>first</strong> task is to add the Sensitive Content Analysis <a href="https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_developer_sensitivecontentanalysis_client](https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_developer_sensitivecontentanalysis_client">entitlement</a>: Without this the analyzer will fail.</p><blockquote>Per Apple:<br>The SensitiveContentAnalysis entitlement is not available for Enterprise development or for people with free accounts.</blockquote><p><strong>Detection</strong></p><p>For my app I have a model object called YAIAttachment. The object contains the realitve properties for the type, i.e. Video or Image and the encrypted URL / Media for the resource. I wrote a convience property to determine if the media “isSensitive”.</p><pre>var isSensitive: Bool {<br>        get async throws {<br>            let analyzer: SCSensitivityAnalyzer = .init()<br>            <br>            /// You have to download the asset to the device locally. You can&#39;t load it from a remote URL<br>            /// or the validation won&#39;t work<br>            <br>            let mediaType: MediaTypeCategory = MediaTypeCategory(rawValue: self.mediaType) ?? .standard<br>            let remoteURL: URL = self.isAssetRemote ? self.viewAssetDecryptedURL! : self.asset!.fileURL!<br>            let (data, _) = try await URLSession.shared.data(from: remoteURL)<br>            <br>            if mediaType == .video {<br>                let videoURL: URL = data.yai_fileURL(&quot;mp4&quot;) ?? URL(fileURLWithPath: &quot;&quot;)<br>                let response = analyzer.videoAnalysis(forFileAt: videoURL)<br>                let isSensitive = try await response.hasSensitiveContent().isSensitive<br>                return isSensitive<br>            }<br>            <br>            let imageURL: URL = data.yai_fileURL(&quot;png&quot;) ?? URL(fileURLWithPath: &quot;&quot;)<br>            let response = try await analyzer.analyzeImage(at: imageURL)<br>            return response.isSensitive<br>        }<br>    }</pre><p>There are two important caveats to using the analyzer:</p><ol><li>This is a concurrent operation</li><li>The analyzers for images and videos won’t work if you pass in a remote URL</li></ol><p>As my example shows above, writing an async computed property is pretty straightforward, but it took me a bit to realize the analyzer was failing because the urls I was passing in were remote. To “work around” this was to download the asset, store it locally and pass that temp url to the analyzer.</p><p><strong>What Next</strong></p><p>Now that we have everything setup to determine if the asset is sensitive or not, what do we do about it. The answer is…well…whatever you want. Referring back to Apple’s doc:</p><blockquote>The SensitiveContentAnalysis framework doesn’t dictate your user interface. You can tailor your app’s experience according to the examples in apps such as Messages.</blockquote><p>At first I wasn’t a fan of this and had hoped Apple had provided an OOTB UI, but being able to use a branded UI that fits with my layout and UX made much more sense.</p><pre>    @ViewBuilder<br>    private func sensitiveWarningView(_ attachment: YAIAttachment) -&gt; some View {<br>        if isSensitiveAttachment(attachment) {<br>            VStack(spacing: 10){<br>                Text(&quot;Sensitive Content&quot;)<br>                    .bold()<br>                    .font(.title)<br>                    .fontDesign(.rounded)<br>                HStack(spacing: 5) {<br>                    Image(systemName: &quot;lock.trianglebadge.exclamationmark.fill&quot;)<br>                        .font(.title)<br>                    Text(&quot;Tap to View&quot;)<br>                }<br>            }<br>            .unredacted()<br>            .onTapGesture {<br>                if let recordIndex: Int = self.viewModel.sensitiveAttachments.firstIndex(of: attachment.record.recordID) {<br>                    self.viewModel.sensitiveAttachments.remove(at: recordIndex)<br>                    self.viewModel.visibleSensitiveAttachments.append(attachment.record.recordID)<br>                }<br>            }<br>        }<br>    }<br>        @ViewBuilder<br>    private func standardImageView(_ attachment: YAIAttachment) -&gt;some View {<br>        AsyncImage(url: attachment.viewAssetDecryptedURL!) { phase in<br>            if let image = phase.image {<br>                /// if the image is valid<br>                image<br>                    .resizable()<br>                    .aspectRatio(contentMode: .fit)<br>                    .clipped()<br>                    .overlay(<br>                        sensitiveWarningView(attachment)<br>                    )<br>            } else if phase.error != nil {<br>                /// some kind of error appears<br>                Text(&quot;404! \n No image available 😢&quot;)<br>                    .bold()<br>                    .font(.title)<br>                    .multilineTextAlignment(.center)<br>                <br>            } else {<br>                /// showing progress view as placeholder<br>                ProgressView()<br>                    .font(.largeTitle)<br>            }<br>        }<br>    }</pre><pre>standardImageView(attachment)<br>    .redacted(reason: isSensitiveAttachment(attachment) ? .placeholder : [])<br>    .animation(.easeInOut, value: self.viewModel.sensitiveAttachments.count)<br>    .onTapGesture {<br>  // toggle to remove the warning overlay<br>    }</pre><p>References<br>* <a href="https://developer.apple.com/documentation/sensitivecontentanalysis/scsensitivityanalyzer">SCSensitivityAnalyzer</a><br>* <a href="https://developer.apple.com/documentation/sensitivecontentanalysis/testing-your-app-s-response-to-sensitive-media">Testing your app’s response to sensitive media</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f39507f480ac" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Migrating Swift Combine Publisher / Observable to Observation]]></title>
            <link>https://kwylez.medium.com/migrating-swift-combine-publisher-observable-to-observation-58fa5547ebb6?source=rss-c51df8eee38d------2</link>
            <guid isPermaLink="false">https://medium.com/p/58fa5547ebb6</guid>
            <category><![CDATA[combine]]></category>
            <category><![CDATA[observation]]></category>
            <category><![CDATA[swiftui]]></category>
            <dc:creator><![CDATA[Cory D. Wiles]]></dc:creator>
            <pubDate>Mon, 11 Dec 2023 18:00:52 GMT</pubDate>
            <atom:updated>2023-12-11T18:02:19.049Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AeRK26ZtQKImeMgk0MVv9w.png" /></figure><h3><strong>Overview</strong></h3><p>Apple introduced the new <a href="https://developer.apple.com/documentation/Observation">Observeration framework</a> at <a href="https://developer.apple.com/wwdc23/">WWDC ‘23</a>. This was a welcome addition because it addresses some performance issues found with the <strong>Observable</strong> <strong>framework</strong>: bottlenecks with SwiftUI view updates, the constraint of only being available to NSObject subclasses and finally being able to provide property observations _without_ special annotations.</p><h3><strong>Migration</strong></h3><p>While the migration to using the new <strong>framework</strong> was relatively straightforward. I did find myself running into a few scenarios to which Apple didn’t have a documentation for. This article won’t go into a <a href="https://developer.apple.com/documentation/swiftui/migrating-from-the-observable-object-protocol-to-the-observable-macro">comprehensive tutorial</a>, it will hopefully save other developers wasted hours in compilation errors and headaches.</p><h3><strong>Usage and Migration</strong></h3><p>Simple view model that can be used to determine if input string for a given <a href="https://developer.apple.com/documentation/swiftui/textfield">TextField</a> is valid. To keep it simple, the length just needs to be greater than or equal to 10 characters.</p><pre><br>class TextInputViewModel: ObservableObject {<br><br>@Published<br>var inputText: String = “”<br><br>@Published<br>private (set) var isValid: Bool = false<br><br>private var cancellables: Set&lt;AnyCancellable&gt; = []<br><br>init() {<br>$inputText<br> .debounce(for: 0.15, scheduler: DispatchQueue.main)<br> .removeDuplicates()<br> .map{<br> !$0.count &gt;= 10<br> }<br> .assign(to: \.isValid, on: self)<br> .store(in: &amp;cancellables)<br>}<br>}</pre><p>With the new Observable macro you have to call the publisher explicitedly.</p><pre>@Observable<br>class TextInputViewModel {<br><br>var inputText: String = &quot;&quot;<br><br>private (set) var isValid: Bool = false<br><br>/// @ObservationIgnored won&#39;t observe changes<br>@ObservationIgnored<br>private var cancellables: Set&lt;AnyCancellable&gt; = []<br><br>init() {<br>self.inputText<br>  .publisher<br>  .debounce(for: 0.15, scheduler: DispatchQueue.main)<br>  .removeDuplicates()<br>  .collect()<br>   .map{<br>      !$0.count &gt;= 10<br>   }<br>  .assign(to: \.isValid, on: self)<br>  .store(in: &amp;cancellables)<br>}<br>}</pre><h3><strong>A little bit of a curve ball</strong></h3><p>Lastly, I ran into another issue with the refactor when it came to Bool properties. Using the ObservableObject protocol I could observe the changes directly. For example, let’s say I had a Toggle option in my UI whose binding value came from a view model’s property: didOptIn. Something like…</p><pre>class ViewModel: ObservableObject {<br> @Published<br> var didOptIn: Bool = false<br> <br> @Published<br> private (set) var isValid: Bool = false<br> <br> @Published<br> var email: String = &quot;&quot;<br> <br> init() {<br>   $didOptIn.map {<br>    return $0 &amp;&amp; !email.isEmpty<br>   }<br>   .assign(to: \.isValid, on: self)<br>   .store(in: &amp;cancellables)<br> }<br>}</pre><p>After the migration I got a compile error stating that didOptIn didn’t conform to Publisher. The fix required to have a custom PassthroughSubject property.</p><pre>@Observable<br>class ViewModel {<br> var didOptIn: Bool = false {<br>  didSet {<br>   self.didOptInPublisher.send(didOptIn)<br>  }<br> }<br><br> private (set) var isValid: Bool = false<br><br> var email: String = &quot;&quot;<br> <br> private var didOptInPublisher: PassthroughSubject&lt;Bool, Never&gt; = .init()<br> <br> init() {<br>   $didOptInPublisher.map {<br>    return $0 &amp;&amp; !email.isEmpty<br>   }<br>   .assign(to: \.isValid, on: self)<br>   .store(in: &amp;cancellables)<br> }<br>}</pre><p>Now I’m able to observe changes for didOptIn to perform validation checks.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=58fa5547ebb6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Animating vs Maintaining ScrollPosition on ScrollViewReader]]></title>
            <link>https://kwylez.medium.com/animating-vs-maintaining-scrollposition-on-scrollviewreader-19e1f59259a3?source=rss-c51df8eee38d------2</link>
            <guid isPermaLink="false">https://medium.com/p/19e1f59259a3</guid>
            <category><![CDATA[messaging-apps]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[scrollview]]></category>
            <dc:creator><![CDATA[Cory D. Wiles]]></dc:creator>
            <pubDate>Wed, 28 Dec 2022 15:50:08 GMT</pubDate>
            <atom:updated>2022-12-28T15:50:08.284Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Goal — Just Like iMessage</h3><p>Writing UIKit based functionality in SwiftUI, in my experience, has been so much easier with an almost 1:1 path (emphasis on almost). With the messaging app I’m working on I needed to mimick the UI / UX as seen in iMesssage. When the app finishes loading, load the initial “n” number of messages and scroll to the bottom. If the user scrolls to the top to “load more” then additional messages should be added to the current list <em>but</em> scroll position should be maintained.</p><h4><strong>If You Ain’t First You’re Last</strong></h4><p>Keeping track of the last (latestMessage) is paramount in determining whether / when we scroll.</p><p><strong>Initial Load and “ScrollToBottom”</strong></p><p>Once the main view has appeared and the initial list of messages have been retrieved the list should scroll to the bottom. In our `viewModel` once the list has been set, the `lastMessageId` is assigned to the last item and set the `scrollAnchor` to `bottom`. In the view itself I animate the scroll position based up this value.</p><p><strong>ViewModel</strong></p><pre>self.scrollAnchor = .bottom<br>if let id = self.messages.last?.id {<br> self.lastMessageId = id<br>}</pre><p><strong>View</strong></p><pre>.onChange(of: viewModel.lastMessageId) { id in<br> withAnimation(viewModel.scrollAnchor == .bottom ? .spring() : nil) {<br>  proxy.scrollTo(id, anchor: viewModel.scrollAnchor)<br> }<br>}</pre><p><em>This is the common code block for the change of the lastMessageId. If the anchor is `bottom` then animate, if not then don’t.</em></p><h4><strong>Load More — Maintain Position</strong></h4><p>When the user “pulls to load more” we need to prepend the new messages to the current list, set the combined list to the master list, `self.messages = result`, set the `scrollAnchor` to `top` (which remove the animation of the scroll view when the `lastMessageId` is set) and then set the `lastMessageId` to the last item in the `newMessages` list.</p><p><em>Mission Accomplished</em></p><pre>let currentMessages = self.messages<br>let newMessages: Array&lt;YAIMessage&gt; = messages<br>let combine = [newMessages, currentMessages]<br>let result: Array&lt;YAIMessage&gt; = combine.flatMap{$0}<br><br>self.messages = result<br>self.scrollAnchor = .top<br><br>if let id = newMessages.last?.id {<br>    self.lastMessageId = id<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19e1f59259a3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a Reusable SwiftUI Refreshable ScrollView]]></title>
            <link>https://kwylez.medium.com/creating-a-reusable-swiftui-refreshable-scrollview-4213274ec4f3?source=rss-c51df8eee38d------2</link>
            <guid isPermaLink="false">https://medium.com/p/4213274ec4f3</guid>
            <category><![CDATA[scrollview]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[refreshable]]></category>
            <dc:creator><![CDATA[Cory D. Wiles]]></dc:creator>
            <pubDate>Thu, 08 Dec 2022 18:47:45 GMT</pubDate>
            <atom:updated>2022-12-08T18:47:45.676Z</atom:updated>
            <content:encoded><![CDATA[<p>While rewriting an app for my day job I took the opportunity to standardize <em>most</em> of the view components. The code that was repeated the most was when views were displayed in a ScrollView. Extracing that into a reusable component was straightforward, but I wanted a flexible way to incorporate .refreshable. I didn’t want to have to constantly add that view modifier. Though the app uses MVVM I didn’t want to limit the <strong>refreshable</strong> functionality to just view models, rather more of a hybrid principle of network protocol / datasource.</p><p><em>We usually think of “refreshing” as a network request, but it could also be a local list that has been updated or background task.</em></p><h3>Solution</h3><ol><li>Establish a Refreshable protocol</li><li>Conform a “base” view model to the Refreshable protocol with an empty implementation</li><li>New SwiftUI ViewBuilder that accepts any object that conforms to Refreshable</li></ol><h3>Example View Model Implementation</h3><pre>/// 1. Protocol<br>public protocol Refreshable: AnyObject {<br> func refreshDataModel() -&gt; Void<br>}<br><br>/// 2. BaseViewModel<br>open class BaseViewModel: ObservableObject, Refreshable {<br> <br> @Published<br> public var isLoading: Bool = false<br> <br> @Published<br> public var showError: Bool = false<br> <br> public init(){}<br> <br> open func refreshDataModel() -&gt; Void {}<br>}<br><br>/// 3. RefreshableScrollView (ViewBuilder)<br>public struct RefreshableScrollView&lt;Content: View&gt;: View {<br><br> public let refreshModel: Refreshable?<br> <br> @ViewBuilder<br> let content: Content<br> <br> public init(_ refresh: Refreshable? = nil, @ViewBuilder content: () -&gt; Content) {<br>  self.content = content<br>  self.refreshModel = refresh<br> }<br> <br> public var body: some View {<br>      GeometryReader{ geometry in<br>   VStack(alignment: .leading) {<br>    ScrollView {<br>     VStack {<br>      content<br>     }<br>     .frame(maxWidth: geometry.size.width)<br>    }<br>    .frame(maxWidth: geometry.size.width)<br>    .refreshable{<br>     refreshModel?.refreshDataModel()<br>    }<br>   }<br>  }<br> }<br>}<br><br>/// Standard ContentView<br>struct ContentView: View {<br><br> @StateObject<br> var viewModel: ExampleViewModel = .init()<br><br> var body: some View {<br> <br>  RefreshableScrollView(viewModel){<br>   Text(&quot;Hello world&quot;)<br>  }<br> }<br>}<br><br>/// Example View Model<br>class ExampleViewModel: BaseViewModel {<br><br> func fetchList() -&gt; Void {<br>  /// fetch list of data from webservices<br> }<br><br> override func refreshDataModel() {<br>  super.refreshDataModel()<br>  self.fetchList()<br> }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4213274ec4f3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SwiftUI Custom ViewModifier for Empty Lists]]></title>
            <link>https://kwylez.medium.com/swiftui-custom-viewmodifier-for-empty-lists-634de5a4d375?source=rss-c51df8eee38d------2</link>
            <guid isPermaLink="false">https://medium.com/p/634de5a4d375</guid>
            <category><![CDATA[swiftui-viewmodifier]]></category>
            <dc:creator><![CDATA[Cory D. Wiles]]></dc:creator>
            <pubDate>Fri, 28 Oct 2022 14:13:46 GMT</pubDate>
            <atom:updated>2022-10-28T14:27:01.145Z</atom:updated>
            <content:encoded><![CDATA[<p>It doesn’t matter whether you are writing your i(TV / Mac)OS app in UI(App)Kit or SwiftUI, there will inevitably come a time where you will have an screen that should display a list of objects, but the list is empty. For a personal app that I’m currently building, after a user onboards they are taken to a screen where they can start a conversation with another user…that will be initial <em>empty</em></p><p>Since this is a <strong>SwiftUI</strong> iOS app and writing the logic to display another view that has a CTA or provides the user with a “No messages” message is quite trivial. Something like:</p><pre>@State var dataList: Array&lt;String&gt; = [] // Populate this in onAppear<br>var body: some View {<br>    if dataList.isEmpty {<br>        Text(&quot;No messages)<br>    } else {<br>        List(dataList, id: \.id){data in <br>            Text(&quot;\(data.text)&quot;)<br>        }<br>    }<br>}</pre><p>But we can do better. Something more reusable and elegant without the use conditionals. In addition, the “placeholder” be any View. Thankfully SwiftUI provides us with tools to create a straightforward reusable viewModifer that we can add to any view that will display the placeholder content if the Binding collection is empty and when it is populated should the content. The modifier requires that the data is of any Collection and the placeHolderContent be any View.</p><h4>Custom Modifier</h4><pre>extension View {<br>    func emptyListPlaceHolder&lt;V: Collection, Content: View&gt;(_ data: Binding&lt;V&gt;, @ViewBuilder placeHolderContent: @escaping () -&gt; Content) -&gt; some View {<br>        return self.modifier(EmptyListPlaceHolderViewModifier(data: data, placeHolderContent: placeHolderContent))<br>    }<br>}<br><br>struct EmptyListPlaceHolderViewModifier&lt;V: Collection, P: View&gt;: ViewModifier {<br>    @Binding<br>    var data: V<br>    <br>    @ViewBuilder<br>    var placeHolderContent: () -&gt; P<br>    <br>    func body(content: Content) -&gt; some View {<br>        if !data.isEmpty {<br>             content<br>        } else {<br>            placeHolderContent()<br>        }<br>    }<br>}</pre><h4>Implementation</h4><pre>@State var dataList: Array&lt;String&gt; = [] // Set this in onAppear<br>var body: some View {<br>        List(dataList, id: \.id){data in <br>            Text(&quot;\(data.text)&quot;)<br>        }<br>        .emptyListPlaceHolderView($data) {<br>            Text(&quot;No messages)<br>        }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=634de5a4d375" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fun Times Creating an Inventory App with SwiftUI]]></title>
            <link>https://kwylez.medium.com/fun-times-creating-an-inventory-app-with-swiftui-9f8931d63291?source=rss-c51df8eee38d------2</link>
            <guid isPermaLink="false">https://medium.com/p/9f8931d63291</guid>
            <category><![CDATA[swiftui]]></category>
            <dc:creator><![CDATA[Cory D. Wiles]]></dc:creator>
            <pubDate>Wed, 03 Mar 2021 12:33:24 GMT</pubDate>
            <atom:updated>2021-03-03T12:36:08.906Z</atom:updated>
            <content:encoded><![CDATA[<h3>Down the SwiftUI Rabbit Hole Continues</h3><h4>This is the Way</h4><p>The deeper my dives / experience / experimentations go with SwiftUI the more I appreciate its efficiencies and strides for a better developer experience. Granted, there are still shortcomings when compared to it’s predecessor, <a href="https://developer.apple.com/documentation/uikit">UIKit</a>, the tone / tenor has been set.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L53ayjcUP7wJlX75B82UXA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kcXUbpFR7kI0pV0v6VKKxA.png" /></figure><p>It has been awhile since <a href="https://medium.com/@kwylez/fun-times-creating-a-dashboard-with-swiftui-28b68f1ffb89">my last experiment</a> in “can this be done in SwiftUI?”, and so much as improved since <strong>SwiftUI 2.0</strong> has been released so I set out to recreate <a href="https://dribbble.com/shots/4246962-Getbelonging-An-Inventory-App/attachments/4246962?mode=media">this Inventory App UI</a> by <a href="https://dribbble.com/zulal">Zulal</a>.</p><h4>Customizations</h4><p>Though TabView, has been supported since <strong>SwiftUI 1.0</strong>, I wanted to create an example which utilized a custom view hiearchy for displaying independent views. To add a little “flare” I created a custom extension on Text for displaying the <a href="https://github.com/kwylez/InventoryUI/blob/main/InventoryUI/Modifiers/PaddedTitleText.swift">circle view place holder text</a>. This originally was a custom ViewModifier, but there isn’t a way to constrain the modifier to a particular View.</p><p>There isn’t a straightforward way to determine the dominate color for the product detail image <em>programmatically</em>, so to insure that the overlay text on top of the image would show properly there is a white -&gt; clear gradient on top of the product detail image.</p><p>Lastly, the trash and pencil overlay’s on the detail screen needed to have a slight offset from the bottom of the product image. No need to add an additional overlay or message with <em>another</em> ZStack; just offset the y coordinate and align the overlay to the bottom</p><pre>.offset(y: 20), alignment: .bottom)</pre><p><strong>::NOTE::</strong></p><p><em>I’m not real thrilled with how the masthead image resizing is handled on the </em><em>ProductDetailUIView. I haven’t quite figured out how best to display them without screwing up the rest of the layout</em></p><h4>Onward</h4><p>Whatever the next iteration that Apple announces at WWDC 2021 &gt; SwiftUI 2.0 &gt; SwiftUI 2.0</p><p><a href="https://github.com/kwylez/InventoryUI">Source code</a></p><p><a href="https://i.ytimg.com/vi/vZWS7Xy-5BE/maxresdefault.jpg">This is the way</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9f8931d63291" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fun Times Creating an Inventory App with SwiftUI]]></title>
            <link>https://kwylez.medium.com/fun-times-creating-an-inventory-app-with-swiftui-85ad7722b52b?source=rss-c51df8eee38d------2</link>
            <guid isPermaLink="false">https://medium.com/p/85ad7722b52b</guid>
            <category><![CDATA[swiftui]]></category>
            <dc:creator><![CDATA[Cory D. Wiles]]></dc:creator>
            <pubDate>Wed, 03 Mar 2021 03:43:37 GMT</pubDate>
            <atom:updated>2021-03-03T03:43:37.825Z</atom:updated>
            <content:encoded><![CDATA[<h3>Down the Rabbit Hole Continues</h3><p><strong>This is the Way</strong></p><p>The deeper my dives / experience / experimentations go with SwiftUI the more I appreciate its efficiencies and strides for a better developer experience. Granted, there are still shortcomings when compared to it’s predecessor, <a href="https://developer.apple.com/documentation/uikit">UIKit</a>, the tone / tenor has been set…<a href="https://i.ytimg.com/vi/vZWS7Xy-5BE/maxresdefault.jpg">this is the way</a>.</p><p>It has been awhile since <a href="https://medium.com/@kwylez/fun-times-creating-a-dashboard-with-swiftui-28b68f1ffb89">my last experiment</a> in “can this be done in SwiftUI”, and so much as improved since <strong>SwiftUI 2.0</strong> has been released.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L53ayjcUP7wJlX75B82UXA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kcXUbpFR7kI0pV0v6VKKxA.png" /></figure><p><strong>Customizations</strong></p><p>Though <a href="https://developer.apple.com/documentation/swiftui/tabview">TabView</a>, has been supported since <strong>SwiftUI 1.0</strong>, I wanted to create an example which utilized a custom view hiearchy for displaying independent views. To add a little “flar” I created a custom extension on `Text` for displaying the <a href="https://github.com/kwylez/InventoryUI/blob/main/InventoryUI/Modifiers/PaddedTitleText.swift">circle view place holder text</a>. This originally was a custom ```ViewModifier```, but there isn’t a way to constrain the modifier to a particular View.</p><p>There isn’t a straightforward way to determine the dominate color for the product detail image <em>programmatically</em>, so to insure that the overlay text on top of the image would show properly there is a `white -&gt; clear` gradient on top of the product detail image.</p><p>Lastly, the ```trash``` and ```pencil``` overlay’s on the detail screen needed to have a slight offset from the bottom of the product image. No need to add an additional overlay or message with <em>another</em> ```ZStack```; just offset the ```y coordinate``` and align the overlay to the `bottom`</p><p>```…<br>.offset(y: 20), alignment: .bottom)<br>```</p><p><strong>::NOTE::</strong></p><p>I’m not real thrilled with how the masthead image resizing is handled on the ```ProductDetailUIView```. I haven’t quite figured out how best to display them without screwing up the rest of the layout*</p><h3><strong>Onward</strong></h3><p>```SwiftUI 1.0``` &lt; ```SwiftUI 2.0``` &lt; <em>Whatever the next iteration that Apple announces at WWDC 2021.</em></p><p><a href="https://i.ytimg.com/vi/vZWS7Xy-5BE/maxresdefault.jpg">This is the way</a></p><p><a href="https://github.com/kwylez/InventoryUI">Source</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=85ad7722b52b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Combine for Synchronous Permissions Requests on iOS]]></title>
            <link>https://kwylez.medium.com/using-combine-for-synchronous-permissions-requests-on-ios-c77a3e639dc7?source=rss-c51df8eee38d------2</link>
            <guid isPermaLink="false">https://medium.com/p/c77a3e639dc7</guid>
            <category><![CDATA[combine]]></category>
            <dc:creator><![CDATA[Cory D. Wiles]]></dc:creator>
            <pubDate>Tue, 05 Jan 2021 21:12:51 GMT</pubDate>
            <atom:updated>2021-01-05T21:12:51.644Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Days of Future Past</h3><h4>Syncing and Grouping Requests</h4><p>Pre iOS 13 if one wanted to run <em>and sync</em> a group of asynchronous requests they had their choice of the following:</p><ul><li><a href="https://developer.apple.com/documentation/dispatch/dispatchsemaphore">DispatchSemaphore</a></li><li><a href="https://developer.apple.com/documentation/dispatch/dispatchgroup">DispatchGroup</a></li><li><a href="https://www.appcoda.com/ios-concurrency/">NSOperation / NSOperationQueue</a></li></ul><p>While each of these techniques provide <strong>very</strong> powerful versitality, implementing thread-safe, edgecase / error proof code, in many instances, isn’t trivial. Most of the examples, tutorials and uses cases showing how to sync multiple asynchronous “operations” fell under the category of <em>networking</em>.</p><p>While it is true that grouping network requests is an extremely common task, a just as common, yet rarely discussed, task is the grouping of <strong>required</strong> requested system permissions, i.e. Microphone and SpeechRecognizer. For example, the <a href="https://github.com/spokestack/spokestack-tray-ios">SpokestackTray</a> that I wrote, would be completely useless without having access to <strong>both</strong> the user’s microphone and speech recognition.</p><h4>Combining It All Together</h4><p>With iOS 13 came the new <a href="https://developer.apple.com/documentation/combine">Combine framework</a>. Within <strong>Combine</strong> comes our friend: <a href="https://developer.apple.com/documentation/combine/future">Future</a></p><blockquote>A publisher that eventually produces a single value and then finishes or fails.</blockquote><p><strong>Futures</strong> are great for handling asynchronous requests in a “synchronous” way without getting into queue management or callback hell. In my case, having heterogenous method signatures makes using Future the best approach for solving my problem.</p><p>I wrapped this into a simple class in case I needed to add more permissions.</p><p><a href="https://github.com/spokestack/spokestack-tray-ios/blob/master/SpokestackTray/Controllers/Permissions.swift">Permissions.swift</a></p><pre>let permission = Permission()<br>let _ = permission.hasGrantedPermissions<br>    .sink(receiveCompletion: {completion in<br>    <br>        switch completion {<br>        case .finished:<br>            print(&quot;finished in completion&quot;)<br>            break<br>        case .failure(let error):<br>            print(&quot;error \(error) in completion&quot;)<br>            break<br>        }<br>    <br>    }, receiveValue: {hasGranted in<br>        print(&quot;hasGranted \(hasGranted)&quot;)<br>    })</pre><p>If you wanted to change the state of a class based upon the permission result then you could so something like</p><pre>class ViewController: UIViewController {<br>    <br>    var isReady = false {<br>        didSet {<br>            someHiddenView.isHidden = !isReady<br>        }<br>    }<br>    <br>    override func viewDidLoad() {<br>        super.viewDidLoad()<br>        self.checkForPermissions()<br>    }<br>    <br>    func checkForPermissions() {<br>        <br>        let permission = Permission()<br>        <br>        let _ = permission.hasGrantedPermissions<br>            .replaceError(with: false)<br>            .assign(to: \.isReady, on: self)<br>    }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c77a3e639dc7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fun Times Creating an Email Client with SwiftUI]]></title>
            <link>https://kwylez.medium.com/fun-times-creating-an-email-client-with-swiftui-e5533863192b?source=rss-c51df8eee38d------2</link>
            <guid isPermaLink="false">https://medium.com/p/e5533863192b</guid>
            <category><![CDATA[macos]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[swiftui]]></category>
            <dc:creator><![CDATA[Cory D. Wiles]]></dc:creator>
            <pubDate>Tue, 24 Mar 2020 12:44:38 GMT</pubDate>
            <atom:updated>2020-03-24T12:44:38.999Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>The Same, but Different</strong></h3><p>In order to “round out” my <strong>SwiftUI</strong> journey I decided to create a <a href="https://github.com/kwylez/EmailUI">MacOS email prototype</a>. The differences between this project and the <a href="https://github.com/kwylez/bankingui">BankingUI</a> / <a href="https://github.com/kwylez/dashboardui">DashboardUI</a> where <strong>much</strong> less than I thought. Though this is just a prototype and not a full fledge, it gave me an insight as to the different mindset(s) and consideration(s) for building a MacOS app vs an iOS / iPad.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2hOU5f5hVwLyNOFt98cdMQ.png" /><figcaption>EmailUI Prototype</figcaption></figure><h3><strong>Lacking (time)</strong></h3><p>I wanted to add in a bit more functionality, but my main hustle and updates to <a href="https://significantotherapp.com/">Significant Other</a> have been up taking most of my time.</p><h3><strong>The Future</strong></h3><p>Now that I have created and <a href="https://github.com/kwylez/BankingUI">iPhone</a>, <a href="https://github.com/kwylez/DashboardUI">iPad</a> and <a href="https://github.com/kwylez/EmailUI">MacOS</a> prototypes, my predication of “SwiftUI as the future” is even higher. AppKit, much like UIKit, isn’t / shouldn’t go away, but <a href="https://developer.apple.com/xcode/swiftui/">SwiftUI</a> bridges the framework and paradigm gap between Apple’s platforms.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e5533863192b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Significant Other 2.1 Released]]></title>
            <link>https://kwylez.medium.com/significant-other-2-1-released-2b051fda0dd5?source=rss-c51df8eee38d------2</link>
            <guid isPermaLink="false">https://medium.com/p/2b051fda0dd5</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[significant-other]]></category>
            <dc:creator><![CDATA[Cory D. Wiles]]></dc:creator>
            <pubDate>Thu, 19 Mar 2020 21:32:39 GMT</pubDate>
            <atom:updated>2020-03-19T21:32:39.690Z</atom:updated>
            <content:encoded><![CDATA[<p>Back in September I had planned to have <strong>2.1</strong> released by Christmas, unfortunately due to deadlines from my day job and a few other side hustles I didn’t get around the updates I wanted until a month ago.</p><p>But alas, it is <a href="https://itunes.apple.com/us/app/significant-other/id1069132961?ls=1&amp;mt=8">here</a>.</p><h3><strong>Dark Mode</strong></h3><p><a href="https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/dark-mode/">Dark Mode</a> arrived last September to much fan fair and while it was on the top of my priority list of features to add to <strong>Significant Other</strong> time took its tool, but now that <strong>2.1</strong> has been released I couldn’t be happier with the results.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*R_samJx1auNF-wt1cCiYWQ.png" /></figure><h3><strong>Videos</strong></h3><p>Up until now videos were limited 30 seconds and filmed within the app. Now you can film or <strong>upload</strong> videos up to <strong>3 mins</strong>.</p><h3><strong>Gallery</strong></h3><p>The gallery overhaul was a last minute decision. I had on my list a few display bugs to knock out, but as I got into the work I got frustated with the layout and lack privacy…not cool. Significant Other aims to be the most private couples based app. Not only should the user be able to see all of their images, but videos well. In regards to privacy I added a blurred view that defaults to when the view is loaded so that wondering eyes don’t catch a glimpse media.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*Eup3IZhVd_BFUlOdR1DtUg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*tIqp0xNgzoNh9kUqoLGLwg.png" /></figure><h3><strong>Significant Other 2.2</strong></h3><p>The main push for this upcoming release is to make onboarding even easier. Currently, in order to “discover” users who have installed the app, the user has to grant <a href="https://developer.apple.com/documentation/cloudkit/ckcontainer_application_permissions/1399176-userdiscoverability">discoverability permission</a> and unfortunately Apple doesn’t make this the most usable experience. Thanks to <a href="https://davedelong.com/">Dave DeLong</a> and <a href="https://joeblau.com/">Joe Blau</a> for providing the inspiration for the implementation of a better onboarding experience. Users will still have the option to search for their Significant Other via phone or email, BUT username will be the preferred method.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2b051fda0dd5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>