<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Swift5.2 on ZK Punk</title>
		<link>https://www.ZKPunk.dev/tags/swift5.2/</link>
		<description>Recent content in Swift5.2 on ZK Punk</description>
		<generator>Hugo</generator>
		<language>en</language>
		
		
		
		
			<lastBuildDate>Tue, 04 Aug 2020 20:59:37 -0700</lastBuildDate>
		
			<atom:link href="https://www.ZKPunk.dev/tags/swift5.2/index.xml" rel="self" type="application/rss+xml" />
			<item>
				<title>Getting Component Information From Date</title>
				<link>https://www.ZKPunk.dev/tips/getting-component-information-from-date/</link>
				<pubDate>Tue, 04 Aug 2020 20:59:37 -0700</pubDate>
				<guid>https://www.ZKPunk.dev/tips/getting-component-information-from-date/</guid>
				<description>&lt;p&gt;Last Run on XCODE 11.6 / Swift 5.2&#xA;Last Run on XCODE 12.0 beta 4 / Swift 5.3&lt;/p&gt;&#xA;&lt;h3 id=&#34;definition&#34;&gt;&#xA;  Definition&#xA;  &lt;a class=&#34;heading-link&#34; href=&#34;#definition&#34;&gt;&#xA;    &lt;i class=&#34;fa 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;&lt;a href=&#34;https://developer.apple.com/documentation/foundation/calendar&#34;&gt;Calendar&lt;/a&gt; - A definition of the relationships between calendar units (such as eras, years, and weekdays) and absolute points in time, providing features for calculation and comparison of dates.&lt;/p&gt;&#xA;&lt;p&gt;The &lt;a href=&#34;https://developer.apple.com/documentation/foundation/calendar&#34;&gt;Calendar&lt;/a&gt; is a value type (struct) that provides with functions that can assist us in decoupling the component information from a given date like the year, month, day of week etc.&lt;/p&gt;</description>
			</item>
			<item>
				<title>Usage of CaseIterable in Swift Enum</title>
				<link>https://www.ZKPunk.dev/tips/usage-of-case-iterable-in-swift/</link>
				<pubDate>Tue, 21 Jul 2020 22:04:00 -0700</pubDate>
				<guid>https://www.ZKPunk.dev/tips/usage-of-case-iterable-in-swift/</guid>
				<description>&lt;p&gt;Last Run on XCODE 11.6 / Swift 5.2&lt;/p&gt;&#xA;&lt;h3 id=&#34;definition&#34;&gt;&#xA;  Definition&#xA;  &lt;a class=&#34;heading-link&#34; href=&#34;#definition&#34;&gt;&#xA;    &lt;i class=&#34;fa 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;&lt;a href=&#34;https://developer.apple.com/documentation/swift/caseiterable&#34;&gt;CaseIterable&lt;/a&gt; is a protocol in Swift, that typically lets an enumeration to provide all of its cases as a collection.&lt;/p&gt;&#xA;&lt;p&gt;Lets look at a simple example from my RoadRage car game. This is an enum type called TrafficType listing the cases of traffic/obstacle Sprites generated in my RoadRage car game.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-swift&#34; data-lang=&#34;swift&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;enum&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;TrafficType&lt;/span&gt;: UInt32 {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;case&lt;/span&gt; Police&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;case&lt;/span&gt; Ambulance&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;case&lt;/span&gt; FireTruck&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;case&lt;/span&gt; Van&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;case&lt;/span&gt; SportsCar&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;case&lt;/span&gt; Taxi&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In my game I would like to find out the total count of the TrafficType entities. I would also like the ability to randomly pick a  traffic object from the list to keep generating obstacles during the game loop. And to achive that is as simple as conforming to the &lt;a href=&#34;https://developer.apple.com/documentation/swift/caseiterable&#34;&gt;CaseIterable&lt;/a&gt; protocol in the enum.&lt;/p&gt;</description>
			</item>
			<item>
				<title>Injecting custom behavior during editmode on a TextField in SwiftUI</title>
				<link>https://www.ZKPunk.dev/tips/injecting-custom-behavior-during-editmode-on-textfield-in-swift-ui/</link>
				<pubDate>Fri, 17 Jul 2020 08:30:06 -0700</pubDate>
				<guid>https://www.ZKPunk.dev/tips/injecting-custom-behavior-during-editmode-on-textfield-in-swift-ui/</guid>
				<description>&lt;p&gt;Last Run on XCODE 11.6 / Swift 5.2&lt;/p&gt;&#xA;&lt;h3 id=&#34;definitions&#34;&gt;&#xA;  Definitions&#xA;  &lt;a class=&#34;heading-link&#34; href=&#34;#definitions&#34;&gt;&#xA;    &lt;i class=&#34;fa 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;&lt;a href=&#34;https://developer.apple.com/documentation/swiftui/textfield&#34;&gt;&amp;lsquo;TextField&amp;rsquo;&lt;/a&gt; is a View provided in SwiftUI for handling user entered input into an app. As per the documentaion, Apple defines it as&lt;/p&gt;&#xA;&lt;p&gt;&amp;ldquo;TextField - A control that displays an editable text interface.&amp;rdquo;&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-swift&#34; data-lang=&#34;swift&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;struct&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;TextFieldEditMode&lt;/span&gt;: View {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    @State &lt;span style=&#34;color:#66d9ef&#34;&gt;private&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;var&lt;/span&gt; someData = &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;var&lt;/span&gt; body: some View {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        TextField(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Type something&amp;#34;&lt;/span&gt;, text: &lt;span style=&#34;color:#960050;background-color:#1e0010&#34;&gt;$&lt;/span&gt;someData)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            .font(.largeTitle)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&#34;initializers&#34;&gt;&#xA;  Initializers&#xA;  &lt;a class=&#34;heading-link&#34; href=&#34;#initializers&#34;&gt;&#xA;    &lt;i class=&#34;fa 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;The &lt;a href=&#34;https://developer.apple.com/documentation/swiftui/textfield&#34;&gt;&amp;lsquo;TextField&amp;rsquo;&lt;/a&gt; has four initializers, and the one we will be using in this post is the one listed below, that provides us with two additional parameters&#xA;&amp;ldquo;onEditingChanged&amp;rdquo; and &amp;ldquo;onCommit&amp;rdquo;.&lt;/p&gt;</description>
			</item>
			<item>
				<title>Custom View Modifiers in SwiftUI</title>
				<link>https://www.ZKPunk.dev/tips/custom-view-modifiers-in-swift-ui/</link>
				<pubDate>Wed, 15 Jul 2020 21:32:39 -0700</pubDate>
				<guid>https://www.ZKPunk.dev/tips/custom-view-modifiers-in-swift-ui/</guid>
				<description>&lt;p&gt;Last Run on XCODE 11.6 / Swift 5.2&lt;/p&gt;&#xA;&lt;p&gt;In SwiftUI View(s) are the building blocks of the UI. All changes to the Views are done by calling special functions called modfiers that wrap up the original View with the needful changes and return a View back.&lt;/p&gt;&#xA;&lt;p&gt;In the example below, we apply a few modifiers to a Text view to create the impression&#xA;of a highlighted text.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-swift&#34; data-lang=&#34;swift&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Text(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;I ♥️ SwiftUI&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    .font(.largeTitle)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    .foregroundColor(.black)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    .background(Color.yellow)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;img src=&#34;https://www.ZKPunk.dev/img/swift_ui_modifier_1.png&#34; alt=&#34;SwiftUI Text modifiers&#34;&gt;&lt;/p&gt;</description>
			</item>
			<item>
				<title>User Input in Swift commandline</title>
				<link>https://www.ZKPunk.dev/tips/user-input-in-swift-commandline/</link>
				<pubDate>Sun, 03 May 2020 22:18:51 -0700</pubDate>
				<guid>https://www.ZKPunk.dev/tips/user-input-in-swift-commandline/</guid>
				<description>&lt;p&gt;Last Run on XCODE 11.4 / Swift 5.2&lt;/p&gt;&#xA;&lt;p&gt;If you are writing a command line tool and need user input, the &lt;code&gt;readLine()&lt;/code&gt; function&#xA;can be used for it. It returns an optional&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-swift&#34; data-lang=&#34;swift&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;let&lt;/span&gt; input = readLine()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;And, if you dont want the ending new line character, you can set the &lt;code&gt;strippingNewline&lt;/code&gt; parameter&#xA;to true.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-swift&#34; data-lang=&#34;swift&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;let&lt;/span&gt; input = readLine(strippingNewline: &lt;span style=&#34;color:#66d9ef&#34;&gt;true&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
			</item>
			<item>
				<title>Checking if a Swift String contains a certain text</title>
				<link>https://www.ZKPunk.dev/tips/checking-if-swift-strings-contains-text/</link>
				<pubDate>Fri, 01 May 2020 12:11:26 -0700</pubDate>
				<guid>https://www.ZKPunk.dev/tips/checking-if-swift-strings-contains-text/</guid>
				<description>&lt;p&gt;Last Run on XCODE 11.4 / Swift 5.2&lt;/p&gt;&#xA;&lt;p&gt;A simple way to check if a string contains a certain text is to use the method &lt;code&gt;contains&lt;/code&gt; available to Strings.&lt;/p&gt;&#xA;&lt;p&gt;In the code snippet below, we will check if a string contains a certain text.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-swift&#34; data-lang=&#34;swift&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;let&lt;/span&gt; fruit1 = &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;apple&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;let&lt;/span&gt; fruit2 = &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;banana&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;let&lt;/span&gt; mySentence = &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;An apple a day keeps the doctor away.&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;mySentence.contains(fruit1) &lt;span style=&#34;color:#75715e&#34;&gt;// result --&amp;gt; True&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;mySentence.contains(fruit2) &lt;span style=&#34;color:#75715e&#34;&gt;// result --&amp;gt; False&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If we need to check the string against multiple options, we will have&#xA;to use a variation of the &lt;code&gt;contains&lt;/code&gt; method that takes a closure. Checkout the code snippet below.&lt;/p&gt;</description>
			</item>
			<item>
				<title>Matching Swift Strings by Prefix or Suffix</title>
				<link>https://www.ZKPunk.dev/tips/matching-swift-strings-by-prefix-or-suffix/</link>
				<pubDate>Tue, 28 Apr 2020 21:56:43 -0700</pubDate>
				<guid>https://www.ZKPunk.dev/tips/matching-swift-strings-by-prefix-or-suffix/</guid>
				<description>&lt;p&gt;Last Run on XCODE 11.4 / Swift 5.2&lt;/p&gt;&#xA;&lt;p&gt;A simple way to check if a string starts or ends with a certain pattern is to use the method &lt;code&gt;hasSuffix&lt;/code&gt; and &lt;code&gt;hasPrefix&lt;/code&gt; available to Strings.&lt;/p&gt;&#xA;&lt;p&gt;In the code snippet below, we will check if a string begins or ends with a specific text pattern.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-swift&#34; data-lang=&#34;swift&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;let&lt;/span&gt; fileName1 = &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;InstagramCover.jpg&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;let&lt;/span&gt; fileName2 = &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;SnapchatCover.doc&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;fileName1.hasSuffix(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;jpg&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#75715e&#34;&gt;// result --&amp;gt; True&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;fileName2.hasSuffix(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;jpg&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#75715e&#34;&gt;// result --&amp;gt; False&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;fileName1.hasPrefix(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Instagram&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#75715e&#34;&gt;// --&amp;gt; True&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;fileName2.hasPrefix(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Facebook&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#75715e&#34;&gt;// result --&amp;gt; False&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If we need to check against multiple variations, we can&amp;rsquo;t just use &lt;code&gt;hasSuffix&lt;/code&gt;. Instead, we will have&#xA;to use it along with another method &lt;code&gt;contains&lt;/code&gt;. Checkout the code snippet below.&lt;/p&gt;</description>
			</item>
			<item>
				<title>Access Swift String by Index</title>
				<link>https://www.ZKPunk.dev/tips/access-swift-string-by-index/</link>
				<pubDate>Tue, 21 Apr 2020 22:23:31 -0700</pubDate>
				<guid>https://www.ZKPunk.dev/tips/access-swift-string-by-index/</guid>
				<description>&lt;p&gt;Last Run on XCODE 11.4 / Swift 5.2&lt;/p&gt;&#xA;&lt;p&gt;The &lt;strong&gt;swift&lt;/strong&gt; string class does not provide the ability to get a character at a specific index because of its native support for UTF characters.&lt;/p&gt;&#xA;&lt;p&gt;In the code snippets below, we will walk through code to access elements of a string at speific positions.&lt;/p&gt;&#xA;&lt;h4 id=&#34;getting-the-first-character&#34;&gt;&#xA;  Getting the first Character&#xA;  &lt;a class=&#34;heading-link&#34; href=&#34;#getting-the-first-character&#34;&gt;&#xA;    &lt;i class=&#34;fa 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;/h4&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-swift&#34; data-lang=&#34;swift&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;let&lt;/span&gt; mySwiftString = &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Swift is awesome!&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;//Getting the first Character&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;mySwiftString.first&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;let&lt;/span&gt; firstIndex = mySwiftString.startIndex&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;mySwiftString[firstIndex]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h4 id=&#34;getting-the-last-character&#34;&gt;&#xA;  Getting the last Character&#xA;  &lt;a class=&#34;heading-link&#34; href=&#34;#getting-the-last-character&#34;&gt;&#xA;    &lt;i class=&#34;fa 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;/h4&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-swift&#34; data-lang=&#34;swift&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;let&lt;/span&gt; mySwiftString = &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Swift is awesome!&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;//Getting the last Character&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;mySwiftString.last&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;let&lt;/span&gt; lastIndex = mySwiftString.index(before: mySwiftString.endIndex)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;mySwiftString[lastIndex]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h4 id=&#34;getting-the-2nd-character&#34;&gt;&#xA;  Getting the 2nd Character&#xA;  &lt;a class=&#34;heading-link&#34; href=&#34;#getting-the-2nd-character&#34;&gt;&#xA;    &lt;i class=&#34;fa 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;/h4&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-swift&#34; data-lang=&#34;swift&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;let&lt;/span&gt; mySwiftString = &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Swift is awesome!&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;//Getting the 2nd Character&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;let&lt;/span&gt; secondIndex_Ver1 = mySwiftString.index(after: firstIndex)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;mySwiftString[secondIndex_Ver1]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;let&lt;/span&gt; secondIndex_Ver2 = mySwiftString.index(firstIndex, offsetBy: &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;mySwiftString[secondIndex_Ver2]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h4 id=&#34;getting-the-nth-character-from-start--say-3rd&#34;&gt;&#xA;  Getting the Nth Character from start ( Say 3rd)&#xA;  &lt;a class=&#34;heading-link&#34; href=&#34;#getting-the-nth-character-from-start--say-3rd&#34;&gt;&#xA;    &lt;i class=&#34;fa 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;/h4&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-swift&#34; data-lang=&#34;swift&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;let&lt;/span&gt; mySwiftString = &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Swift is awesome!&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;//Getting the Nth Character from start ( Say 3rd )&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;let&lt;/span&gt; thirdIndex = mySwiftString.index(firstIndex, offsetBy: &lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;mySwiftString[thirdIndex]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h4 id=&#34;getting-the-nth-character-from-end--say-3rd-last-&#34;&gt;&#xA;  Getting the Nth Character from end ( Say 3rd last )&#xA;  &lt;a class=&#34;heading-link&#34; href=&#34;#getting-the-nth-character-from-end--say-3rd-last-&#34;&gt;&#xA;    &lt;i class=&#34;fa 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;/h4&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-swift&#34; data-lang=&#34;swift&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;let&lt;/span&gt; mySwiftString = &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Swift is awesome!&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;//Getting the Nth Character from end ( Say 3rd last )&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;let&lt;/span&gt; thirdLastIndex = mySwiftString.index(lastIndex, offsetBy: &lt;span style=&#34;color:#f92672&#34;&gt;-&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;mySwiftString[thirdLastIndex]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
			</item>
			<item>
				<title>How to enumerate nodes in Spritekit?</title>
				<link>https://www.ZKPunk.dev/tips/enumerate_spritekit_nodes/</link>
				<pubDate>Fri, 10 Apr 2020 09:00:05 -0700</pubDate>
				<guid>https://www.ZKPunk.dev/tips/enumerate_spritekit_nodes/</guid>
				<description>&lt;p&gt;Last Run on XCODE 11.4 / Swift 5.2&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Spritekit&lt;/strong&gt; has a method &lt;code&gt;enumerateChildNodes&lt;/code&gt; that searches the children of the receiving node to perform processing for nodes that share a name.&lt;/p&gt;&#xA;&lt;p&gt;In the code snippet below, we are are iterating through all the nodes with the name &amp;ldquo;trafficCar&amp;rdquo; in the parent node (or &lt;code&gt;SKScene&lt;/code&gt;) and performing some action on it.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-swift&#34; data-lang=&#34;swift&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;func&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;moveTraffic&lt;/span&gt;() {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    enumerateChildNodes(withName: &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;trafficCar&amp;#34;&lt;/span&gt;) { &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (trafficCar, stop) &lt;span style=&#34;color:#66d9ef&#34;&gt;in&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;let&lt;/span&gt; car = trafficCar &lt;span style=&#34;color:#66d9ef&#34;&gt;as&lt;/span&gt;! SKSpriteNode&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        car.position.y &lt;span style=&#34;color:#f92672&#34;&gt;-=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;10&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
			</item>
	</channel>
</rss>
