Sometimes when building an app, we find ourselves in a situation when we want to use a private API. It may provide some important functionality that is not exposed (yet), or we may want to work around a known platform issue. Or, you may be just debugging your code and poking around to get extra details.
Whatever you are trying to achieve, keep in mind that private APIs are fragile and can change without notice, leaving you with a broken product and frustrated users.
Swift adds another dimension here: restricted APIs marked as
NS_SWIFT_UNAVAILABLE. Those are not technically private, but…
Great applications should have great localization. And users will appreciate an option to use beloved apps in their native language. There is no excuse for developers not to support interface localization even on early stages of the development process, especially when it’s so easy to do.
I prefer to design mostly with the Interface Builder. In this article I would like to share an approach I use in my projects to localize those resources.
Normally, when you try to localize a XIB file or storyboard, Xcode will happily clone the resource and you get stuck with duplicated view layouts. …
Sometimes you want to write a generic algorithm working on any
Optional type no matter what actual type is wrapped inside. Ok, this can be easily done with a free generic function, but what if you want to write a
Sequence extension to remove all
nil values for example?
Things get a little bit complicated here since
Optional is not a protocol but a concrete type and so it can’t be used as a generic type constraint.
Generic protocols and concrete types in Swift serve different purposes: we create instances and declare variables of concrete types while protocols can be…
It might be tempting to use
Self as a parameter type when extending classes but Swift only allows it in a protocol or as the result of a class method invocation.
In fact, this is a semantically correct restriction for non-final classes in most cases, except when we want to use
Self as an argument of the closure, think about completion handlers for example. In that case
Self is used just as an another method call result which is absolutely valid option.
My favorite example here is the continuation helper for the
Reference counting is great in taking unused objects out of memory. The same can be applied to the temporary files we allocate.
Let’s say you are building a video sharing app, here is what you have to do each time user decides to upload some content from the app:
Taking care of those files manually…
While looking through another sample project today, I have once again noticed how many string literals and force downcasts accompany most of the storyboard-related code.
Having realized that, I decided to share a few practices I use myself to make my view controller and storyboard handling code more conscious.
Let’s start with the instantiation process: we rely on file name to create
UIStoryboard instance, then we use view controller identifier to call
instantiateViewController(withIdentifier:) and all this mess is followed by the force downcast to the actual type.
View controller instantiation code should be much cleaner, here is an example of…