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.
Limitations of NSCache
After writing a simple proxy class around NSCache, you can get maximum out of it in…
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
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 …
Senior Mobile App. Developer