A bookshelf in a library (Flickr)

What makes NSCache a better fit for caching objects compared to the collections found in the Swift standard library (such as Dictionary) is that NSCache automatically evict objects when the system is running low on memory — which in turn enables our app itself to remain in memory for longer.

NSCache

Limitations of NSCache

  • It’s an Objective C class

After writing a simple proxy class around NSCache, you can get maximum out of it in…


Broadcast towers Flickr

NotificationCenter is a typical example for the observer design pattern. It’s a “cool” and easy mechanism to broadcast information from one class to all registered listeners. You define a key for a notification, you add observers to this notification by its unique name. You implement in the observer class a handler function that is triggered upon receiving the notification. The sender broadcasts its information over the NotificationCenter which is responsible for keeping track of listeners and observers for the individual notifications.

Pros in theory

  • Loosely coupled design between interacting objects (Senders and Observers)


One typical use case in many mobile apps is selecting image or video with help of UIImagePickerController from image gallery or making a new one with the camera. Depending on the desired source and preferences, we need to configure certain UIImagePickerController’s properties and set the UIImagePickerControllerDelegate to the presenting UIViewController in order to be informed after the asset selection.

let imagePickerViewController = ImagePickerController()
imagePickerViewController.sourceType = .camera
imagePickerViewController.cameraDevice = .rear
imagePickerViewController.cameraCaptureMode = .photo
imagePickerViewController.showsCameraControls = true
imagePickerViewController.imagePickerDelegate = self

You can then access the selected asset in the delegate method as the following.

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String …

Ilker Baltaci

Senior Mobile App. Developer

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