<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Xcode14-1 on dev.endevour</title><link>https://devendevour.iankulin.com/tags/xcode14-1/</link><description>Recent content in Xcode14-1 on dev.endevour</description><generator>Hugo</generator><language>en-AU</language><lastBuildDate>Sun, 11 Dec 2022 00:00:00 +0000</lastBuildDate><atom:link href="https://devendevour.iankulin.com/tags/xcode14-1/index.xml" rel="self" type="application/rss+xml"/><item><title>ChatGPT's code writing</title><link>https://devendevour.iankulin.com/chatgpts-code-writing/</link><pubDate>Sun, 11 Dec 2022 00:00:00 +0000</pubDate><guid>https://devendevour.iankulin.com/chatgpts-code-writing/</guid><description>&lt;p&gt;&lt;img src="https://devendevour.iankulin.com/images/22.jpg" alt="room full of monkeys typing at computers - stable diffusion" class="img-responsive"&gt; &lt;/p&gt;
&lt;p&gt;This week, the internet has been all about &lt;a href="https://chat.openai.com/chat" target="_blank" rel="noopener"&gt;ChatGPT&lt;/a&gt; , the rather remarkable natural language AI with a very large model. If you&amp;rsquo;re a twitter user, you were probably amazed, but now eventually tired of seeing examples of it&amp;rsquo;s output. I&amp;rsquo;ll add to that with an example of a SwifUI CoreData based todo app it wrote for me from a single sentence prompt below. Rather than look at other people&amp;rsquo;s examples you should definitely go and play with it yourself - it is very impressive. Along with the image based AI&amp;rsquo;s it&amp;rsquo;s made 2022 into a historical year for AI.&lt;/p&gt;</description></item><item><title>Sharing is caring</title><link>https://devendevour.iankulin.com/sharing-is-caring/</link><pubDate>Sat, 10 Dec 2022 00:00:00 +0000</pubDate><guid>https://devendevour.iankulin.com/sharing-is-caring/</guid><description>&lt;p&gt;Continuing on with the demo project from yesterday, in which we used the ImageRenderer class to turn a view into an image, today we want to let the user share it somehow.&lt;/p&gt;
&lt;p&gt;Typically, apps have a button using the square.and.arrow.up SF Symbol to share something from the current screen. It&amp;rsquo;s probably not an accident that it&amp;rsquo;s literally the first symbol in the app.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devendevour.iankulin.com/images/screen-shot-2022-12-05-at-9.23.33-pm.png" alt="" class="img-responsive"&gt; &lt;/p&gt;
&lt;p&gt;Pressing it generally opens the &amp;ldquo;share sheet&amp;rdquo; which has options for opening whatever is being shared in another app, printing it, saving it to photos, or whatever.&lt;/p&gt;</description></item><item><title>Clean code</title><link>https://devendevour.iankulin.com/clean-code/</link><pubDate>Fri, 09 Dec 2022 00:00:00 +0000</pubDate><guid>https://devendevour.iankulin.com/clean-code/</guid><description>&lt;p&gt;&lt;img src="https://devendevour.iankulin.com/images/young-woman-cleaning-a-computer-painting.jpg" alt="young woman cleaning a computer, painting - stable diffusion" class="img-responsive"&gt; &lt;/p&gt;
&lt;p&gt;I&amp;rsquo;ve been listening to the &lt;a href="https://www.youtube.com/watch?v=YVrHPCZnC50" target="_blank" rel="noopener"&gt;latest episode of the Empower Apps&lt;/a&gt; podcast, this one with &lt;a href="https://twitter.com/Jilsco9" target="_blank" rel="noopener"&gt;Jill Scott&lt;/a&gt; talking about &amp;ldquo;Humane&amp;rdquo; development - in the sense of being humane to whoever (probably you) is going to be reading this code in the future. It helped me clarify my thoughts about a couple of things.&lt;/p&gt;
&lt;p&gt;None of these ideas are particularly new or groundbreaking, and although I think of them as my personal style, they are very common, and in Swift could be regarded as part of the culture. Some of these concepts support each other, some represent a trade off between two opposing ideas that require us to make a choice.&lt;/p&gt;</description></item><item><title>ImageRenderer()</title><link>https://devendevour.iankulin.com/imagerenderer/</link><pubDate>Thu, 08 Dec 2022 00:00:00 +0000</pubDate><guid>https://devendevour.iankulin.com/imagerenderer/</guid><description>&lt;p&gt;&lt;a href="https://developer.apple.com/documentation/swiftui/imagerenderer" target="_blank" rel="noopener"&gt;ImageRenderer&lt;/a&gt; () is a SwiftUI class that creates an image from a view. You just initialize it with the view, then extract a cgImage (Core Graphics) or uiImage that can be cast to a SwiftUI Image.&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;ll need a view to work with, so here it is; a crude version of my behaviour ticket.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-swift" data-lang="swift"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;struct&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;TicketView&lt;/span&gt;: View {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;var&lt;/span&gt; body: some View {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; ZStack {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Color(.cyan)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; .frame(width: &lt;span style="color:#ae81ff"&gt;300&lt;/span&gt;, height: &lt;span style="color:#ae81ff"&gt;350&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; VStack {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Text(&lt;span style="color:#e6db74"&gt;&amp;#34;Fred Bloggs&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; .font(.largeTitle)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Text(&lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; HStack {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Text(&lt;span style="color:#e6db74"&gt;&amp;#34;Putting rubbish in the bin&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Image(systemName: &lt;span style="color:#e6db74"&gt;&amp;#34;trash&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; .foregroundColor(.purple)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Text(&lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Text(&lt;span style="color:#e6db74"&gt;&amp;#34;Green Faction&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Text(&lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Text(&lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Text(&lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt;&lt;span style="color:#e6db74"&gt;\(&lt;/span&gt;Date&lt;span style="color:#e6db74"&gt;()&lt;/span&gt;.formatted&lt;span style="color:#e6db74"&gt;())&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Here it is, with a couple of buttons underneath:&lt;/p&gt;</description></item><item><title>Regex to split a string with two different characters</title><link>https://devendevour.iankulin.com/regex-to-split-a-string-with-two-different-characters/</link><pubDate>Wed, 30 Nov 2022 00:00:00 +0000</pubDate><guid>https://devendevour.iankulin.com/regex-to-split-a-string-with-two-different-characters/</guid><description>&lt;p&gt;&lt;img src="https://devendevour.iankulin.com/images/young-woman-cutting-string-painting-by.jpg" alt="young woman cutting string, painting by - StableDiffusion" class="img-responsive"&gt; &lt;/p&gt;
&lt;p&gt;I&amp;rsquo;m working on the behaviour tickets app, and wanted a visually functional version to share with stakeholders this week to get some feedback. As usual in this situation, I&amp;rsquo;m pressed for time so feeling the pressure to take some liberties with code quality that I&amp;rsquo;ll come back and fix one day.&lt;/p&gt;
&lt;p&gt;In a salient lesson of why that&amp;rsquo;s usually a bad idea, I&amp;rsquo;ve ended up googling to try and understand regex instead of writing code.&lt;/p&gt;</description></item><item><title>FriendFace 61 Feedback</title><link>https://devendevour.iankulin.com/friendface-61-feedback/</link><pubDate>Sat, 26 Nov 2022 00:00:00 +0000</pubDate><guid>https://devendevour.iankulin.com/friendface-61-feedback/</guid><description>&lt;p&gt;As usual after a challenge, I compare my efforts to Paul&amp;rsquo;s model solution. Just to quickly recap the app, it sucks up some data (Users who have multiple friends) and displays it. The change in this challenge was to convert it to add that data to a Core Data store so that if a future network error prevented accessing new data, it could still display the old.&lt;/p&gt;
&lt;h4 id="merge-policy"&gt;Merge Policy&lt;/h4&gt; &lt;p&gt;The first difference is that Paul adds a merge policy. A Merge policy tells Core how to deal with any constraints defined in the data model. In this app, I&amp;rsquo;d defined the CachedUser.id as a constraint. The purpose of this is that under normal conditions the app would be picking up mostly the same data each time it started up. We don&amp;rsquo;t want scabs of duplicate data, so constraining users based on their unique id is smart.&lt;/p&gt;</description></item><item><title>61 Done</title><link>https://devendevour.iankulin.com/61-done/</link><pubDate>Fri, 25 Nov 2022 00:00:00 +0000</pubDate><guid>https://devendevour.iankulin.com/61-done/</guid><description>&lt;p&gt;&lt;img src="https://devendevour.iankulin.com/images/green_tick.svg_.png" alt="" class="img-responsive"&gt; &lt;/p&gt;
&lt;p&gt;I think I&amp;rsquo;ve finally completed the minimum work for Day 61 of &lt;a href="https://www.hackingwithswift.com/100/swiftui/61" target="_blank" rel="noopener"&gt;#100DaysOfSwiftUI&lt;/a&gt; . The task was to suck up some data in JSON, decode it. back it up into a Core Data graph then display the data from the Core Data.&lt;/p&gt;
&lt;p&gt;I got stuck on dealing with the one:many relationship and had to revisit that from a different source to get my head around it, after that it was straightforward. Other small problem I ran into was that I created the id in the CachedUser as a UUID from (newly formed) habit. Then when I went to copy it in from the JSON version, it wouldn&amp;rsquo;t let me. When I realised my mistake and changed it in the data model, I still could not figure out why it wasn&amp;rsquo;t working - but of course I hadn&amp;rsquo;t regenerated the code for the ManagedObject. I just had to change the property type in the already generated code from UUID to string and I was back in business.&lt;/p&gt;</description></item><item><title>Core Data basics – Part Three</title><link>https://devendevour.iankulin.com/core-data-basics-part-three/</link><pubDate>Thu, 24 Nov 2022 00:00:00 +0000</pubDate><guid>https://devendevour.iankulin.com/core-data-basics-part-three/</guid><description>&lt;p&gt;If you&amp;rsquo;re just stumbling across this, perhaps have a look at Part 1 where I layout a simple master/detail app with the data held as arrays of structs, and Part 2 where I convert that into the simplest possible Core Data version. In this post, I&amp;rsquo;m going to add the mechanics for the one:many relationship - Each Garden can be associated with multiple Plants.&lt;/p&gt;
&lt;p&gt;I should also mention I figured out some of this with help from &lt;a href="https://www.youtube.com/watch?v=xgPlJXTfiNA" target="_blank" rel="noopener"&gt;this video&lt;/a&gt; from &lt;a href="https://www.youtube.com/channel/UCxnCA5FBYRCFgIZWD0CKCVg/about" target="_blank" rel="noopener"&gt;Jonathan Rasmusson&lt;/a&gt; .&lt;/p&gt;</description></item><item><title>Core Data basics - Part Two</title><link>https://devendevour.iankulin.com/core-data-basics-part-two/</link><pubDate>Wed, 23 Nov 2022 00:00:00 +0000</pubDate><guid>https://devendevour.iankulin.com/core-data-basics-part-two/</guid><description>&lt;p&gt;Yesterday I roughed out a master/detail app with a list of gardens, and for each garden a detail screen including some plants. It used arrays of structs for the data. Today I&amp;rsquo;m going to convert that app to use Core Data, and explain my understanding of each step. This won&amp;rsquo;t be the entire app - I&amp;rsquo;m going to include the plants in my data structure, but not actually use them in this version. I&amp;rsquo;ll save that 1:many relationship stuff for another post.&lt;/p&gt;</description></item><item><title>Core Data basics - Part One</title><link>https://devendevour.iankulin.com/core-data-basics-part-one/</link><pubDate>Tue, 22 Nov 2022 00:00:00 +0000</pubDate><guid>https://devendevour.iankulin.com/core-data-basics-part-one/</guid><description>&lt;p&gt;To help me get clear on the Core Data basics (&lt;a href="https://devendevour.iankulin.com/tough-day/"&gt;so I can master one of the #100Days challenges&lt;/a&gt; ), I&amp;rsquo;ll write a simple master/detail app with arrays of structs, then convert it to Core Data listing out of the steps. Almost everything I know about Core Data, I learned from Paul Hudson&amp;rsquo;s &lt;a href="https://www.hackingwithswift.com/100/swiftui" target="_blank" rel="noopener"&gt;100 Days of SwiftUI&lt;/a&gt; course - of which I&amp;rsquo;m up to day 61. So shout out to him. I highly recommend that course, and most of the code you&amp;rsquo;ll see in this post is either inspired by, or directly copied from 100 Days, except of course the errors - those are mine. This post - Part One - just describes the app and shows the struct/array version.&lt;/p&gt;</description></item><item><title>Something weird 'append</title><link>https://devendevour.iankulin.com/something-weird-about-append/</link><pubDate>Mon, 21 Nov 2022 00:00:00 +0000</pubDate><guid>https://devendevour.iankulin.com/something-weird-about-append/</guid><description>&lt;p&gt;I&amp;rsquo;m noodling around making sure I understand how Core Data works. Thought I&amp;rsquo;d start with a master/detail app with an array of structs, then replicate it in a Core Data implementation. I&amp;rsquo;m using an array of this struct for my data:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;struct Garden {
 var id = UUID()
 var name = &amp;#34;&amp;#34;
 var address = &amp;#34;&amp;#34;
 var plants: [Plant] = []
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;And I thought this code to load up some sample data was pretty sweet.&lt;/p&gt;</description></item><item><title>Clean Build Folder</title><link>https://devendevour.iankulin.com/clean-build-folder/</link><pubDate>Thu, 17 Nov 2022 00:00:00 +0000</pubDate><guid>https://devendevour.iankulin.com/clean-build-folder/</guid><description>&lt;p&gt;Working on adding Core Data to the FriendFace app, and burnt up 20 minutes figuring out a bug. To set the scene, all I&amp;rsquo;ve changed in the app is to add a couple of core data entities. The plan is that when the JSON is fetched, and decoded into the objects, a copy of the graph will be persisted.&lt;/p&gt;
&lt;p&gt;Problem One was that I was getting a build errors saying the core data classes had been re-declared, and others saying that my class name was ambiguous. Since XCode had generated this code when I&amp;rsquo;d told it to &amp;ldquo;Create NSManagedObject subclass&amp;rdquo;. This is what you do when you want to be able to edit the NSManagedObject for example to created computed properties to unwrap the real properties. If you don&amp;rsquo;t need that flexibility, you just leave the default setting in the entity for XCode to create internally.&lt;/p&gt;</description></item></channel></rss>