Did you know that you can create your own file templates for Xcode? Sure you did. But did you also know that you can create a template that takes a string and puts it into a field you define?
Let’s build a file template for a Swift protocol and a protocol extension.
Create a file template
First things first.
Xcode looks for your custom templates at the locationRead more...
~/Library/Developer/Xcode/Templates/. We will start by copying a template that comes with Xcode to that location.
The 4th problem in Project Euler is this:
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
Yesterday I gave a talk at the Cologne Swift meetup and I tried something new. I used a Swift Playground for the “Slides”.
Yesterday I got asked, what a Swift beginner should learn first. Here is the question:
I did want to ask you something, is it worth a while to learn TDD, or spend that time learning Swift, and functional programming?
Of course, my opinion is a bit biased as I wrote a book about TDD with Swift. So, keep that in mind when you read my answer.
Advice #1: Read the Swift Book provided by Apple.
In my opinion you should first learn Swift. This is the basis of everything. If you don’t understand what functions can do in Swift, you won’t understand the concepts of functional programming in Swift. In addition, Swift is still mainly used to write apps for iOS and OS X. This means, most of the time you need to interact with object oriented APIs (at least at the time of writing ;)). So you also need to understand object oriented Swift to leverage the potential of Swift when writing Swift.
And even if you don’t believe me, this is what Chris Eidhof, Florian Kugler, and Wouter Swierstra write in Functional Swift:
„You should be comfortable reading Swift programs and familiar with common programming concepts, such as classes, methods, and variables. If you’ve only just started to learn to program, this may not be the right book for you.“
With the new syntax for selectors in Swift 2.2 the approach I used in “Utilize the responder chain for target action” produces a warning. Let’s fix that.
Protocols for president
First we add a protocol:Read more...
I got some feedback to my last blog post about The best table view controller. In this post I want to comment on the feedback because the comment sections is not really good for detailed discussion.
I couldn’t get Interface Builder in Xcode 7.3 to support typed view controllers. While you can type in the associated class, the field becomes blank when the storyboard is saved.
Interesting. I wasn’t aware of this. But this again tells me, that storyboards (and the Interface Builder in general) are not suited for my style of iOS development. As you may know, I don’t like the Interface Builder.
If you depend on storyboards for your User Interface, than this kind of table view controller isn’t for you (yet).Read more...
Since I read the objc.io post about light view controller, every few month I come back to the same problem: find the best way to write a table view controller. I have tried several different approaches like putting the data source and delegate in a separate class or using MVVM to populate the cell.
This post is the March 2016 solution to this problem. And as most of the times, I’m quite happy with the current solution. It uses generics, protocols and value types.
The main part is the base table view controller. It holds the array to store the model data, is responsible for registering the cell class and it implements the needed table view data source methods.
Let’s start with the class declaration:Read more...
Last month my book about Test-Driven Development with Swift finally got published. In this and some of the next blog posts I will present some things I learned while I wrote it.
In this post I will show a nice way to test if a view controller got pushed onto the navigation stack as a result of an event.
Let’s say we have button on a view controller. When the user taps the button, a detail view controller should be pushed onto the navigation stack. How can we test this?
Easy! We will use a mock for the navigation controller. The mock looks like this:Read more...
Since I wrote the table view data source code in Part 8, I have experimented with table views and table view cells a lot. And I found a way of setting the data in the cell that I like more now. Most probably that will change in the future. That is the point of being a developer. Code I write today will probably scare me in half a year. I fear the day when this stops. Change of preferences is a good thing. Without it I’d have stopped improving.Read more...
Again I haven’t written a post in a long time in this series. And even this post isn’t a real post. It’s just a correction and and I’ll tell you the reason why I was so busy during the last months. There will be a real post soon. Stay tuned. :)Read more...
subscribe via RSS