Skip to main content

Posts

iOS Mid Senior level [Part 3/4]: Applying design patterns.

[1] Singleton When a class is restricted to just one instantiation, that one object is called a singleton. A singleton class returns the same instance no matter how many times an application requests it.   Example : + (instancetype)sharedManager   {      static DocumentManager * sharedDocumentManager = nil;      static dispatch_once_t onceToken;      dispatch_once(&onceToken, ^{          sharedDocumentManager = [[DocumentManager alloc] init];          NSLog(@"Singleton memory address: %@", sharedDocumentManager);      });      return sharedDocumentManager; } [2] Abstract Factory  Provide an interface for creating families of related or dependent objects without specifying their concrete classes. Creates a base class with abstract methods defining methods for the objects that should be created. Each factory class w...

iOS Beginner Level [Part 2/4]: Familiar Objective-C Classes

[1] NSUserDefaults NSUserDefaults object used to read information and caches information in user’s default data base.  Stores the data in Plist. The synchronised method of this class automatically invoked at a period of intervals to sync  the memory cache the data base. ex: `[defaults synchronize];` Always returns the immutable values. Non-persistent data storage. [2] NSBundle  This object locates your app in the file system from where you can access resources and use them in your programs. [3] UIResponder:  Subclass of NSObject defines the interface for objects ( likely abstract class) objects responds to this class and it handles those events. It is the super class of UIApplication, UIWindow , UIView (including all of its subclasses). Handles all type of touch events, motion events. [4] NSCoder  NSCoder is an abstractClass which represents a stream of data. They are used in Archiving and Unarchiving objects. NSCoder objects are...

IOS Beginner level [Part 1/4]: Basic concepts and terminology

Started developing iOS  apps? Great ! Before that make sure you have familiar with basic concepts covered in this post. Most probably you started using, but  totally unaware of it.  All these topics are the checklist for your next interview or your presentation and also you are welcome  even if use it as cheatsheet.  Again I want to stress that it covers only the topic definition or few lines of description. You can find good tutorial sites for rest of in depth explanation. [1] App A large ecosystem of interconnected objects that communicate with each other to solve specific problem such as displaying user interface, responding events, inputs and storing information. [2] App ID App id is a 2 part string used to identify one or more apps from a single development team. Combination of Team Id and Bundle ID separated by a period character(.) There are 2 types of App Id’s , an Explicit app id used for single app and wildcard app ids (with domain na...

Tech Mega Events - to Create Event in Your Calendar

Annual tech events not only exhibiting future technologies but also gives   up-to-date knowledge of IT industry buddies. Here is the list of tech events that to be marked as event in our calendar app. Consumer Electronics Show (CES)   - January Kick start your new year with CES, an annual trade show on upcoming electronics gadgets and overview upcoming innovations in consumer electronics industry. Event held in Las Vegas organized by Consumer Technology Association.

Popular posts from this blog

Implementing autocompletion OTP field in iOS

Long waiting is over. !!  iOS 12 brings Autofill for OTP text field which is close to Android provided a decade back. Previously in iOS we used to toggle between OTP text screen and message inbox.  Which was hard to remember and time consuming resulting a bad user experience. Personally, I have been asked from the client/customer couple of times to implement autocompletion for OTP field and took me a lot of time to convey that it is not possible in iOS. Why Autofill was not possible previously?  We all know that Apple gives at most care for user privacy. When we see iOS architecture, each individual app is like a separate island. There is no inter-app bridge between apps (exception for Keychain and URLSchemes APIs which gives very limited scope). Thus we cannot read message content from inbox. Where to start Autofilling? First of all, the target SMS need to have the OTP Code with prefix string "Code" or "Passcode"on its message content. Beware of OTP c...

Animating label text update - choosing a better way

Recently I published a countdown app .  At one point of development - I have to show a timer on a UILabel which ticks on each seconds. As usual I started  setting text to a label object - self .timerLabel.text = someString Easy piece of cake right !?   But wait ... it won't take much user attention when timer ticks on every seconds. So I decided to make use of a simple animation while label gets text update. I found there are dozens of ways to animate a label. In this short article, I listed 3 best way you can animate text on a label. ( Spoiler Alert 👀- I decided to go with 3rd option)  1. Fade In - Fade out animation : CATransition class has got transition type `fade`. With timing function of CATransition - I was able to see the below result. let animation: CATransition = CATransition () animation.timingFunction = CAMediaTimingFunction (name: CAMediaTimingFunctionName .easeInEaseOut) animation.type = CATransitionType .fade animation.subtype = C...

Cached Async Image in SwiftUI

 SwiftUI’s AsyncImage is handy, but every time your view appears, it refetches the image—leading to flicker, delays, and unnecessary network use. What if you could fetch once, then reuse instantly? That's exactly what the Cached Async Image  delivers: a memory-powered caching layer that keeps SwiftUI image loading smooth, snappy, and resilient. First a simple in-memory cache without disk persistence. This will be thread-safe and auto-purges under memory pressure. A Singleton wrapping NSCache for URL → UIImage caching as follows : final class ImageCache {   static let shared = ImageCache()   private init() {}   private let cache = NSCache<NSURL, UIImage>()   func image(for url: URL) -> UIImage? {     cache.object(forKey: url as NSURL)   }   func insertImage(_ image: UIImage?, for url: URL) {     guard let image else { return }     cache.setObject(image, forKey: url as NSURL)   }   func clearAll() { ...

Prevent Navigationbar or Tabbar overlapping Subview - solved for Card view

Recently, I started with a Card view added as a subview of UIView in a view-controller. When a view controller created along subviews, it tends to use entire screen bounds and also slips behind Tab bar or Navigation bar. In my current situation, it's second case. Casually new iOS developers will write a patch by additional value for coordinate y and subtracting bar height from its size. A lot of them posted in SO threads too : How to prevent UINavigationBar from covering top of view? View got hidden below UINavigationBar iOS 7 Navigation Bar covers some part of view at Top So, how I got solved ? self.edgesForExtendedLayout = [] This  will avoid all subviews in a view controller get behind any bars. Read full apple  documentation on here. Full Source code below :  //Simple view controller where its view layed-out as a card. class WidgetCardViewController : UIViewController { var containerView = UIView () //MARK:- View Controller Life Cyc...

UICollectionViewCell shows with wrong size on First time - Solved

We commonly use Collection view where its cell size calculated run time. The flow layout delegate is responsible to return individual cell sizes. BUT in most of the cases, delegate method `collectionView: layout sizeForItem:` expects cell size too early. Before generating actual cell size. extension YourViewController : UICollectionViewDelegateFlowLayout { func collectionView ( _ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { return CGSize (width: externalWidth, height: externalHeight) } } For instance, if a cell size depends on external view and its frame is not yet ready - results with wrong (or outdated) cell size. Typically happens for the first time view controller laid out all views. You can find similar queries in StackOverflow community : Collection view sizeForItemNotWorking UICollectionViewCell content wrong size on first load How to refresh UICollec...