<?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 Jake Shelley on Medium]]></title>
        <description><![CDATA[Stories by Jake Shelley on Medium]]></description>
        <link>https://medium.com/@JakeShelley3?source=rss-4a799bf3029c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Yy3X8Jj1dHd-2vypPlQxtQ.jpeg</url>
            <title>Stories by Jake Shelley on Medium</title>
            <link>https://medium.com/@JakeShelley3?source=rss-4a799bf3029c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 18:23:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@JakeShelley3/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[How To Build A Super Quick Smile Tracking App]]></title>
            <link>https://medium.com/free-code-camp/how-to-build-a-super-quick-smile-tracking-app-16eee960888d?source=rss-4a799bf3029c------2</link>
            <guid isPermaLink="false">https://medium.com/p/16eee960888d</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[augmented-reality]]></category>
            <dc:creator><![CDATA[Jake Shelley]]></dc:creator>
            <pubDate>Wed, 23 Jan 2019 18:02:28 GMT</pubDate>
            <atom:updated>2019-05-08T13:59:43.330Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6zDrFfE7gE4IIoeiR3IJiw.jpeg" /></figure><p>ARKit might seem intimidating but it’s not so bad if you already have some basic experience building iOS apps.</p><p>I’m a learn-by-doing type, so I’ve been playing around with ARKit, building basic apps to get familiar with it. In this post, I’ll review what I’ve learned creating a simple face tracking app.</p><p>I’ll do this in 3 parts:</p><ol><li><strong>Initial Setup → </strong>First things first, get Camera permissions and make sure the device can use ARKit.</li><li><strong>Smile tracking → </strong>Start tracking smiles with ARKit. This is probably what you’re here for.</li><li><strong>User Interface → </strong>Add the UI for our app that will react to smiles.</li></ol><p>As of this writing, the Xcode simulator does not support the front facing camera so you will need a real device to run the app. Your device will also need to have a TrueDepth camera<strong> (as of May 8th 2019, only the iPhone X and iPhone X Plus have a TrueDepth camera).</strong></p><p>Finally, for my fellow members of the Copy Paste Club, <a href="https://github.com/JakeShelley1/SmileTracker">all the code is available on Github</a>.</p><h4><strong>Initial Setup</strong></h4><p>Start by opening up Xcode and creating a new project named “SmileTracker” (or whatever name you prefer).</p><p>Before we can get into face tracking, we’ll need to do two things:</p><ol><li>Make sure your device supports ARKit</li><li>Get permission to access your device’s camera</li></ol><p>In your new project, open ViewController.swift. Near the top of the file, underneath import UIKit, add the line: import ARKit. This will let us access all the goodies that Apple has provided us to make face tracking super easy.</p><p>Now add the following code inside of viewDidLoad:</p><pre>guard ARFaceTrackingConfiguration.isSupported else {<br>   fatalError(&quot;Device does not support face tracking&quot;)<br>}</pre><p>ARFaceTrackingConfiguration.isSupported is a boolean that will be true if the device running the app can support face tracking and false if not. In this case, if the device can’t support face tracking, we’ll crash the app with a fatal error.</p><p>Next, let’s get permission to use the camera. Add the following in viewDidLoad below our guard statement:</p><pre>AVCaptureDevice.requestAccess(for: AVMediaType.video) { granted in<br>   if (granted) {<br>      Dispatch.main.sync {<br>         // We&#39;re going to implement this function in a minute<br>         self.setupSmileTracker()<br>      }<br>   } else {<br>      fatalError(&quot;User did not grant camera permission!&quot;)<br>   }<br>}</pre><p>Here we’re asking the device to request camera permissions. If the user grants permissions, we’ll run the function that will setup our smile tracking (don’t worry about the error, we’ll be implementing this function in a moment).</p><p>We wrap the function in Dispatch.main.sync because we’ll be adding UI elements in this function, which can only be done on the main thread.</p><p>We’ll also need to add a Camera Usage Description to our Info.plist. Open Info.plist and add a new row (you can do this by highlighting the last row and hitting enter).</p><p>In the row you just created, add Privacy — Camera Usage Description to the Key column and make sure the Type column is set to string. You can leave the Value column blank or add a message to explain how you will use the camera to the user.</p><p>Your Info.plist should now look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/1*gzKy5D-8Pw-DQnPd6lQz7Q.png" /></figure><p>If you’d like to test your app so far, you can comment out the line where we call setupSmileTracker(). Just remember to uncomment it later.</p><p>If you run your app now, you should see a popup asking you to enable camera permissions. <strong>If you say no you’ll have to go to application settings to enable those permissions in order for the app to run.</strong></p><p>If the app crashes, check the console for one of our two error messages to see what went wrong.</p><h4>Smile tracking</h4><p>Open ViewController.swift and add the following variable to the top of ViewController:</p><pre>class ViewController: UIViewController {<br><strong>   let sceneView = ARSCNView()</strong></pre><pre>   override func viewDidLoad() {...}</pre><pre>}</pre><p>ARSCNView comes equipped with an ARSession that your iPhone uses to coordinate AR experiences. We’ll be using sceneView’s ARSession to analyze our user’s face through the front facing camera.</p><p>Add this function to your file underneath viewDidLoad:</p><pre>func setupSmileTracker() {<br>   let configuration = ARFaceTrackingConfiguration()<br>   sceneView.session.run(configuration)<br>   sceneView.delegate = self<br>   view.addSubview(sceneView)<br>}</pre><p>Here we’ve created a configuration to handle face tracking and used it to run our sceneView’s ARSession.</p><p>Then we set sceneView&#39;s delegate to self and add it to our view.</p><p>Xcode will tell you that there is a problem since ViewController does not conform to ARSCNViewDelegate. Go to where ViewController is declared near the top of the file and change the line to the following:</p><pre>class ViewController: ViewController, <strong>ARSCNViewDelegate </strong>{<br>   ...<br>}</pre><p>Now add thisARSCNViewDelegate function in your ViewController class setupSmileTracker:</p><pre>func renderer(_renderer: SCNSceneRenderer, didUpdate node: SCNNode, for anchor: ARAnchor) {</pre><pre>}</pre><p>renderer will run every time our scene updates and provides us with the ARAnchor that corresponds to the user’s face.</p><p>To make it easier to create face tracking experiences, <strong>Apple automatically creates an </strong>ARFaceAnchor<strong> and adds it to our session when we use an </strong>ARFacetrackingConfiguration <strong>to run it. </strong>This ARFaceAnchor is then passed into renderer as an ARAnchor.</p><p>Add the following code to renderer:</p><pre>func renderer(_renderer: SCNSceneRenderer, didUpdate node: SCNNode, for anchor: ARAnchor) {<br>   // 1   <br>   guard let faceAnchor = anchor as? ARFaceAnchor else { return }</pre><pre>   // 2<br>   let leftSmileValue = faceAnchor.blendshapes[.mouthSmileLeft] as! CGFloat<br>   let rightSmileValue = faceAnchor.blendShapes[.mouthSmileRight] as! CGFloat</pre><pre>   // 3   <br>   print(leftSmileValue, rightSmileValue)</pre><pre>}</pre><p>There’s a lot going on inside this function so I’ve numbered the steps (Ray Wenderlich style).</p><p>In <strong>step 1 </strong>we convert the ARAnchor into an ARFaceAnchor and assign it to the faceAnchor variable.</p><p>ARFaceAnchor contains information about the current position and orientation, topology, and <em>facial expression</em> of the face we’re tracking.</p><p>ARFaceAnchor stores information about facial expressions in its variable blendShapes. blendShapes is a dictionary that stores coefficients corresponding to various facial features. If you’re interested, I suggest you <a href="https://developer.apple.com/documentation/arkit/arfaceanchor/blendshapelocation">check out the full list of facial features in Apple’s documentation</a>. (<em>Hint</em>: if you want to add frown tracking you’ll find a way to do it in here.)</p><p>In <strong>step 2</strong>, we use faceAnchor.blendShapes to get the a CGFloat that corresponds to how much the left and right sides of the user’s mouth is smiling by using the keys mouthSmileLeft and mouthSmileRight.</p><p>Finally, <strong>step 3</strong> just prints out the two values so you can make sure it’s working properly 😉.</p><p>At this point you should have an app that:</p><ul><li>Gets camera and face tracking permissions from the user</li><li>Uses ARKit to track the users facial expressions</li><li>Prints how much the user is smiling on the left and right sides of their mouth to the console</li></ul><p>We’ve made a lot of progress, so let’s take a second to make sure everything is running properly.</p><p>When you run the app for the first time, you should be asked if you will grant camera permissions. Make sure to say yes.</p><p>You’ll then be sent to a blank screen, but you should start seeing CGFloat values being printed to the console (there may be a short delay before you see them).</p><p>When you smile at your phone you should notice the values being printed going up. The more you smile the higher the numbers go.</p><p>If it’s working properly, <em>congratulations</em> 🎊! If you’re running into an error, double check to make sure your device supports face tracking and you have camera permissions turned on. If you’ve been following this writeup from the beginning the console will print errors in both those cases.</p><h4>User interface</h4><p>So we’re tracking faces, now let’s build the UI to react to smiles.</p><p>First add a new UILabel called smileLabel to the top of the file, just below sceneView.</p><pre>class ViewController: UIViewController {<br>   let sceneView = ARSCNView()   <br><strong>   let smileLabel = UILabel()</strong></pre><pre>   ...<br>}</pre><p>This will be the view that reacts to the user’s facial expressions.</p><p>Add the following code at the bottom of your setupSmileTracker function:</p><pre>smileLabel.text = &quot;😐&quot;<br>smileLabel.font = UIFont.systemFont(ofSize: 150)</pre><pre>view.addSubview(smileLabel)</pre><pre>// Set constraints<br>smileLabel.translatesAutoresizingMaskIntoConstraints = false<br>smileLabel.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true<br>smileLabel.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true</pre><p>Here, we’re adding the basic UI properties to our smileLabel and setting its constraints so it is in the middle of the screen. Now when you run the app, you should see a giant 😐 emoji in the middle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*Ck5tlFtnQJaHkq2qscxpQA.jpeg" /></figure><p>Once you see the emoji appear, add the following function to your ViewController:</p><pre>func handleSmile(leftValue: CGFloat, rightValue: CGFloat) {<br>      let smileValue = (leftValue + rightValue)/2.0</pre><pre>      switch smileValue {<br>      case _ where smileValue &gt; 0.5:<br>         smileLabel.text = &quot;😁&quot;<br>      case _ where smileValue &gt; 0.2:<br>         smileLabel.text = &quot;🙂&quot;<br>      default:<br>         smileLabel.text = &quot;😐&quot;<br>      }<br>}</pre><p>This function will change the emoji in our smileLabel depending on how much the user is smiling into the camera. We calculate the smileValue by taking the average of the left and right smile values given to us by our ARFaceAnchor (very scientific, I know).</p><p>Plug that value into the switch statement, and the more the user smiles the happier our emoji gets.</p><p>Finally, go back to our renderer function and add this to the bottom to plug in our left and right smile values into handleSmile:</p><pre>DispatchQueue.main.async {<br>   self.handleSmile(leftValue: leftSmileValue, rightValue: rightSmileValue)<br>}</pre><p>Again, we use DispatchQueue because we are making changes to the UI, which must be done on the main thread.</p><p>When you run the app you should now see the emoji change depending on how much you smile at it.</p><p>In the gif below I’ve added my face so that you can see it working with the camera output along with the emoji.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/280/1*3JpVijoijxS-11U3ltn_Fw.gif" /><figcaption>I added the camera output to show how it works</figcaption></figure><p>Your app won’t have the camera output, but you can add it by adding our ARSCNView, sceneView, to the superview and giving it dimensions.</p><h4>Wrapping up</h4><p>I hope this post was helpful for you to get started creating apps with ARKit.</p><p>If you want to extend this app further, check out the list I mentioned above with all the other facial features you can track. I left a hint for how to extend this to check for frowns as well.</p><p>Come back and comment with any cool projects you create on your own, I’m still getting my feet wet with this stuff so it’d be excited to see more complex apps.</p><p><a href="https://github.com/JakeShelley1/SmileTracker">I’ve posted all the code for this app up on Github</a> for feedback and questions. Thanks for reading and good luck!</p><p><em>Thanks so much for reading! If you liked this story, follow me on </em><a href="https://twitter.com/JakeShelley3"><em>Twitter</em></a><em> where I post updates about stories I’m working on and what I’m up to.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=16eee960888d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/how-to-build-a-super-quick-smile-tracking-app-16eee960888d">How To Build A Super Quick Smile Tracking App</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What happens to Local Notifications when the user turns them off?]]></title>
            <link>https://medium.com/@JakeShelley3/what-happens-to-local-notifications-when-the-user-turns-them-off-bdecc06fcf64?source=rss-4a799bf3029c------2</link>
            <guid isPermaLink="false">https://medium.com/p/bdecc06fcf64</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift-programming]]></category>
            <dc:creator><![CDATA[Jake Shelley]]></dc:creator>
            <pubDate>Tue, 24 Apr 2018 23:17:34 GMT</pubDate>
            <atom:updated>2018-07-06T15:33:51.747Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*6_h0ZOsdXdk-mdGGqE3M6w.jpeg" /></figure><p><strong>TLDR: If you set a Local Notification to fire when a user has Local Notification permissions turned off, it will still fire at the expected time if the user turns permissions on later.</strong></p><p>Local Notifications are a useful tool in any iOS developers toolbox. If you are building any sort of alarming tool you pretty much have no other option.</p><p>Unfortunately, many users don’t distinguish between local notifications and push notifications and will deny permissions for both.</p><p>Recently, <a href="http://www.jacobshelley.com/radiou">I was working on an app</a> where users could sign up to get alerts for their favorite events. Even if the user did not allow me to send local notifications, I would still set them up to repeat at the desired time (I won’t be going over how to set local notifications, but here are <a href="https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/SchedulingandHandlingLocalNotifications.html">Apple’s instructions on how to set them up</a>).</p><p>So what happened to those local notifications that were being sent to users? <strong>More importantly, if I convinced the users to turn permissions on, would the notifications be sent as scheduled?</strong></p><p>Let’s set up a scenario:</p><blockquote><em>While the user has denied notification authorization I set a local notification to repeat at 2:00PM every day. At 1:30PM the user grants me authorization to send local notifications. What happens at 2PM? Does the notification send as scheduled or does it never get set because I didn’t have permission when it was initialized?</em></blockquote><p>In the above case, the notification would be sent as normal, even though I set the notification while the user had notifications turned off.</p><p>From this, it’s probably safe to conclude that Apple is simply suppressing the notifications that you send if the user’s permissions are still offline.</p><p>Hope this saves someone some time!</p><p><em>Thanks so much for reading! If you liked this story, follow me on </em><a href="https://twitter.com/JakeShelley3"><em>Twitter</em></a><em> where I post articles about product management, engineering, and design.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bdecc06fcf64" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to make an App Store-worthy iOS app preview on a budget]]></title>
            <link>https://medium.com/free-code-camp/how-to-make-an-app-store-worthy-ios-app-preview-on-a-budget-c4a7de1d5401?source=rss-4a799bf3029c------2</link>
            <guid isPermaLink="false">https://medium.com/p/c4a7de1d5401</guid>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Jake Shelley]]></dc:creator>
            <pubDate>Sat, 31 Mar 2018 07:56:38 GMT</pubDate>
            <atom:updated>2018-03-31T07:56:38.342Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BkBLvnsaD7NaXFVj3quLGQ.jpeg" /></figure><p>Back in 2014, Apple made it possible to add an app preview to the the App Store. App previews are the best way to show potential users what your app has to offer before they download the app. In fact, users are 3x more likely to install an app with an app preview, according to <a href="https://www.storemaven.com/">StoreMaven</a>.</p><p>Unfortunately, many solo makers don’t have the budget to hire a professional to make an app preview. Recently, I found myself in this position, and after some digging, I found a couple of free tools to make a quality app preview.</p><p>In this post, I’m going to go over the following:</p><ol><li>Preparing the content</li><li>Recording the video</li><li>Editing the video</li><li>Common issues</li></ol><p>I’m assuming that you are using a Mac, which comes with Xcode, Quicktime, and iMovie for free. If you are not using a Mac you might need to purchase these tools.</p><h4>Preparing the content</h4><p>Each app developer knows the most engaging and fun parts of their app. Make sure to highlight those in your app preview. Figure out where you need to add text overlays and ensure the text contrasts with the background it’s displayed on.</p><p>As of iOS 11, you can have up to three app previews to show off your app. It may be tempting to use the entire 90 seconds you are given, but I would suggest loading your most interesting features in the first one. If users aren’t interested in your app by the first preview, it’s unlikely they’ll take the time to watch the other two.</p><p>Finally, you may want to show the users how they will interact with your app. To show off touches and gestures, use <a href="https://github.com/LukasCZ/GSTouchesShowingWindow-Swift">GSTouchesShowingWindow</a>. It’s super easy to install and will show off how users will interact with your app.</p><h4>Recording the video</h4><p>Once you have decided the content you want to show, you can start recording your video. The easiest way to do this is to use <strong>Quicktime</strong> to record the screen of a connected iPhone.</p><p>Plugin your iPhone, then open quicktime and hit File &gt; New Movie Recording. This will open a recording window. From the dropdown next to the record button, you can select the device you have connected.</p><p>Using a connected device means that you are limited only to the devices you have. Luckily, you can use <strong>Xcode CLI</strong> to record your simulator actions.</p><p>To record with the Xcode CLI, begin running your simulator in Xcode. Then, open your terminal and enter the following command:</p><pre>$ xcrun simctl io booted recordVideo example.mp4</pre><p>Perform the actions you want to record in the simulator then ctr-C in your terminal to end the recording session. The above command will add the video example.mp4 to the current directory of your terminal.</p><h4>Editing the Video</h4><p>There are two goals you are trying to hit while editing your preview:</p><ol><li>Show your app in the best light possible</li><li>Edit the preview down to between 15 and 30 seconds</li></ol><p>The best tool for editing an app preview is <strong>iMovie</strong>. Open iMovie and click File &gt; New App Preview. Drop your video into the media area to add it to your project.</p><p>I’m not going to go into details of how to edit an iMovie app, but the UI is pretty intuitive. Just drag and drop the scenes you want onto the lower area to add them to your clip. command+B will allow you to split your clip so you can fit cool transitions and keep track of the pacing better. You can add transitions between split clips, audio, and title screens.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EcphKke7Tlz_eJWJNnue7w.png" /><figcaption>You can add text overlays and audio to your app preview in iMovie before exporting it</figcaption></figure><p>Once you are done editing, click File &gt; Share &gt; App Preview (if you don’t see App Preview you can also click file). Then, select the destination you want to save it to and hit enter. After a few seconds, your video will be available.</p><h4>Common issues</h4><p>So at this point there is a good chance you already have everything ready to go, but when you try to upload your preview to iTunes Connect, you get an error. It is likely that your problems are caused by one of these two app preview requirements:</p><ol><li>Your app preview’s resolution must match the requirements for the device type</li><li>Your app preview must run at 30 fps</li></ol><p>The likelihood that your app preview’s resolution doesn’t meet the requirements is pretty low, but I actually ran into trouble <strong>even when I recorded directly from my iPhone</strong><em>.</em> For whatever reason, Quicktime captured everything off by one pixel, so iTunes Connect refused to let me upload the video.</p><p>After some searching, I found a free tool that lets you crop your .mov (or any video type) into the correct resolution. Go to <a href="https://ezgif.com/">ezgif.com</a> and click Video to GIF on the nav bar. This opens another nav bar below the first one, where you will see Crop video. Click that, then you can upload your quicktime .mov file. Crop the video to the size you need and download the new file.</p><p>If you face issues related to your app preview not running at 30 fps, that’s an easy one to fix (for free) with <a href="https://www.ffmpeg.org/">ffmpeg</a>. Open your terminal, ensure you have <a href="https://brew.sh/">homebrew</a> installed, and enter:</p><pre>$ brew install ffmpeg</pre><p>Now with ffmpeg installed, cd into the directory that contains your video and enter:</p><pre>$ ffmpeg -i &quot;original.mov&quot; -r 30 &quot;converted_30fps_video.mov&quot; </pre><p>This will output your video converted to 30 fps.</p><h4>Conclusion</h4><p>You should now have an app preview that meets all of Apple’s requirements. Having an app preview is important so that your app stands out from the millions of apps on the app store. I found that the tools used in this guide landed me with a high quality app preview that I felt marketed my app well, and it didn’t cost a dime!</p><p>I hope this guide saved you some time and money. Good luck on the app store!</p><p><em>Thanks so much for reading! If you liked this story, follow me on </em><a href="https://twitter.com/JakeShelley3"><em>Twitter</em></a><em> where I post articles about product management, engineering, and design.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c4a7de1d5401" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/how-to-make-an-app-store-worthy-ios-app-preview-on-a-budget-c4a7de1d5401">How to make an App Store-worthy iOS app preview on a budget</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Go-To Pods and Extensions For iOS Development]]></title>
            <link>https://medium.com/@JakeShelley3/my-go-to-pods-and-extensions-for-ios-development-e78ac91637fe?source=rss-4a799bf3029c------2</link>
            <guid isPermaLink="false">https://medium.com/p/e78ac91637fe</guid>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Jake Shelley]]></dc:creator>
            <pubDate>Sat, 03 Feb 2018 18:03:24 GMT</pubDate>
            <atom:updated>2018-02-03T18:03:24.295Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*64npeqa57xpKgcQB3jnfbQ.jpeg" /></figure><p>On any given weekend, I’ve got two or three iOS ideas that I want to tinker on. Most of those will likely never see the light of day, nor should they, but a lot of will at least make it to an Xcode project.</p><p>Starting apps in Xcode can be exciting, but it also stinks when I try to use a function from an extension or pod that I’ve already loaded or written in an older, more mature project only to find that I haven’t added it to my new one.</p><p>Through the wreckage of tens (maybe hundreds?) of abandoned iOS projects I’ve noticed a set of extensions and pods that find their way into almost all of my applications. Now whenever I start a new project I’ll typically add these extensions and pods immediately so I can hit the ground running. It saves me time later when I want to build apps the way I’m used too.</p><p>This is pretty much a personal list of tools I add to projects. If you have any to add, comment or send me a message and I’ll be happy to add them.</p><h3>Extensions</h3><p>Swift encourages developers to extend on existing classes. It’s incredibly easy to add an extension to a class in Swift:</p><pre>extension ClassToExtend {<br>   func doSomething() {<br>      // This can now be called by the class<br>   }<br>}</pre><p>Here are a couple of extensions I find useful.</p><h4>UIColor</h4><pre>extension UIColor {<br>   public class var primaryColor: UIColor {<br>      return UIColor(red:0.33, green:0.33, blue:0.33, alpha:1.0)<br>   }<br>}</pre><p>I <em>always</em> extend UIColor to add my own custom colors. Once you’ve added an extended UIColor, you can access it easily.</p><pre>view.background = .primaryColor<br>view.layer.shadowColor = UIColor.primaryColor.cgColor</pre><p>You can add tons of custom colors with that extension. <a href="https://github.com/JakeShelley1/Todo-List-App-Swift/blob/master/Todo/Extensions/UIColor%2BTodo.swift">Here’s a look at all of the colors I added to UIColor in one of my apps</a>.</p><h4>UIView</h4><pre>extension UIView {<br>    addSubviews(_ views: [UIView]) {<br>        for view in views {<br>            self.addSubview(view)<br>        }<br>    }<br>}</pre><p>Ever since I started drifting towards constructing views programmatically, addSubviews has been a great help in cleaning up my code.</p><p>It takes an array of UIViews and calls addSubview on each one in the order of the array. It cuts down on the amount of view.addSubview’s in a file and lets me focus sectioning off where I build the UI pieces and where I add them.</p><h3>Cocoapods</h3><p>Cocoapods is the first thing I download in any project I have. Incase you are not familiar, Cocoapods is sort of like the app store for iOS libraries (Orta Thoreaux, one of the maintainers of Cocoapods, told me that).</p><p>Adding pods to your file is simple. In your terminal, cd to your project directory then enter pod init. After that you can add pods to your Podfile and use pod install to build a .xcworkspace where you can import and use them.</p><h4><a href="https://cocoapods.org/pods/Realm">Realm</a></h4><p>Persisting data across sessions in iOS can be annoying. NSUserDefaults is fine for simple storage, it falls flat for more complex objects. Core Data is the built in solution, but it’s really frustrating to use, especially because Apple’s documentation for it can be confusing.</p><p>Realm is a replacement database for Core Data. It has better performance, amazing documentation, and really clear API’s. Any time I need to store something too complex for UserDefaults, I’ll use Realm.</p><h4><a href="https://cocoapods.org/pods/SnapKit">SnapKit</a></h4><p>Like I mentioned before, I recently starting constructing many of my views programmatically rather than with a Storyboard or Nib. The reason I felt comfortable enough to make the switch to programmatic UI building was SnapKit.</p><p>SnapKit drastically simplifies the process of writing constraints in code. It’s API is clear and concise, which forces you to write easily readable code.</p><p><a href="https://medium.freecodecamp.org/how-to-use-snapkit-to-write-constraints-programmatically-for-ios-apps-ce0a6d9e76cf">I actually wrote up a whole article about how to get started with SnapKit</a>.</p><h4><a href="https://cocoapods.org/pods/Alamofire">AlamoFire</a></h4><p>Building an app is already difficult enough without having to worry about networking. AlamoFire (or AFNetworking if you want to use the Objective-C version) makes setting up callbacks and managing data over HTTP easy on.</p><p>Note that if you want to use it to load images you’ll have to use AlamoFireImages as well.</p><h4><a href="https://cocoapods.org/pods/SwiftyJSON">SwiftyJSON</a></h4><p>Loading JSON over swift is the freakin’ worst. Since they added Codables in 4.0 it’s gotten better, but at this point I’m just used to using SwiftyJSON. It allows you to open up JSON data in Swift in a familiar way rather than trudging through a bunch of optionals. If you are loading any sort of JSON data, this is a must have.</p><h4><a href="https://cocoapods.org/pods/SDWebImage">SDWebImage</a></h4><p>SDWebImage library lets you build a UIImage using an image from the web as though it were local. Check out the examples on their website to see how easy it is. They handle the callback and setting place holder images as well so you can add slick animations for when your image loads.</p><h4><a href="https://cocoapods.org/pods/RxSwift">RxSwift</a></h4><p>Key-Value Observing (KVO) is so important for building with iOS but is often overlooked due to its perceived complexity. RxSwift has awesome API’s for building a reactive app. It’s built out of RxCocoa so it already has a mature ecosystem of reactive API’s to draw from.</p><p>As a bonus, RxRealm will allow you to observe Realm objects like you would with RxSwift. If you are ready to take it to the next level, you can use <a href="https://cocoapods.org/?q=moya">Moya</a> which allows you to turn objects loaded over an HTTP request into observables.</p><p>That’s it for now, I’m going to keep editing this with more stuff later. If there are any pods or extensions you find yourself always using, send me a comment or message and I’ll happily add it to the list.</p><p><em>Thanks so much for reading. If you like this story, follow me on </em><a href="https://twitter.com/JakeShelley3"><em>Twitter</em></a><em> where I post stuff about product management, engineering, and design.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e78ac91637fe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Use SnapKit to Write Constraints Programmatically for iOS Apps]]></title>
            <link>https://medium.com/free-code-camp/how-to-use-snapkit-to-write-constraints-programmatically-for-ios-apps-ce0a6d9e76cf?source=rss-4a799bf3029c------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce0a6d9e76cf</guid>
            <category><![CDATA[iphone]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Jake Shelley]]></dc:creator>
            <pubDate>Sun, 14 Jan 2018 21:13:53 GMT</pubDate>
            <atom:updated>2018-03-28T02:43:28.660Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mLxT0gEiltVrN8rS_zKLWg.jpeg" /></figure><p>When I first started building apps with Xcode, I thought Storyboards were magic. Dragging and dropping subviews into place was so simple, I never understood how people built views without them.</p><p>Eventually, I decided that to become a “master programmer,” I would need to learn how to construct views programmatically. One problem, writing constraints in code is a pain.</p><pre>let horizontalConstraint = NSLayoutConstraint(<br>   item: newView, <br>   attribute: NSLayoutAttribute.centerX, <br>   relatedBy: NSLayoutRelation.equal, <br>   toItem: view, <br>   attribute: NSLayoutAttribute.centerX, multiplier: 1, constant: 0)</pre><p>That’s a horizontal constraint that will center a subview on the X axis of its superview. Not so easy to read not to mention writing that for every constraint gets old fast. Still, I wanted to ditch storyboards so I searched for an alternative. That’s when I found <a href="http://github.com/SnapKit/SnapKit">SnapKit</a>.</p><p>SnapKit has a clear and concise API that makes writing constraints in the code a breeze. I’m going to go through a few really basic examples of what can be done in SnapKit.</p><p>I’ll be going over:</p><ol><li><strong>Laying out a subview in its superview</strong></li><li><strong>Laying out subviews relative to each other</strong></li><li><strong>Updating and animating constraints</strong></li></ol><h4>Getting started</h4><p>Make sure you download SnapKit in your project. I use <a href="http://cocoapods.org/">Cocoapods</a> for 3rd party libraries.</p><p>Add pod &#39;SnapKit&#39; to your Podfile and run pod install. Now write import SnapKit at the top of the file you want to use it in.</p><h4>Laying out a subview in its superview</h4><p>First off I’ll pin a subview to the edges of its superview:</p><pre>let subview = UIView()<br>view.addSubview(subview)</pre><pre>subview.snp.makeConstraints { (make) in<br>    make.top.equalTo(view)<br>    make.bottom.equalTo(view)<br>    make.left.equalTo(view)<br>    make.right.equalTo(view)<br>}</pre><p>This will set constraints for the top, bottom, left, and right edges of the subview to the corresponding edges of its superview with a constant of 0.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*MLyyrj4xpqBlzzkK9Ylbnw.png" /><figcaption>The subview pinned to its superview’s edges with a constant of 0</figcaption></figure><p>Notice that I add the subview to the superview before I setting the subview’s constraints. If you write constraints for views that aren’t already added to the superview, it will throw a fatal runtime error when the view loads.</p><p>The SnapKit syntax is already a lot more readable than the standard library but it can be shortened. SnapKit provides an even more concise way to constrain a view to the edges of its superview:</p><pre>let subview = UIView()<br>view.addSubview(subview)</pre><pre>subview.snp.makeConstraints { (make) in<br>    make.top.bottom.left.right.equalTo(view)<br>}</pre><p>This will layout my subview the same way as the code above, but with one line instead of four.</p><p>I can also constrain the size of my subview. Below, I’m going to set the height and width of the subview and set it to the center of its superview:</p><pre>subview.snp.makeConstraints { (make) in<br>    make.width.equalTo(200)<br>    make.height.equalTo(200)<br>    make.centerX.equalTo(view)<br>    make.centerY.equalTo(view)<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*Tbq19GOnKbQPCl0dOtF12Q.png" /></figure><p>That example is pretty simple, but I repeated myself a lot. When setting constraints that have the same values, SnapKit allows me to chain constraints together like so:</p><pre>subview.snp.makeConstraints { (make) in<br>    make.width.height.equalTo(200)<br>    make.centerX.centerY.equalTo(view)<br>}</pre><p>This block will result in the same constraints as the one above. Just another way SnapKit helps to write cleaner code.</p><h4>Laying out subviews relative to each other</h4><p>When adding many subviews to a single view, it’s likely that you’ll want to layout subviews in relation to each other. In this example, I will:</p><ol><li>Add subview1 and constrain it to the left edge its superview</li><li>Add subview2 and constrain it to the right edge of the subview1</li></ol><pre>let subview1 = UIView()<br>let subview2 = UIView()<br>view.addSubview(subview1)<br>view.addSubview(subview2)</pre><pre>subview1.snp.makeConstraints { (make) in<br>    make.width.height.equalTo(100)<br>    make.left.equalTo(view)<br>}</pre><pre>subview2.snp.makeConstraints { (make) in<br>    make.width.height.equalTo(subview1)<br>    make.left.equalTo(subview1.snp.right)<br>}</pre><p>Up until now, I’ve wanted my constraints to be equal to the corresponding constraint for the relative view. For example, in make.left.equalTo(view)SnapKit sets the left of subview1 to the left of view. SnapKit will automatically match the constraint I set if I do not specify otherwise.</p><p>For the left constraint of subview2, I want to set it to the right edge of subview1. If I wrote make.left.equalTo(subview1) SnapKit would set the left edge of subview2 to the left edge of subview1. Instead, I use the right edge of subview1 which I grab by writing subview1.snp.right.</p><p>I can access any constraint of a view’s layout by adding snp as seen above.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*sWcRe94bA9dNUUbJSkKzeg.png" /><figcaption>subview 2 is constrained to the right of subview 1 with a constant of 0</figcaption></figure><p>Now that I have subview2 to the right of subview1, I’ll create some space between them by adding an <strong>offset</strong> to subview2.</p><pre>subview2.snp.makeConstraints { (make) in<br>    make.width.height.equalTo(subview1)<br>    make.left.equalTo(subview1.snp.right)<strong>.offset(50)</strong><br>}</pre><p>An offset can be appended at the end of any equalTo() to change the constant of that constraint. Now subview2 will have a constant of 50 on its leftconstraint.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*f70msAF6Nn69tSceL9f2Fg.png" /><figcaption>subview 2 is now constrained to subview 1 with a constant of 50</figcaption></figure><h4>Updating and animating constraints</h4><p>If you want your app to be the #NextBigThing everyone knows you’ll need to add a little flair! SnapKit provides a way to easily update constraints to create dynamic views.</p><p>Updating a constraint with SnapKit is almost identical to adding a new one. Here, I’ll update the constraint for subview1 from the previous example by changing the left edge constraint’s constant from 0 to 50:</p><pre>subview1.snp.updateConstraints { (make) in<br>   make.left.equalTo(50)<br>}</pre><p>And that’s it! My subview will update to the new constraints when the code block is run.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*4fq8ufgqHlY6-fmoIUdSpw.gif" /><figcaption>Clicking the button updates subview1’s constraints</figcaption></figure><p>You probably noticed that subview2 moved when I updated subview1 even though I didn’t update its constraints.subview2 is constrained to the right edge of subview1. When subview1 gets moved, subview2 will continue to honor the left constraint it has with subview1.</p><p>Now I’ll add an animation to smooth out the transition. If you’ve ever animated a view before, this syntax will be familiar:</p><pre>UIView.animate(withDuration: 0.3) {<br>    subview1.snp.updateConstraints { (make) in<br>        make.left.equalTo(50)<br>    }<br>    <br>    self.view.layoutIfNeeded()<br>}</pre><p>When animating updates on my constraints, I need to call layoutIfNeeded()on the subview’s parent. If I’m animating more than one view at once, I will need to call layoutIfNeeded() on the subview’s closest common superview.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*enXFakS5klYotI7_xQSNeA.gif" /></figure><p>updateConstraints() can only update existing constraints. Attempting to update a constraint that isn’t already in place will result in a fatal run time error.</p><p>If you want to add new constraints to your subview, use remakeConstraints(). <strong>remakeConstraints()</strong> <strong>will remove any existing constraints you have set on that subview</strong> and allow you to add new ones.</p><p>You can also use deactivate() to remove a constraint. Below I create, set, and them remove a constraint using deactivate():</p><pre>var constraint: Constraint!<br>let subview = UIView()</pre><pre>subview.snp.makeConstraints { (make) in<br>    constraint = make.height.equalTo(100).constraint<br>}</pre><pre>constraint.deactivate()</pre><p>You can also animate the removal of a constraint by deactivating it inside of an animation block.</p><p>So now you are a master of writing constraints programmatically. Storyboards seem like a joke now and there’s no reason to ever go back to them, right?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*pugkQrT4HOtoakIBLFu4og.jpeg" /><figcaption>How it feels building storyboards after reading this guide</figcaption></figure><p>Not really. Storyboards and nibs are still the fastest way to put together a view controller, and, if you are working with non-developers, they are the best way to show what the app will look like without sending a beta version.</p><p>Personally, I use both. In <a href="https://github.com/JakeShelley1/Todo-List-App-Swift/">the last app I built</a>, I added constraints both in code with SnapKit and using Auto Layout on storyboards and nibs, sometimes on the same view. In the end, you’ll have to decide which works best for the view you are building.</p><p><em>Thanks so much for reading! If you liked this story, follow me on </em><a href="https://twitter.com/JakeShelley3"><em>Twitter</em></a><em> where I post articles about product management, engineering, and design.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce0a6d9e76cf" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/how-to-use-snapkit-to-write-constraints-programmatically-for-ios-apps-ce0a6d9e76cf">How to Use SnapKit to Write Constraints Programmatically for iOS Apps</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>