<?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 Dan Wickes on Medium]]></title>
        <description><![CDATA[Stories by Dan Wickes on Medium]]></description>
        <link>https://medium.com/@danwickes?source=rss-3a10d8ddaf4b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Xgav5rCriJfZOLUqOnFmAg.jpeg</url>
            <title>Stories by Dan Wickes on Medium</title>
            <link>https://medium.com/@danwickes?source=rss-3a10d8ddaf4b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 10:05:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@danwickes/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[I’m new to Swift.]]></title>
            <link>https://medium.com/@danwickes/i-m-new-to-swift-9eb368677b01?source=rss-3a10d8ddaf4b------2</link>
            <guid isPermaLink="false">https://medium.com/p/9eb368677b01</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[optionals]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Dan Wickes]]></dc:creator>
            <pubDate>Sun, 20 Dec 2015 00:22:28 GMT</pubDate>
            <atom:updated>2015-12-20T00:22:28.286Z</atom:updated>
            <content:encoded><![CDATA[<p>I’m new to Swift. Often, I write things that aren’t totally correct. One of these moments happened to me while attempting to unwrap an optional. I wanted to execute the body of an if statement only if I was able to unwrap the contents of an optional. Therefore, I would like to specify that my String is really there, which should be done like String!, right? Here is a reader friendly version of the code I wrote:</p><pre>func gonnaBeNil() -&gt; String? {<br>    return nil<br>}</pre><pre>if let s : String! = gonnaBeNil() {<br>    print(“String!”)<br>}</pre><p>But this code printed out String!. I found the fix quickly, which is simply to delete the ! from the type (or not specify at all, either of the next two examples would work as I expected (and display no output):</p><pre>if let s : String = gonnaBeNil() {<br>    print(“String”)<br>}</pre><pre>if let s = gonnaBeNil() {<br>    print(“String”)<br>}</pre><p>Something that I found to be particularly strange was this next example, which printed out String?.</p><pre>if let s : String? = gonnaBeNil() {<br>    print(&quot;String?&quot;)<br>}</pre><p>So, the example that shouldn’t be able to be nil is the same as the one that should be able to be nil, according to my understanding of the feature. So, what’s really going on with this gonnaBeNil() function call? I double checked that and was surprised. I did this with the dynamicType property, which allows you to determine the type of an expression at runtime.</p><pre>gonnaBeNil().dynamicType</pre><p>This gave me Optional&lt;String&gt;.Type. Weird, so I guess it wasn’t actually nil then. String! and String? both expect to be this type, so that would explain why the body of the if statement runs. String, however, expects the type String, and therefore the body does not run. As a sanity check, I ran this:</p><pre>func alsoGonnaBeNil() -&gt; String? {<br>   return .None<br>}</pre><pre>alsoGonnaBeNil().dynamicType</pre><p>Which was also of type Optional&lt;String&gt;. So, I guess a String! isn’t really a String, it’s just overcompensating. All the code with output is below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/469/1*A4EKM2cjUAzUr46zXvWB2g.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9eb368677b01" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Navigation Controller Stack Navigation]]></title>
            <link>https://medium.com/@danwickes/navigation-controller-stack-navigation-ec8816693e3?source=rss-3a10d8ddaf4b------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec8816693e3</guid>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Dan Wickes]]></dc:creator>
            <pubDate>Mon, 17 Aug 2015 02:03:33 GMT</pubDate>
            <atom:updated>2015-08-17T15:16:06.735Z</atom:updated>
            <content:encoded><![CDATA[<p>I would like to add a label above the tab bar in my app. I would like it to look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*2baS5zcREhvu2nyg-bEgvA.jpeg" /></figure><p>Unfortunately, the navigation controller stack can get very complicated. Here’s a screenshot of the side view of one from Xcode’s view hierarchy debugger:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/216/1*KQib-n2v1N1ZHkkexGMQLw.png" /></figure><p>That’s a lot of layers. Thankfully, Xcode has an easier way of looking at them:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/292/1*lADBglCUVt9CHVfRWHmuWA.png" /></figure><p>Here’s the purpose of each of these:</p><p><strong>UIWindow</strong>: The main window of the app. It contains the visible content, delivers touch events to views and other application objects, and helps to handle orientation changes.</p><p><strong>UILayoutContainerView: </strong>Private Apple class, contains view controllers and determines the layout of its children (in this case the transition view and the tab bar).</p><p><strong>UITransitionView: </strong>Another private Apple class, this view is constrained by the LayoutContainerView and handles transitions between views by adding their wrapper.</p><p><strong>UIViewControllerWrapperView: </strong>This view does what it sounds like, even if the purpose of it doesn’t seem obvious. View controller’s are not supposed to have their display properties affected by other view controllers (for various reasons) but the wrapper can have its properties changed.</p><p><strong>UILayoutContainerView: </strong>Same purpose as the first one, but this is for children of the navigation controller rather than the tab bar controller.</p><p><strong>UINavigationTransitionView: </strong>Same purpose as the UITransitionView, but this handles Navigation Controller transitions.</p><p><strong>UIViewControllerWrapperView: </strong>The Navigation Controller’s wrapper view.</p><p><strong>UIView: </strong>Finally one of my views.</p><p>Now, back to that label. Because of autolayout issues, I would prefer not to use device coordinates. Therefore, I will need to traverse the navigation controller stack in order to do so. I can try to mess around with the private class UILayoutContainerView (assuming this stack is consistent) or I can just do this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*6Bc2BG6EUxfkl71KR9TA4Q.png" /></figure><p>with this call:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/827/1*SRtEJT_cdsre95djHA-fVw.png" /></figure><p>Basically, this method checks if it finds a tab bar among the subviews, and if not, go one level deeper. So, yeah, I guess all of that navigation stack wasn’t really necessary for me. But learning is fun, right?</p><p>Big thanks to the author of this blog: <a href="http://stablekernel.com/blog/view-controller-containers-part-i/">http://stablekernel.com/blog/view-controller-containers-part-i/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec8816693e3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[UI Testing in Xcode 7]]></title>
            <link>https://medium.com/@danwickes/uitesting-in-xcode-7-436acdbbdd3e?source=rss-3a10d8ddaf4b------2</link>
            <guid isPermaLink="false">https://medium.com/p/436acdbbdd3e</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[objective-c]]></category>
            <category><![CDATA[xcode]]></category>
            <dc:creator><![CDATA[Dan Wickes]]></dc:creator>
            <pubDate>Tue, 28 Jul 2015 13:31:43 GMT</pubDate>
            <atom:updated>2015-07-29T17:30:34.990Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Preface: This blog does not contain screenshots because of Apple’s confidentiality agreement for the beta.</em></p><p>Xcode is more shitty at UI testing than you are at writing readable code (barely). It’s a serious problem that is addressed at pretty much every developer conference, and it’s never solved. So, yeah, the speakers are all wasting their and your time. You do want to keep reading my blog about UI testing in Xcode 7 though, things are DEFINITELY different now.</p><p>So go download the Beta. It’s gonna take a while. As it should. It’s huge and you didn’t contribute, so shut up and be grateful. When it’s finally done, open up one of your existing projects. Turn on accessibility for all elements you’re planning on testing. You’re then going to go to new, and then target. Then under iOS, select Cocoa Touch UI Testing bundle. Thankfully Apple knows how simple you are and designs their interface accordingly.</p><p>Go through all of the typical file making bs and then check the project navigator (that’s the side menu with the folders you neanderthal). You will see a folder for your tests. Open the folder. Click the file with UITest. Breathe.</p><p>Ok, now you can start testing. Actually, you’re probably scrolling up to reread the snail paced instructions you should have gotten the first time. I’m sorry about the lack of screenshots, I know words intimidate you. Catch up yet? Good. In the file, you’ll see a method that says testing example.</p><p>The prefix test lets Xcode infer that the method is one of your tests (if you didn’t figure that out, I guess Xcode is smarter than you. Don’t let that get you down, it only crashes like, 3 times a day). Click in the body of the provided example or use your outstanding creativity to name your own method, as long as you remember to prefix it with test (write it on your hand). Now notice the red record button in the debugger’s left pane (the bottom window that you wanted to dismiss but couldn’t figure out how). Pressing this will launch your app and have Xcode autogenerate code to simulate your fat fingers spreading grease on your screen.</p><p>After this code is generated, you can set a variable and call XCTAssert to check if it’s actually that value. Yes, you need to figure out what you want the value to be. For example, you know that remarkably innovative to-do list app you’re working on that’s gonna make everyone but the most hardheaded curmudgeon stop using Google Calendar? You can set an NSUInteger to equal the row count of your tableview, add an item in the game changing way you implemented in your app, and use XCTAssert to check that the row count was increased by one. Then run your test. And that’s it. You’re done. Woohoo.</p><p>Big thanks to Julio Rivera, whose presentation at Prolific interactive inspired this post, and to Adrian Lignos and Dimitri Dietz for helping me clean it up.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=436acdbbdd3e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a Today Extension]]></title>
            <link>https://medium.com/@danwickes/creating-a-today-extension-6b36cc7dccf1?source=rss-3a10d8ddaf4b------2</link>
            <guid isPermaLink="false">https://medium.com/p/6b36cc7dccf1</guid>
            <category><![CDATA[objective-c]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[framework]]></category>
            <dc:creator><![CDATA[Dan Wickes]]></dc:creator>
            <pubDate>Fri, 10 Jul 2015 15:21:00 GMT</pubDate>
            <atom:updated>2015-07-10T15:27:02.109Z</atom:updated>
            <content:encoded><![CDATA[<p>A nice feature that began with iOS 8 was the ability to create app extensions. This allows the use of app functionality in other places, such as in photos, for sharing, or in this case, in the Today pull-down menu.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/311/1*cnibob84rolSQjQKdjFDMQ.png" /></figure><p>I was working on a weather app with my friend Jordan and I wanted to provide hourly weather in a widget. The first step to do this is creating a framework. App extensions do not communicate with the containing app, only with the host app (in this case, the Today app). Therefore, the shared logic between the containing app and the extension needs to be present in a framework that is visible to both.</p><p>To create a framework, go to File &gt; New &gt; Target.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wkPRmqRg181J4aMB0irUnA.png" /></figure><p>After that, select Cocoa Touch Framework, and then name it, probably APPNAMEFramework. In this case, I named it TimesurferFramework.After this, drag the necessary files into the framework folder, and import the headers into the Framework.h file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*XJjgQepP9LzSo0Whi-IKVw.png" /></figure><p>Also, add the framework to the target membership within storyboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/184/1*BIFhLaAqdLwsBDMohgb58Q.png" /></figure><p>The extension is created in the same way, File &gt; New &gt; Target, but this time select extension, and then Today Extension. Name it APPNAMEExtension (in this case, TimesurferExtension). This will default to display TimesurferExtension in the Today view instead of Timesurfer, so this can be changed in the extension’s plist.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/757/1*zdNHHzyWHegrEg2DEEyb-Q.png" /></figure><p>Next, the build settings need to be configured. Click on the project file and then on the framework. Add the headers that need to be shared to the Headers phase (they will be added to project by default, drag them to public), the implementation files to the Compile Sources phase, and the resources to the Copy Bundle Resources phase. Everything added here needs to be removed from the corresponding phase of the containing app target (Timesurfer).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/755/1*LG0Azq0ZMzfHJWav-r-S-A.png" /></figure><p>Now navigate to the build phases of the extension target and add the framework under link binary with libraries (it should already have been linked to the containing app although it’s worth double checking.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/568/1*bnjhXFdphNCApy9KFDScxA.png" /></figure><p>Finally, to ensure that the storyboard sees the viewcontroller, add -all_load and -ObjC linker flags to Other Linker Flags in the containing app’s build settings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/503/1*8mrYcZNeM5HJp0RvGxojcQ.png" /></figure><p>To import the framework, use this syntax: @import TimesurferFramework;</p><p>Now the extension itself can be worked on. It’s three files, a storyboard, Viewcontroller.h, and Viewcontroller.m. The viewcontroller should inherit from the corresponding view controller in the base class that it is going to share logic with. Then you can go into storyboard and link up whichever UI elements share logic with the containing app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/271/1*n49OMYkK2QDi9w5Krz0Lig.png" /></figure><p>This will allow all of the superclass’ logic to be used for the extension. At this point, just continue working on the extension the way you would any other app, the storyboard and view controller work the same way as they do in a containing app, as long as you don’t add anything that conflicts with the built in swipe gesture to view notifications. Big thanks to these two tutorials:</p><p><a href="http://atinyfish.com/2014/06/27/ios-8-extensions-sharing-code-with-an-embedded-framework/">http://atinyfish.com/2014/06/27/ios-8-extensions-sharing-code-with-an-embedded-framework/</a></p><p><a href="http://www.raywenderlich.com/83809/ios-8-today-extension-tutorial">http://www.raywenderlich.com/83809/ios-8-today-extension-tutorial</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6b36cc7dccf1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Adding Items to a Context Menu in an Xcode Plugin]]></title>
            <link>https://medium.com/@danwickes/adding-items-to-a-context-menu-in-an-xcode-plugin-a52679e30cc4?source=rss-3a10d8ddaf4b------2</link>
            <guid isPermaLink="false">https://medium.com/p/a52679e30cc4</guid>
            <category><![CDATA[objective-c]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[open-source]]></category>
            <dc:creator><![CDATA[Dan Wickes]]></dc:creator>
            <pubDate>Fri, 26 Jun 2015 14:08:03 GMT</pubDate>
            <atom:updated>2015-06-26T23:57:26.248Z</atom:updated>
            <content:encoded><![CDATA[<p>Two weeks ago, I authored a post about contributing to an open source repository. The focus was more on the open source model than on the content of the contribution. I have since contributed a more substantial feature to the repository which I will now detail.</p><p>HTYCopyIssue is a nice plugin that allows you to copy formatted issues onto your clipboard, or to open a new browser tab searching Google or StackOverflow. This was accomplished through the Edit Menu or a keyboard shortcut.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/387/0*1bVH_SemQBVBfCHs.png" /></figure><p>However, it did not have these options in the Issue Navigator’s context menu. I opened up the files again and worked to implement this.</p><p>HTYCopyIssue was a somewhat unusual plugin in the fact that it did not use a technique used in many other plugins, known as swizzling. The general way a plugin is implemented is by passing some .h and .m files to the application instance of Xcode as a bundle, and then changing Xcode’s methods with a technique known as swizzling.</p><p>In Objective-C, it is possible to change what a method does at runtime, for all instances of a given class. The general idea behind swizzling is that you instantiate an object of type Class, and then objects of type Method, IMP (implementation), etc. and use these to get the various necessary parts of a method (selector, implementation, and type signature to name a few). To accomplish this, I used the Aspects library, which allows easy access to an instance and a method’s invocation, as well as the ability to position new code before, after, or in place of the existing method implementation.</p><p>The next step was to figure out which method I needed to swizzle. I looked up Xcode’s header files (created by a class dump and on github <a href="https://github.com/luisobo/Xcode-RuntimeHeaders/tree/fd2e90b6414a20fb83c57ca52fadd97df736ae59">here</a>). I found a class that looked promising:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/816/1*p763_bY82OAEeZ5iL5CR6A.png" /></figure><p>Great! This was exactly whose context menu I wanted to change. I looked at the class hierarchy and found this method:</p><p>-(NSMenu*)menuForEvent:inRect:OfView</p><p>I figured I was set. I swizzled the method, but I was getting the default context menu. I set a breakpoint and searched for the root of the problem, and it turned out this method was returning nil, even when I commented out the swizzling code. I figured I must have had the wrong method. Looking at the stack trace, I found this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/313/1*0bqftjqtB6qTYQriaId9Hw.png" /></figure><p>Perhaps this method was creating the context menu? I then swizzled this here:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/1*hyniBXicfXF_FL6M72JPGQ.png" /></figure><p>I added a check for the type of the instance so these options would only be added for the context menu of the issue navigator, and made sure to retain the context menu so it wouldn’t be deallocated before being returned. This worked… although the menu items needed to be enabled. The Edit menu items were enabled by checking against the copy menu item in the Edit menu, so these would have to be enabled by checking against the copy menu item in the context menu. Which meant more swizzling:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/897/1*1Kx-mXqX_WtvzRBTPa47ZA.png" /></figure><p>I checked the instance of the menu to make sure it was in the issue navigator. This worked:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1Tll5VLDA1Vp9A3cEvyDKQ.png" /></figure><p>I pushed the changes and when I woke up in the morning my pull request had been accepted. Big thanks to Tim Clem and Joe Burgess for their help, GitHub user Hanton for creating the repo, Boris Bügling for his talks on Xcode extensions, Luis Solano for his Xcode class dump repo, and Peter Steinberger for making probably my favorite library in Aspects.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a52679e30cc4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Contributing to an Open Source Repository]]></title>
            <link>https://medium.com/@danwickes/contributing-to-an-open-source-repository-d2158b6eddf9?source=rss-3a10d8ddaf4b------2</link>
            <guid isPermaLink="false">https://medium.com/p/d2158b6eddf9</guid>
            <dc:creator><![CDATA[Dan Wickes]]></dc:creator>
            <pubDate>Fri, 12 Jun 2015 13:55:54 GMT</pubDate>
            <atom:updated>2015-06-12T16:13:19.964Z</atom:updated>
            <content:encoded><![CDATA[<p>As developers, we do not exist in a vacuum. There is an entire community of like minded individuals striving to build a better tomorrow. To contribute to this community, we needn’t start from scratch every time, rather we can build on the accomplishments of others. This idea led me to contribute to an open source repository.</p><p>When one of my instructors informed me of the existence of Xcode plugins, it made me think of features I had always wanted. Chief among these was the ability to Google my error messages. I looked through the Alcatraz (package manager for Xcode plugins) list and found HTYCopyIssue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/533/1*tk9Zf3qJWWqTwt1BUhnWJA.png" /></figure><p>I downloaded the plugin and was excited to be able to easily web search my errors. While it accomplished this purpose well, it strangely did not accomplish its signature feature, the ability to copy issues to the clipboard. I forked the repository to see if I could fix this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/831/1*v9pVnhG-Pxtbg-Wbn_zsdA.png" /></figure><p>I then took a look at the code. It was principally two files, HTYCopyIssue.h and HTYCopyIssue.m.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/264/1*avQSiXI7efFP6uaU5yUYog.png" /></figure><p>Looking over the code, I could see that the menu items to search Google and StackOverflow for the error were implemented as properties, while the option to copy the issue was implemented as a local variable.I fixed this and gave the property a name that better explained its function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*PduBCiNoxx_NuZKc3gKFIg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DNhzbY3662z9FwmP_xbpcA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/957/1*Xt_SUzi_PAh85k16rFv8Ig.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/967/1*3UxOTpZBlclpJFrU8HCJEg.png" /></figure><p>I tested this and it worked, so I submitted a pull request. Later that night, I was ecstatic to see that my pull request had been accepted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/1*qZ03vcz3heVMrV1rgP2vww.png" /></figure><p>Contributing this made me feel like a real developer, which is something that is very important to me. It is why I stopped using a Git GUI and prefer to navigate my filesystem through terminal rather than Finder. Any of you reading this with a semi-decent understanding of programming can contribute to an open source repository, as my commit was only about two lines. Doing so is something that not only builds your portfolio, but invaluably increases your self-confidence as a programmer. Thanks to Hanton for creating this plugin, and Tim Clem, Henry Chan, and Mark Edward Murray for their help.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d2158b6eddf9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>