Skip to main content

Posts

Showing posts with the label iOS

What is the defer statement and what is the use of defer statement?

Defer Statement: Introduced in Swift 2.0, The Swift Defer statement isn't something you'll need to use often.  What is Defer? A defer statement is used for executing code just before transferring program control outside of the scope that the defer statement appears in. In simple words, defer is an operator used with closure where you include a piece of code that is supposed to be executed at the very end of the current scope. Syntax defer { statements } Example func f () { defer { print ( "defer statement executed" ) } print ( "End of function" ) } f () // Prints "End of function" // Prints "defer statement executed" The above example defer statement was executed after the print statement after the end of function f() 's Scope. Multiple Defer One of the most powerful features of defer statement is that you can stack up multiple deferred pieces of work, and Swift will ensure they all get executed. If you use multiple de...

Static Library, Dynamic Library, Framework Which is best way to distribute Custom Code?

If you’ve been developing for iOS for some time, you probably have a decent set of your own classes and utility functions that you reuse in most of your projects and shared with teams.  Well, there are different ways, the easiest way to reuse code is simply to copy/paste the source files. However,  this can quickly become a maintenance nightmare. Whenever you update the source code, you have to update the changes to all the files between teams and projects, Since each app gets its own copy of the shared code, it’s difficult to keep all the copies in synch for bug-fixes and updates. Also, this will not work if you don't want to expose the implementation details. When developing iOS apps you rarely implement everything from the ground-up, because operating systems, as well as the open-source community, offer a large amount of functionality ready-to-use. Such pieces of functionality are usually packed in a distributable form known as the library. In this article let's explore sta...