<?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 Austin Louden on Medium]]></title>
        <description><![CDATA[Stories by Austin Louden on Medium]]></description>
        <link>https://medium.com/@austinlouden?source=rss-8a95264b5c47------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*vf2OvmN2JjcSCgfXlKzJJg.jpeg</url>
            <title>Stories by Austin Louden on Medium</title>
            <link>https://medium.com/@austinlouden?source=rss-8a95264b5c47------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 10:49:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@austinlouden/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[Chaining logical expressions with commas in Swift]]></title>
            <link>https://medium.com/@austinlouden/chaining-logical-expressions-with-commas-in-swift-c3755ee784e9?source=rss-8a95264b5c47------2</link>
            <guid isPermaLink="false">https://medium.com/p/c3755ee784e9</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[programming-languages]]></category>
            <category><![CDATA[swift-programming]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Austin Louden]]></dc:creator>
            <pubDate>Fri, 17 Jul 2020 17:49:20 GMT</pubDate>
            <atom:updated>2020-07-17T17:49:20.094Z</atom:updated>
            <content:encoded><![CDATA[<p><em>With Swift 5.2</em></p><p>You may remember that it’s possible to chain if let statements with a comma.</p><pre>let o1:Int? = 1<br>let o2:Int? = 2</pre><pre>if let one = o1, let two = o2 {<br>  print(one, two)<br>}</pre><pre>// Output: 1 2</pre><p>The comma here is acts as equivalent to the logical &amp;&amp;. The code inside the if statement will not execute unless <em>both</em> o1 and o2 are not nil.</p><p>It’s also possible to chain a logical expression after the let statement. In the case below, we check that one is not nil, and also that 1 &gt; 0.</p><pre>let o1:Int? = 1</pre><pre>if let one = o1, one &gt; 0 {<br>  print(one)<br>}</pre><pre>// Output: 1</pre><p>However, an interesting side effect of this syntax is , and &amp;&amp; can be used interchangeably. In other words, we don’t need to begin our statement with if let to be allowed to used a comma. This means the following code will compile and run as expected:</p><pre>let one = 1<br>let two = 2</pre><pre>if one &gt; 0, two &gt; 1 {<br>  print(one, two)<br>}</pre><pre>// Output: 1, 2</pre><pre>if one &gt; 0 &amp;&amp; two &gt; 1 {<br>  print(one, two)<br>}</pre><pre>// Output: 1, 2</pre><p>The nuanced difference is that one &gt; 0 &amp;&amp; two &gt; 1 is evaluated as one whole expression, whereas one &gt; 0, two &gt; 1 is treated as two independent expressions. Which way you choose to go with is more of a stylistic decision.</p><p>I’d argue that for simple expressions, one &gt; 0 &amp;&amp; two &gt; 1 is more readable. The &amp;&amp; clearly conveys the intent of the expression. However, for complex expressions, relying on &amp;&amp; requires more thought about parentheses and order of operations. I’d argue that this is less readable and more error prone compared to the comma-based style.</p><p>Using &amp;&amp;:</p><pre>if (this || that) &amp;&amp; something() &amp;&amp; (another == 1 || example == 6)</pre><p>Using ,:</p><pre>if this || that, something(), another == 1 || example == 6</pre><p>Because of this, I’ve chosen to use commas whenever logical expressions go beyond one &amp;&amp;.</p><p>Let me know if you have any thoughts, and check out this post on <a href="https://forums.swift.org/t/is-equal-to/31121">forums.swift.org</a> for a longer discussion on this bit of syntax.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c3755ee784e9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Your First iOS App: 100% Programmatically (Swift)]]></title>
            <link>https://medium.com/@austinlouden/your-first-ios-app-100-programmatically-swift-cc05bec55f62?source=rss-8a95264b5c47------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc05bec55f62</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Austin Louden]]></dc:creator>
            <pubDate>Sun, 27 Mar 2016 03:38:35 GMT</pubDate>
            <atom:updated>2016-03-28T04:57:43.601Z</atom:updated>
            <content:encoded><![CDATA[<h4>Part 3</h4><p><em>This is Part 3 of a tutorial that follows </em><a href="https://developer.apple.com/library/ios/referencelibrary/GettingStarted/DevelopiOSAppsSwift/Lesson2.html#//apple_ref/doc/uid/TP40015214-CH5-SW1"><em>Apple’s “Build a Basic UI”</em></a><em>, but implements all of the user interface elements programmatically. View the </em><a href="https://github.com/austinlouden/first"><em>full project</em></a><em> on GitHub. View </em><a href="https://medium.com/@austinlouden/your-first-ios-app-100-programmatically-swift-70e76ac9b18b"><em>Part 1</em></a><em> or </em><a href="https://medium.com/@austinlouden/your-first-ios-app-100-programmatically-swift-f239c608922f"><em>Part 2</em></a><em>.</em></p><p>Now that we’ve got our text field, button, and label, we can get everything working together.</p><p>The goal is to change the label text when we hit return on the keyboard, then reset it to our original text when we press the button.</p><p><strong>Changing the label text with the keyboard</strong></p><p>To do this, we need to implement a UITextField delegate method. <a href="https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Protocols.html#//apple_ref/doc/uid/TP40014097-CH25-ID276">Delegates</a> and protocols are an important component of Swift and Objective-C. I’m not going to go into detail here, but you’ll notice that these methods will often give us an opportunity to do something when an event happens.</p><p>There’s a lot you can learn from trying it out. At the top of your file, modify the class declaration line to add the UITextFieldDelegate like so:</p><pre>class ViewController: UIViewController, UITextFieldDelegate {</pre><p>The is essentially shorthand for: “the name of this class is ViewController, it’s a subclass of UIViewController, and <em>conforms to the UITextFieldDelegate protocol</em>.”</p><p>⌘+Click on UITextFieldDelegate once you’ve added it. Here we can see the list of the functions in the UITextFieldDelegate protocol. I’ve included a screenshot of a few.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8YiIbr_uMpQzkPu7dwSFxw.png" /></figure><p>Notice that all of these functions are prefixed with the word “optional”, meaning a class which conforms to the UITextFieldDelegate protocol can implement these, but does not have to. This is not the case for all protocols.</p><p>Next, we need to let our instance UITextField know that our ViewController implements its protocol methods. You can set this in init, next to where you set the other textField property.</p><pre>textField.delegate = self</pre><p>Our app needs to implement the “textFieldShouldReturn” method, which is called when a user presses the return key. You can put this below viewDidLoad.</p><pre>func textFieldShouldReturn(textField: UITextField) -&gt; Bool {<br>  label.text = textField.text<br>  return false<br>}</pre><p>When return is pressed, we simply set the text of the label equal to the text of the text field.</p><p>Build and run the app. Now, if you type inside the box and hit enter, the label should update!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*PAcupqCSQw1cMbeP_lrhYA.png" /></figure><p><strong>Resetting the text when pressing the button</strong></p><p>Below viewDidLoad, create another function that will be called when the button is pressed.</p><pre>func buttonPressed() {<br>  label.text = “hello!”<br>}</pre><p>Finally, below where you set the textField delegate add this line, which hooks up the button to the “buttonPressed” method you implemented above.</p><pre>button.addTarget(self, action: #selector(ViewController.buttonPressed), forControlEvents: .TouchUpInside)</pre><p>Build and run your app. Everything should work as expected — try changing the text of the label by typing in the text field and hitting return, then press the button.</p><p><strong>A final word</strong></p><p>While this code will work on all iOS devices, writing the layout programmatically means that it will not adapt to them. However — since many companies have chosen to forgo storyboards and interface builder — there are some great alternatives. When you feel ready to make a decision, I’d recommend checking out <a href="http://snapkit.io/">SnapKit</a> or <a href="http://asyncdisplaykit.org/">AsyncDisplayKit</a>.</p><p>Feel free to reach out to me with comments or corrections! I’m <a href="https://twitter.com/austinlouden">@austinlouden</a> on Twitter.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cc05bec55f62" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Your First iOS App: 100% Programmatically (Swift)]]></title>
            <link>https://medium.com/@austinlouden/your-first-ios-app-100-programmatically-swift-f239c608922f?source=rss-8a95264b5c47------2</link>
            <guid isPermaLink="false">https://medium.com/p/f239c608922f</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[learning]]></category>
            <dc:creator><![CDATA[Austin Louden]]></dc:creator>
            <pubDate>Sun, 27 Mar 2016 03:38:13 GMT</pubDate>
            <atom:updated>2016-03-28T04:55:05.658Z</atom:updated>
            <content:encoded><![CDATA[<h4>Part 2</h4><p><em>This is Part 2 of a tutorial that follows </em><a href="https://developer.apple.com/library/ios/referencelibrary/GettingStarted/DevelopiOSAppsSwift/Lesson2.html#//apple_ref/doc/uid/TP40015214-CH5-SW1"><em>Apple’s “Build a Basic UI”</em></a><em>, but implements all of the user interface elements programmatically. View the </em><a href="https://github.com/austinlouden/first"><em>full project</em></a><em> on GitHub. View </em><a href="https://medium.com/@austinlouden/your-first-ios-app-100-programmatically-swift-70e76ac9b18b"><em>Part 1</em></a><em> or </em><a href="https://medium.com/@austinlouden/your-first-ios-app-100-programmatically-swift-cc05bec55f62"><em>Part 3</em></a><em>.</em></p><p>The next step is to add elements to the user interface — a text field, a button, and a label.</p><p><strong>The label</strong></p><p>First, we’ll need an init method, which is called when the view controller is created.</p><p>Above the viewDidLoad method, we can create our own init method. Right now, we’ll just call the superclass’s init method (UIViewController).</p><pre>init() {<br>  super.init(nibName: nil, bundle: nil)<br>}</pre><p>After we make this, Xcode will complain that we’re not implementing the other initializer of UIViewController:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nxygxfYjbdHa96p8NvuUPA.png" /></figure><p>Clicking on the warning will auto-generate the following code:</p><pre>required init?(coder aDecoder: NSCoder) {<br>  fatalError(“init(coder:) has not been implemented”)<br>}</pre><p>Where do these required initializer’s come from? If you ⌘+Click on “UIViewController” at the top of the file, you can see the public parts of Apple’s UIViewController class. There’s a comment above the first initializer which explains why we can’t just call super.init() with no arguments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*skyd0WiRYLxQCoPN77VaNw.png" /></figure><p>Back to creating the label. Above your init method, write the line:</p><pre>let label = UILabel()</pre><p>Because we used “let” instead of “var”, the label can be set once and only once. You can set the label and it’s text property in the init method like so:</p><pre>init() {<br>  super.init(nibName: nil, bundle: nil)<br>  <br>  label.text = “hello!”<br>}</pre><p>Then, in viewDidLoad, set its frame and add it to the view hierarchy.</p><pre>override func viewDidLoad() {<br>  super.viewDidLoad()<br>  self.view.backgroundColor = UIColor.whiteColor()</pre><pre>  label.frame = CGRectMake(20, 40, CGRectGetWidth(self.view.frame),  20)<br>  self.view.addSubview(label)<br>}</pre><p>We do this inside viewDidLoad because it’s best practice to not access the view controller’s view property (i.e. self.view) until this method is called.</p><p>Build and run the app. You should your label in the upper left of the screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/1*w5pp_yieUpxwFRjlWQj9_w.png" /></figure><p><strong>The text field</strong></p><p>Create the text field constant below your label.</p><pre>let textField = UITextField()</pre><p>We should also set the border style so the text field shows up on the screen (the default text field does not have a background). You can do this below where you set label.text in the init method.</p><pre>textField.borderStyle = .RoundedRect</pre><p>Finally, in viewDidLoad, set the text view’s frame and it to the subview. Make sure this is below your label code.</p><pre>textField.frame = CGRectMake(20, CGRectGetMaxY(label.frame) + 10, CGRectGetWidth(self.view.frame) — 40, 30)<br>self.view.addSubview(textField)</pre><p>I’m using a lot of different numbers in the CGRectMake method. It’s best practice to put these numbers into constants so they can be reused and easily modified, but I’ll leave these as is for the sake of this tutorial.</p><p>Build and run the app — you should now see the text field box below your label. Clicking on the text field allows you to type using your keyboard, however the simulator hides the phone’s keyboard by default. You can show it by pressing ⌘+K.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/816/1*gblhblVZNwExr5UK6UGStg.png" /></figure><p><strong>The button</strong></p><p>Create the button constant as you’ve done before. This time, we’ll use a UIButton initializer which lets us set a type property.</p><pre>let button = UIButton(type: .RoundedRect)</pre><p>UIButton also has a method <a href="https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIButton_Class/#//apple_ref/occ/instm/UIButton/setTitle:forState:">- setTitle:forState:</a>, which lets us change the button title depending on whether it’s pressed or not. “.Normal”, which is short for UIControlState.Normal, corresponds to the regular, unpressed state. You can set this below the textField.borderStyle line in init.</p><pre>button.setTitle(“Set Default Label Text”, forState: .Normal)</pre><p>In viewDidLoad, below your text field code, set the frame of the button and add it to the view.</p><pre>button.frame = CGRectMake(20, CGRectGetMaxY(textField.frame) + 10, CGRectGetWidth(self.view.frame) — 40, 30)<br>self.view.addSubview(button)</pre><p>Build and run the app. At this point, you should have all the user interface components ready to go.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/816/1*BWvQuy4zG2_EjxuDkvTxcw.png" /></figure><p>You can tap on the button, but it won’t do anything (yet!). We’ll hook everything up the final post, <a href="https://medium.com/@austinlouden/your-first-ios-app-100-programmatically-swift-cc05bec55f62"><em>Part 3</em></a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f239c608922f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Your First iOS App: 100% Programmatically (Swift)]]></title>
            <link>https://medium.com/@austinlouden/your-first-ios-app-100-programmatically-swift-70e76ac9b18b?source=rss-8a95264b5c47------2</link>
            <guid isPermaLink="false">https://medium.com/p/70e76ac9b18b</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[learning]]></category>
            <dc:creator><![CDATA[Austin Louden]]></dc:creator>
            <pubDate>Sun, 27 Mar 2016 03:37:29 GMT</pubDate>
            <atom:updated>2016-03-27T05:46:51.027Z</atom:updated>
            <content:encoded><![CDATA[<h4>Part 1</h4><p><em>Three years ago, I wrote the </em><a href="https://medium.com/@austinlouden/your-first-ios-app-100-programmatically-67cc41319bd8#.gfurjklc4"><em>same tutorial</em></a><em> for Xcode 4.6. Times have changed since then.</em></p><p><em>This is Part 1 of a tutorial that follows </em><a href="https://developer.apple.com/library/ios/referencelibrary/GettingStarted/DevelopiOSAppsSwift/Lesson2.html#//apple_ref/doc/uid/TP40015214-CH5-SW1"><em>Apple’s “Build a Basic UI”</em></a><em>, but implements all of the user interface elements programmatically. View the </em><a href="https://github.com/austinlouden/first"><em>full project</em></a><em> on GitHub. View </em><a href="https://medium.com/@austinlouden/your-first-ios-app-100-programmatically-swift-f239c608922f"><em>Part 2</em></a><em> or </em><a href="https://medium.com/@austinlouden/your-first-ios-app-100-programmatically-swift-cc05bec55f62"><em>Part 3</em></a><em>.</em></p><p>I created this tutorial for developers transitioning to iOS that don’t want to deal with Storyboards or Interface Builder. Here’s what we’re building, from <a href="https://developer.apple.com/library/ios/referencelibrary/GettingStarted/DevelopiOSAppsSwift/Lesson3.html#//apple_ref/doc/uid/TP40015214-CH22-SW1">Apple’s documentation</a>:</p><blockquote>You can select the text field and type text into it. When you click the Done button on the keyboard, the keyboard is dismissed and the label text changes to display the text in the text field. When you click the Set Default Label Text button, the label changes from what’s currently displayed in the label to Default Text.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/340/1*oiNEMTsnZq_Ljs5JmHqBaw.png" /><figcaption>The finished sample app.</figcaption></figure><p>First, open Xcode and select “Create a new Xcode project”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/490/1*OKdh4QQubY2_LYvzr1r-7g.png" /></figure><p>Select “Single View Application”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*JtGWN3oD7LQAmTcw2Q1jig.png" /></figure><p>Choose Swift as the language, and fill out any other settings — they shouldn’t matter for this project, but you can match mine if you like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*9KvnEUNwslpGWfCfZDHntQ.png" /></figure><p>From the file selector on the left, right click Main.storyboard and delete it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/515/1*wo_EABYC8zX8G5ro4hDtLg.png" /></figure><p>Then, click on the project file at the top of the file selector (the blue icon that says “First”). This should display some app configuration options. Under the Deployment Info section, change the Main Interface option to be blank.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*06RTnrG-Q7uN0SVCLPz6qQ.png" /></figure><p>Now that we’ve removed storyboards from the project (you can look into removing the storyboard for the launch screen later), we can get to some code.</p><p>Open the AppDelegate.swift file. The App Delegate file is your application’s way of communicating with the operating system, and includes several useful methods.</p><p>We’ll mostly be dealing with “application didFinishLaunchingWithOptions”, which is called immediately after the app starts.</p><p>Add the following lines, so your method looks like this:</p><pre>func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -&gt; Bool {<br>  // Override point for customization after application launch.<br>  <br>  let rootViewController = ViewController()</pre><pre>  window = UIWindow(frame: UIScreen.mainScreen().bounds)<br>  window?.rootViewController = rootViewController<br>  window?.makeKeyAndVisible()</pre><pre>  return true<br>}</pre><p>Notice in the left sidebar that the class ViewController.swift was already created for you. This is the class that you’re initializing in the code above. It subclasses <a href="https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/">UIViewController</a>, which is a fundamental class in iOS development.</p><p>After, we set the window’s rootViewController property to the view controller we created. Every app must have a root view controller.</p><p>Open up the ViewController.swift file. Here you’ll find some functions Apple has predefined for you. There are several stages in what’s called the <a href="https://developer.apple.com/library/ios/referencelibrary/GettingStarted/DevelopiOSAppsSwift/Lesson4.html">view controller lifecycle</a>, and viewDidLoad is one of them.</p><p>In the viewDidLoad function, add another line to change your background color to white.</p><p>The code in this function should look like the block below:</p><pre>override func viewDidLoad() {<br>  super.viewDidLoad()<br>  self.view.backgroundColor = UIColor.whiteColor()<br>}</pre><p>Build and run the app by clicking on the play button in the top left. The iOS simulator should launch with a blank white screen.</p><p>In the next part of this tutorial, we’ll handle all of the on-screen elements. Continue to <a href="https://medium.com/@austinlouden/your-first-ios-app-100-programmatically-swift-f239c608922f"><em>Part 2</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=70e76ac9b18b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Swift Resources]]></title>
            <link>https://medium.com/@austinlouden/swift-content-list-387dc4fa12a5?source=rss-8a95264b5c47------2</link>
            <guid isPermaLink="false">https://medium.com/p/387dc4fa12a5</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[learning]]></category>
            <dc:creator><![CDATA[Austin Louden]]></dc:creator>
            <pubDate>Sat, 26 Mar 2016 08:03:30 GMT</pubDate>
            <atom:updated>2016-11-01T05:26:47.686Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve been learning a lot about <a href="http://www.apple.com/swift/">Swift</a> lately, and thought it might be helpful to aggregate some materials I’ve come across. I’ll continue to update as I find more. This list is mostly for people already familiar with iOS development that are considering switching.</p><p><strong>Reading:</strong></p><ul><li><a href="https://engineering.linkedin.com/ios/our-swift-experience-slideshare">Our Swift Experience at SlideShare</a></li><li><a href="http://making.duolingo.com/real-world-swift">Real World Swift</a> | Duolingo</li><li><a href="https://www.objc.io/issues/16-swift/">Swift</a> | objc.io</li><li><a href="http://artsy.github.io/blog/2015/09/24/mvvm-in-swift/">MVVM in Swift</a> | Artsy</li><li><a href="http://matthijshollemans.com/2015/07/22/mixins-and-traits-in-swift-2/">Mixins and Traits in Swift 2.0</a> by Matthijs Hollemans</li></ul><p><strong>Talks:</strong></p><ul><li><a href="https://realm.io/news/gotocph-ash-furrow-best-practices-swift/">Emerging Best Practices in Swift</a> by Ash Furrow</li><li><a href="https://realm.io/news/altconf-ash-furrow-functional-reactive-swift/">Functional Reactive Awesomeness in Swift</a> by Ash Furrow</li><li><a href="https://realm.io/news/slug-keith-smiley-embrace-immutability/">Embrace Immutability</a> by Keith Smiley</li><li><a href="https://realm.io/news/doios-natasha-murashev-protocol-oriented-mvvm/">Introduction to Protocol-Oriented MVVM</a> by Natasha the Robot</li><li><a href="https://developer.apple.com/videos/play/wwdc2015/408/">Protocol-Oriented Programming in Swift</a> by Dave Abrahams</li><li><a href="https://www.youtube.com/watch?v=XWoNjiSPqI8">Protocols with Associated Types</a> by Alexis Gallagher</li></ul><p>A few key takeaways:</p><ol><li>Consider using MVVM instead of MVC. There are a lot of reasons for this, but the benefits mostly stem from reducing the number of things a view controller is responsible for. This makes code cleaner and tests easier to write.</li><li>Use immutable models, and prefer constants over variables. This makes code safer, since you don’t have to worry about faulty model objects. If something fails, it will fail at the model creation level — not somewhere else when you’re trying to do things with model properties.</li><li>Consider using structs and protocols instead of classes. Every time I watch <a href="https://developer.apple.com/videos/play/wwdc2015/408/">Dave Abrahams’ talk on this</a>, I learn something new. Protocols can be used to handle situations that are difficult to solve with inheritance. <a href="http://matthijshollemans.com/2015/07/22/mixins-and-traits-in-swift-2/">Matthijs Hollemans writes</a>, “Inheritance is often used as a mechanism for code reuse, but protocol extensions let you reuse code without forcing you into a superclass-subclass relationship.”</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=387dc4fa12a5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Your First iOS App: 100% Programmatically]]></title>
            <link>https://medium.com/@austinlouden/your-first-ios-app-100-programmatically-ca333d14a64c?source=rss-8a95264b5c47------2</link>
            <guid isPermaLink="false">https://medium.com/p/ca333d14a64c</guid>
            <dc:creator><![CDATA[Austin Louden]]></dc:creator>
            <pubDate>Sat, 30 Nov 2013 02:18:51 GMT</pubDate>
            <atom:updated>2016-03-27T04:41:26.348Z</atom:updated>
            <content:encoded><![CDATA[<h4>Part 2</h4><blockquote><em>This tutorial is for Xcode 4.6, and was written in 2013. </em><a href="https://medium.com/@austinlouden/your-first-ios-app-100-programmatically-swift-70e76ac9b18b"><em>Check out my updated version (in Swift!)</em></a><em>, using Xcode 7.3/iOS 9.3.</em></blockquote><p>The next step is to add elements to the user interface — a text field, a button, and a label.</p><p><strong>1. The Text Field</strong></p><p>Go back to your MainViewController.m file. Similar to the app delegate, this comes with some helpful methods to handle different points in the life cycle of the UIViewController class.</p><p>First we need to create class properties for the text field and the label. Creating a property allows instances of an object to be accessed anywhere in the class, as opposed to just within the scope of one function. We’ll need to do this to pass a string from the text field to the label.</p><p>Private properties can be declared between the lines below in the MainViewController.m file.</p><pre>@interface MainViewController()<br>@end</pre><p>So we can add in the lines:</p><pre>@interface MainViewController()</pre><pre>@property (nonatomic, strong) UITextField *textField;<br>@property (nonatomic, strong) UILabel *label;</pre><pre>@end</pre><p>You might be wondering what the “nonatomic, strong” means — the short answer is that it has to do with memory management. You can <a href="http://stackoverflow.com/questions/9859719/xcode-property-attributes-nonatomic-copy-strong-weak">read more about it here</a>.</p><p>Now find the “viewDidLoad” method, which is executed immediately after the view is created and loaded on screen — right now it should look like this:</p><pre>- (void)viewDidLoad<br>{<br> [super viewDidLoad];<br> // Do any additional setup after loading the view.<br>}</pre><p>Time to create the text field. Using the “self.” prefix references the class property we created above. You can find more about class properties and the “self dot” syntax <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/EncapsulatingData/EncapsulatingData.html#//apple_ref/doc/uid/TP40011210-CH5-SW2">here</a>.</p><pre>- (void)viewDidLoad<br>{<br> [super viewDidLoad];<br> // Do any additional setup after loading the view.<br> <br> /*<br> this creates the text field and sets the frame<br> “CGRectMake” creates the frame with (x,y,width,height)<br> where x and y are are pixel distances from the top left<br> of the screen<br> */<br> self.textField = [[UITextField alloc]<br> initWithFrame:<br> CGRectMake(10.0f, 30.0f, <br> 300.0f, 30.0f)];<br> <br> //changes the border style so the text field appears on screen<br> self.textField.borderStyle = UITextBorderStyleRoundedRect;<br> <br> /*<br> add the text field to the main view.<br> Note: UITextField (along with a number of<br> other UI classes are subclasses of<br> UIView, which means they can be<br> added onto the view hierarchy<br> */<br> [self.view addSubview:self.textField];<br> <br>}</pre><p>If you run the app, you should now see the text field at the top of the screen. Clicking inside will bring up the keyboard and allow you to type. While the keyboard appears automatically, we have to add to code make it disappear ourselves.</p><p>The key is implementing a “delegate method” of the UITextField. Delegate methods are like helper functions for the objects in your application, and can sometimes help pass data between two classes. The delegate method we need to dismiss the keyboard is called “textFieldShouldReturn”, a function that is called every time the user presses the “return” button on the keyboard.</p><p>Information about a class’s delegate methods is in Apple’s documentation. You can find the “textFieldShouldReturn” method in the <a href="http://developer.apple.com/library/ios/#documentation/uikit/reference/UITextFieldDelegate_Protocol/UITextFieldDelegate/UITextFieldDelegate.html">UITextFieldDelegate reference article</a>.</p><p>Add it below your viewDidLoad method:</p><pre>- (BOOL)textFieldShouldReturn:(UITextField *)textField {</pre><pre>} </pre><p>Dismiss the text field programmatically by adding the following lines:</p><pre>- (BOOL)textFieldShouldReturn:(UITextField *)textField {<br> //this tells the operating system to remove<br> //the keyboard from the forefront<br> [textField resignFirstResponder];</pre><pre> //returns NO. Instead of adding a line break,<br> //the text field resigns<br> return NO;<br>}</pre><p>We need to do a few more things before this works. Go back to the viewDidLoad method where you created the text field. Right below the alloc, init line, add</p><pre>self.textField.delegate = self;</pre><p>This lets the application know where to look for the implementation of the delegate methods, which in this case is inside Self — a reference to our MainViewController class.</p><p>The last thing we need to do is update the MainViewController.h file. In the .h file, you’ll find the line:</p><pre>@interface MainViewController : UIViewController</pre><p>Change it to:</p><pre>@interface MainViewController : UIViewController &lt;UITextFieldDelegate&gt;</pre><p>This tells the MainViewController that it implements delegate methods of a UITextField object. Run the app — pressing the return button should now dismiss the text field.</p><p><strong>2. The Button</strong></p><p>We’ll create the label in the viewDidLoad method as well. Start below the line</p><pre>[self.view addSubview:self.textField];</pre><p>You can initialize a button the same way the text field was initialized (with the alloc, initWithFrame methods), but because we’re just using a default button I do it a bit differently here with a UIButton class method. Note that if you try the alloc/init way, you have to set the button’s background for it to appear.</p><pre>//initialize the button with the default, rounded rect type<br>UIButton *button = <br> [UIButton buttonWithType:UIButtonTypeRoundedRect];</pre><pre>//set the button’s frame<br>button.frame = CGRectMake(110.0f, 200.0f, 100.0f, 30.0f);</pre><pre>//set the target, action, and control event.<br>//more about this in the paragraph below<br>[button addTarget:self <br> action:@selector(buttonPressed) <br> forControlEvents:UIControlEventTouchUpInside];</pre><pre>//set the title<br>[button setTitle:@”Press Me!” forState:UIControlStateNormal];</pre><pre>//add the button to the main view<br>[self.view addSubview:button];</pre><p>This takes care of most of the button’s properties. The addTarget, action, forControlEvents method allows you to specify a function that’s called when the button is pressed. The target is the object to which the action message is sent — in this case, self. The action after the button is pressed is identical to what would happen if you called</p><pre>[self buttonPressed];</pre><p>Wrapped in the @selector() block is the name of the function to be called when the button is pressed — we still need to implement this.</p><p>The control event specifies the type of interaction required to trigger the button. Apple’s “UIControlEventTouchUpInside” is the way to specify just a simple tap.</p><p>Now we can create the shell of the buttonPressed function. We need to create the label before we can implement the full thing.</p><p>In between viewDidLoad and textFieldShouldReturn, create the buttonPressed method:</p><pre>- (void)buttonPressed {<br> <br>}</pre><p>We’ll come back to this after we create the label.</p><p><strong>3. The Label</strong></p><p>I’ve saved the easiest for last. We’ll create the label below the line</p><pre>[self.view addSubview:button]</pre><p>The label is initialized much like the textfield, and is ready to go with just three lines:</p><pre>self.label = [[UILabel alloc] <br> initWithFrame:CGRectMake(115.0f, 150.0f, 200.0f, 30.0f)];<br>self.label.text = @”Hello World!”;<br>[self.view addSubview:self.label];</pre><p>Run the app, and you should see the familiar “Hello World!” above your button.</p><p><strong>4. Changing the Label Text</strong></p><p>Only one thing left to do. Since you’ve already created the shell of the button pressed method, we just have to add a line that sets the label text equal to the string in the text field. This is done with one line inside buttonPressed:</p><pre>- (void)buttonPressed {<br> self.label.text = self.textField.text;<br>}</pre><p>That’s it! Run the app and try it out.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ca333d14a64c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Your First iOS App: 100% Programmatically]]></title>
            <link>https://medium.com/@austinlouden/your-first-ios-app-100-programmatically-67cc41319bd8?source=rss-8a95264b5c47------2</link>
            <guid isPermaLink="false">https://medium.com/p/67cc41319bd8</guid>
            <dc:creator><![CDATA[Austin Louden]]></dc:creator>
            <pubDate>Sat, 30 Nov 2013 02:18:08 GMT</pubDate>
            <atom:updated>2016-03-27T04:41:04.552Z</atom:updated>
            <content:encoded><![CDATA[<h4>Part 1</h4><blockquote>This tutorial is for Xcode 4.6, and was written in 2013. <a href="https://medium.com/@austinlouden/your-first-ios-app-100-programmatically-swift-70e76ac9b18b">Check out my updated version (in Swift!)</a>, using Xcode 7.3/iOS 9.3.</blockquote><p><em>This is Part 1 of a tutorial that follows Apple’s old “Your First iOS App” tutorial, but implements all of the user interface elements programmatically. </em><a href="https://medium.com/on-coding/ca333d14a64c"><em>View Part 2 here</em></a><em> or </em><a href="https://github.com/austinlouden/programmatically"><em>view the complete code on Github</em></a><em>. Discussion on </em><a href="https://news.ycombinator.com/item?id=5559216"><em>Hacker News</em></a><em>.</em></p><p>I created this tutorial for developers transitioning to iOS that don’t want to deal with Storyboarding or Interface Builder. It implements the “Hello World” app from Apple’s documentation entirely in code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/314/1*XtFFvHBaMexmOAIrYx6qoQ.png" /></figure><p>From Apple’s documentation:</p><blockquote>When you run the finished app, you click inside the text field to reveal the system-provided keyboard. After you use the keyboard to type your name, you dismiss it (by clicking its Done key) and then you click the Hello button to see the string “Hello, <em>Your Name</em>!“ in the label between the text field and the button.</blockquote><p>First, open Xcode and click on “Create a new Xcode project” I’m using version 4.6.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*Pfh-8xevyjCJGl5_4aEL3Q.png" /></figure><p>Use an empty application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*aJ1SXn8eRS-9B7ORRId90Q.png" /></figure><p>Fill out the remaining fields. Make sure “Use Automatic Reference Counting” (this is now enabled by default in XCode 5) and “Include Unit Tests” are checked. Core Data isn’t necessary for this tutorial.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*LMu9fCSSvo--B8Y2cexbSw.png" /></figure><p>Even though we chose to create an “Empty Application”, Xcode still created some default files. Navigate to the AppDelegate.m file by clicking the file browser on the left side of the screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*VH1qd36VQtBZjtkKbNkBVw.png" /></figure><p>The App Delegate file is your application’s way of communicating with the operating system, and includes several useful methods.</p><p>We’ll mostly be dealing with “application didFinishLaunchingWithOptions”, which is called immediately after the application launches.</p><p>If you click on the Run button in the top left, your application should build with a blank white screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/230/1*ZWRMYqOkXtIJSmaXEI8Vkw.jpeg" /></figure><p>You might have noticed a warning:</p><blockquote>“Application windows are expected to have a root view controller at the end of application launch”.</blockquote><p>Don’t worry, we’ll set this next, but first we have to create a ViewController class. Click on File, New, File…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/1*KHm9lzyBMfB_3JVK_pJRaw.png" /></figure><p>In the Cocoa Touch section, select Objective-C class and click Next.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*vCdNiXabyS2VDrXi8LsR4A.png" /></figure><p>You can choose the name of your class, but make sure to set it as a subclass of UIViewController below. I named mine “MainViewController”. The UIViewController is a fundamental class of iOS development, and is used to make and handle interaction with elements in the user interface. Click Next, and then Create.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*sNPAl3kbZeex5ax0lUn5AA.png" /></figure><p>You should now have MainViewController.m and MainViewController.h files with some boilerplate code inside. We’ll come back to those in a bit — for now, go back to your AppDelegate.m file.</p><p>First, make sure to import your MainViewController class at the top of the file:</p><pre>#import “AppDelegate.h”<br>#import “MainViewController.h”</pre><p>Next, take a look at the “application didFinishLaunching” method — it should contain some default code matching the one below:</p><pre>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions<br>{<br> self.window = [[UIWindow alloc] <br>initWithFrame:[[UIScreen mainScreen] bounds]];<br> // Override point for customization after application launch.<br> self.window.backgroundColor = [UIColor whiteColor];<br> [self.window makeKeyAndVisible];<br> return YES;<br>}</pre><p>It’s here that we set the “root view controller” property — or the view that is displayed when the application launches.</p><pre> — (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions<br>{<br> self.window = [[UIWindow alloc] <br> initWithFrame:[[UIScreen mainScreen] bounds]];<br> <br> // Override point for customization after application launch.<br> self.window.backgroundColor = [UIColor whiteColor];<br> <br> /* create an instance of our view controller<br> then set it as the window’s root view controller<br> */<br> MainViewController *viewController = <br> [[MainViewController alloc] init];<br> <br> self.window.rootViewController = viewController;<br> <br> [self.window makeKeyAndVisible];<br> return YES;<br>}</pre><p>Running the app again should still give you a white screen, but this time the warning will disappear. In the next part of this tutorial, we’ll handle all of the on-screen elements.</p><p><a href="https://medium.com/on-coding/ca333d14a64c">Continue to Part 2</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=67cc41319bd8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>