In finance, the key to growing wealth exponentially over time is compound interest. Wealth simply grows faster when you earn a return on your capital, and then re-invest the return, to earn a return on that.
Many people have of course made analogies, applying the concept of compounding generally to…
There are many ways to record audio on iOS, with the
AVFoundation framework being a veritable Swiss Army Knife of tools.
At the basic level,
AVAudioRecorder makes it dead simple to record audio in a variety of common formats, and save it to disk. However, the audio is only available…
Swift, as a highly protocol-oriented programming language, is chock-a-block with a multitude of protocols in its standard library. In this series, I hope to discover & learn more about some of them.
Any two instances of a type that conforms to Equatable can be checked against each other to see…
One of the most powerful parts of Swift is its support for Generics. Using Generics, you can write code that is type-agnostic, meaning less code duplication.
But Generic code, as such, accepts any type. If you however want to constrain your code to accept only certain types, and that too…
A protocol in Swift is generic when it does not enforce types in (some or all of) its variables and functions, on types that conform to it. Different conforming types can then implement the protocol in ways that’re relevant or convenient for them.
There are two ways to make a…
The MapKit framework allows you to create and embed maps in your app. But sometimes, embedding an entire map may be overkill — like if you want display multiple coordinates, as a list of maps in a UITableView. Or if you want the map to be non-interactive.
In such cases…
When designing the models and data structure for your app, you would probably be deciding between Structs and Classes.
If you’re coming from a different programming language, it’s easy to settle into a pattern of using classes throughout your app.
However, structs in Swift are highly significant — they have…
dispatch_group is a part of Apple’s Grand Central Dispatch (GCD) set of APIs that allows you to coalesce and synchronise the results of multiple asynchronous functions into a single point of execution.
With dispatch_groups, a thread is blocked until all tasks associated with that group are finished. And once they…
By default, Swift Playgrounds do not execute (asynchronous) code that depends on the RunLoop for callbacks or completion.
This includes, for example , NSURLConnection/Session requests, and NSTimer actions.
This is because, the code in the Playground is executed, and the process is terminated — the completion operations / callbacks are simply not executed.
To enable this, there are two options
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true // Your Code
This creates a 30-second window for the async code to execute and finish, after which it’ll time-out. This duration can be customised using the timeline view (at the bottom of the playground). After the code is executed, you can call: