Starting from iOS15, to adjust the layout when keyboard is shown/hidden, we do not need to import third party library IQKeyboardManager or do the math ourselves. iOS has a new native layout guide named keyboardLayoutGuide. All you have to do is to anchor bottom of your view to the top of the keyboardLayoutGuide: To try…
iOS Adaptive Presentation Controller
If you want to change the presented view controller’s modelPresentationStyle according to size class, here ‘s a guideline for you. My setup is basic: I have a view controller and it has a button on it. When user taps on the button a new view controller is presented. First you need to set presented view…
iOS Custom UIPresentationController
The purpose of this story is to demonstrate the creation of a custom presentation controller. In my example, there will be a button on first view controller and when user taps on it, the detail view controller will be opened in a custom presentation controller. Here’s the first view controller: We need to create our…
iOS UserDefaults Best Practices
1- Extension: 2- Property Wrappers:
iOS Fastlane Setup
This is a guideline for installing fastlane on your mac. 1- Install Xcode command line tools: xcode-select — install 2- Install Homebrew: https://brew.sh/ 3- Install ruby. Ruby is already installed on Mac but I highly recommend to install a new version with brew. Check below links if you encounter any problem: brew install ruby https://stackoverflow.com/questions/39381360/how-do-i-install-ruby-gems-on-mac…
Swift OptionSet
So if you need a property which might have more than one enum case, you can use OptionSet. Bitwise shift operator is used to take advantage of OptionSet features such as intersection and union: CakeIngredients(rawValue: 3) means banana and strawberry because rawValue of banana is 1 and rawValue of strawberry is 2 and sum is…
Custom UIViewController Transition
I will show with an example: I have two UIViewControllers, one is to present and the other one is to be presented. They both have UITapGestureRecognizer on their views. When tapped, the presenting one presesents and the presented one dismisses. And the transition is not custom yet. To make it custom, first we need an…
Preventing the Retain Cycle Memory Leak Of Strong Swift Arrays
Let’s create a retain cycle memory leak with arrays: Subscriber holds publisher strong and publisher holds its subscribers back in its subscribers array. Paste the code into your playground and observe that deinit never gets called, too bad! The array itself can not be a weak reference. But its elements can be defined as weak…
Testing iOS SSL Pinning With Charles
So you have finished implementing SSL Pinning with your favorite tool (URLSession, AlamoFire, AFNetworking, etc…) and you want to test it. I would suggest using Charles on doing that. As in “https://www.charlesproxy.com” stated, “Charles is an HTTP proxy / HTTP monitor / Reverse Proxy that enables a developer to view all of the HTTP and…
UIScrollView Content Layout Guide with Auto Layout in Interface Builder
I will try to keep this short enough. With iOS11, Apple introduced Content Layout Guide for UIScrollView and I will show you how it’s used with a vertical UIScrollView example: 1- Add a UIScrollView and attach it to safe area. Don’t worry about the errors yet. Content Layout Guides is checked by default. 2- You…
accessing instance variables hints
Internally read data with instance variables, write via properties. In init and dealloc use instance variables. use properties if the data is lazily initialised.
readonly copy
Even though you set a property as readonly, it is best to define what semantics would be when the initialiser runs. It is good because consumer of this class would know what semantics the object is using and would behave accordingly.
