All the variables and constants that you allocate in Swift are stored in memory, so they get lost when users quit the app.

Persistence is saving data to a place where it can be re-accessed and retrieved upon restart of the device or app. So, that is longer than a life cycle the running app and keeps it available to the user.

UserDefaults is by far the easiest way to persist your data to your device. It’s like a dictionary that automatically saves its contents. With all that;

  • It saves data into p.list
  • We need to keep the size below…


Reactive programming is converting everything into an event sequence. Every change in our data converted into an event that other parts of the application might be observing for. In ReactiveX, many instructions may execute in parallel and their results are later captured.

There are some mechanisms we will get used to.

Observable

Rather than calling a method, you define a mechanism for retrieving and transforming data in the form of observable to be able to subscribe to it. With subscribing, we have access to the data and the event.

An Observer subscribes to an Observable. An observable emits/sends items notifications to…


Grand Central Dispatch provides language features to support concurrency on iOS. It works with Dispacth Queue (objects) in our application.

By default, every iOS application has

  • 1 x Main Thread (Serial Queue)
  • 4 x Background Thread (Concurrent Queue)

Main thread is reserved for UI related tasks. And, we are able to create more custom (concurrent or serial) threads. Concurrent and serial queues help us to manage how we execute tasks.

Serial Queue:

Executes tasks one at a time.So, task 2 will not start until 100% of task 1 completed.

  • Slower
  • Predictable execution order
  • Prevents race conditions

Concurrent Queue:

Every task…


We will begin with the networking foundations to understand web services.

Clients can connect to the related server by using URL which contains;

https:// — SCHEME = specifies how to connection will happen.
* HTTP is a protocol for transferring hypertext documents on the World Wide Web. HTTPS is secure(encrypted data flow) version of HTTP.

medium.com/ — HOST = gets our request to the right computer

@vuralkaan/PATH = our end point

But the URL can contain below items;

scheme:[//[user[:password]@]host[:port]][/path][?query][#fragment]

Therefore, DNS will help to determine the actual IP address of the server.

Let’s say we are going to use Dog API in our application. And we have

let urlString…


Before you begin I highly recommend you to check ARC story.

We will begin with checking no memory leak case in closures;

Prints Initialized and Deinitialized

The closure block is separate from the Human object and the humanClosure property has a reference to the closure block.

Since the Human object as one reference from the kaan property, we able to deallocate.

The closure block has been also deallocated due to the reference count of zero.

Now, check below case.


Why delegate should be weak var?

Before you begin I highly recommend you to check ARC story.

We will design protocol and classes in order to show retain cycle on delegates.


Functional programming, which means using functions to derive results.

Imperative (Non-functional): Tells you how to got the answer from A to B.


When an object is initialized, it is physically stored on RAM. Since the space is limited, the object should be removed when unused. The process is known as deallocation.

If the reference count reaches zero, the object is deallocated automatically by ARC.


Drawbacks of OOP:

1. When you subclass, you have to inherit all properties and methods which you may not need. Your object unnecessarily bloated.

2. When you make a lot of superclasses it becomes extremely hard to navigate between each class and fix bugs.

3. Since objects are referencing to the place in memory, if you make a copy and create a small change to it’s property, it can mess up the rest. (Mutability due to reference)

Protocols


Photo by Wes Hicks on Unsplash

Closures are an anonymous functions (without names). And they are reference types.

Kaan Vural

Software engineer @huawei , musician

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store