When the user taps an on App icon, iOS creates an instance of UIApplication which runs on the main thread. This main thread processes all UI events such as touch, location updates etc.
After app launched successfully, it becomes available for the user to do interactions with it and every single interaction which known as an event is processed in a FIFO manner.
Now while events are being processed there may come some UI update requests which aren’t get fulfilled immediately. Instead, the system waits until the existing process finishes and the next redraw cycle comes. There is a periodic interval between the event processing and UI layout handling. The setLayoutNeeded() and layoutIfNeeded are two UIView’s methods here to ask the system for updating the view with new changes.
The setNeedsLayout() tells the system that you want the view and all it’s subviews to be redrawn in the update cycle.
Here is What Apple’s doc says on this, “Call this method on your application main thread when you want to adjust the layout of a view’s subviews. Note that it returns immediately (Async call) because it does not force an update, it waits for the next update cycle”.
Whereas layoutIfNeeded() is an async call which tells the system that you want the view and it’s subviews to be redrawn immediately without waiting for the next update cycle.
UIView have one more method named layoutSubviews() which you can use for your own implementation to set the frame of your view directly by overriding it. And since it’s default implementation uses the constraints you have given to determine it’s size and positions to get the frame, you should override it unless autoresizing and constraint behavior is not working for you as expected.
In short use setNeedsLayout(), if you are okay with the system to update it in the next upcoming update cycle and use layoutIfNeeded() if you want it to be updated immediately.
Thanks for reading.
Announced in 2014, the Swift programming language has quickly become one of the fastest growing languages in history. Swift makes it easy to write software that is incredibly fast and safe by design.
Blog for developers to highlight, top 10 trending open source to learn.
- MessageViewController A SlackViewController replacement written in Swift, compatible with iPhone X, iOS12. Created by Ryan Nystrom
- Swift interpreter for Pascal language (Inspired from Ruslan’s Blog). Created by Igor Kulman
- CollectionViewSlantedLayout subclass of the UICollectionViewLayout allowing the display of slanted cells in a UICollectionView.Created by Yassir Barchi
- Mint Package manager that installs and runs Swift command line tools, created by Yonas Kolb
- CryptoSwift Collection of standard and secure cryptographic algorithms implemented in Swift. Created by Marcin Krzyzanowski
- CocoaDebug Debugger tools for iOS supports Swift and Objective C, created by CocoaDebug
- iOS-Depth-Sampler Examples of Depth APIs in iOS, created by Shuichi Tsutsumi
- Universal Link Testing It fetches and parses apple-app-site-association file for you to quickly check whether Universal Links are working. created by Ethan Huang
- Swift Syntax Set of Swift bindings for the libSyntax library. It allows for Swift tools to parse, inspect, generate, and transform Swift source code. Created by Apple
- WhatsNewKit Showcase your awesome new app features, Created by Sven Tiigi
Thanks for reading!
“Today is all about Software,” Apple CEO Tim said as he took the stage at WWDC 2018.
It all started with statistics.
- 20 million iOS developers
- 500 million weekly app store visits
- 81% using iOS 11 where only 8% using latest Android
- Developers earned 100 million through App Store
- New iOS 12 will be released as a free update, every model back to the 5S will get a performance boost.
- ARKit, second generation, which included a lot of cool updates, most interesting is the ability for multiple users to observe and interact with the same environment from different angles.
- Apple Screen time, now iOS 12 will tell you how much time you’re spending with your iPhone and which are the apps.
- Do not disturb a lot of improvements, while you are sleeping will hide the notification, one step one time notifications.
- Photos, with iOS 12 they have revamped it. Allowing more search options driven by AI, share the photos through iMessage.
- Siri, it’s handling 10 billion requests per month and now Apple is allowing you to interact with it more, create shortcuts to trigger app features.
- Animojis, more personal now. It’s super accurate, face-tracking and tongue tracking capabilities. Surely it will feel you very familiar.
- Group FaceTime, now chat with 32 people at once with emoji, sticker, and other effects support.
iOS Apps updates
- Stocks, new UI with better performance
- Apple News app.
- Apple iBooks getting a redesign and a new name.
- Voice Memos, iPad getting it for the first time and recording will be now synced to iCloud.
So far biggest functions of the Apple iWatch is fitness, now Apple adding more components which let you challenge your friends.
- Automatic workout detection using your heart-beats(once you stop working out your heart rate decreases, so it will automatically stop).
- Walkie-Talkie, Texting/phone are tough using watch screen so Apple added an instant audio messaging app called walkie-talkie (uses the wifi or cellular to interact with other devices).
- Siri on Watch, allow third-party apps to show you more information. Now just lift your wrist and start talking it means no more “Hey Siri”.
- Podcasts app is coming on your wrist.
How to use Swift classes into Objective Code when you have multiple targets.
For using Swift classes in Objective-C Code when you have one target in your app. We generally need to and
import TargetName-Swift.h next to add support in your Swift file you need to inherit if from
NSObject or use
What if you have multiple targets in your codebase? As you cannot import,
TargetNameB-Swift.h etc. In that case, you can tell the compiler that not to create Swift module specific to target change it to project name because the project will be same and unique.
For achieving this select your every target, Build Settings and change the build configuration.
Objective-C Generated Interface Header Name —> replace $(SWIFT_MODULE_NAME)-Swift.h that is specific to the each target, with $(PROJECT_NAME)-Swift.h
Later import PROJECT_NAME-Swift.h in your Objective C code to make use of your Swift code.
Yes, correct you heard it right. It was the most awaited feature because nobody wants to spend a lot on Apple connectors, haha. But unfortunately, I don’t see people are utilizing this features. So here we go with one to kick start.
iOS device with later or
iOS 11 OS version.
- MacBook with
macOS 10.12.4 or later.
Xcode IDE with 9 or later
- Developer Macbook and
iOS device should be on same WiFi network.
I hope after reading prerequisites you are clear about what is gonna happen. Let’s move on further steps.
Step: 1 Here you need your connector cable for first and yes last time. Connect your iOS device and open Xcode.
Step 2: Switch to,
Devices and Simulators options, below is the screen for reference.
Step 3: Just enable the option
Connect via network.
Step 4: Sometimes it will ask you to provide your
iOS device IP to enter but in my case, it didn’t ask.
Thanks for reading!
Why do we need to create frameworks? because it has three major purposes mentioned below and also you can share your code with your team, other developer or iOS community.
- Code encapsulation
- Code modularity
- Code reuse
Let’s create the iOS framework.
Now just give some meta-data about your framework like name, organization, identifier etc (I hope you’re already aware of it).
We’re good to go till now. Just add the files that you want to keep within your framework.
Build the framework project to make sure that you get build succeeded with no build warnings or errors.
Things that you need to take care.
- Make sure to check Copy items if needed, so that the files actually copy into the new project instead of just adding a reference. Frameworks need their own code, not references, to be independent.
- Double-check that each of the files has Target Membership in ThreeRingControl to make sure they appear in the final framework. You can see this in the File Inspector for each file.
- Double-check the access modifiers, while creating framework access modifiers plays very important roles.
- if you’re creating Swift framework make sure you’re extending classes from NSObject otherwise it won’t reflect once you will import the framework.
Thanks for reading.
Recent blog: SOLID vs STUPID
STUPID principles and yes this may hurt your feeling but yes if you are following this you are writing stupid code.
Well known design pattern, but mostly understood one as well. Like me, people are also fighting with Singleton syndrome. In that case, whenever we create a class we create it Singleton but why? That is definability not cool. Singleton also considered anti-patterns. We should think and avoid if possible because the program using Singleton are hard to test because of global state, with the global state they hide their dependencies.
Avoiding static things is important to avoid tight coupling. If it’s there then making a change in one module requires to changes another module too. Now it’s really difficult to reuse and difficult to test.
Testing is not hard, what you think? We don’t write test case may be because we don’t have the time or the code we are writing is bad because of tight coupling?
One of my favorite quote from Donald Knuth, premature is the root of all evil. There are only cost and no benefits. Actually optimised code is much complex as compared to just writing a loop.
That’s what I like most and I try to follow as much as possible. Name of your class, variables or methods should be clear because at the end of the day human is only going to read because programming languages are for human not for computers, computers can understand 0 or 1 very well.
That’s bad. Writing same code again and again so don’t repeat yourself, keep it simple and strong. Write Code only once.
Thank you for reading the quick introduction of STUPID principles, next will be SOLID principles.