Important Starting in iOS 8.0 and OS X 10.10, use WKWebView to add web content to your app. Do not use UIWebView or WebView.
WebKit was introduced in iOS 8 but it was released with an error which caused in a runtime crash, If you are using Xcode 9/10, your project configuration support less than iOS 11 and if you are trying to add WKWebView using interface builder. Xcode immediately shows a compile-time error.
WKWebView before iOS 11.0 (NSCoding Support was broken in the previous version)
Although WKWebView was introduced in iOS 8, there was a bug in –[WKWebView initWithCoder:] that was only fixed in iOS 11.
Resolution is you must add WKWebView through code (Only if you are supporting below iOS 11). That actually sounds strange.
Another solution is to change the Interface Builder Document Builds for the option to iOS 11 and later (If you’re migrating from older target to iOS 11 and still getting the same error).
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.
Properties of a constant instance of the struct are immutable because struct’s instance own the whole object and by declaring it as a constant means the whole object itself will be immutable.
Properties of a constant instance of the class are mutable as class’s instance owns the object’s reference thus by declaring it as a constant only means that the further reference assignment can’t be done.
Structs are blessed with default member-wise initializer but classes are not.
Structs are preferable when they are small and copyable.
With Structs, there is much less need to worry about memory leaks or multiple threads racing to access/modify a single instance of a variable.
Since struct instances are allocated on the stack, and class instances are allocated on the heap, structs can sometimes be drastically faster (but it still depends on how many values you’re storing and the size/structure.)
In a multi-threaded environment, for instance, with a database connection that’s opened in a different thread, structs are safer. They can be copied from one thread to another thread, without running the risk of a race condition or deadlock. Classes do not have this inherent safety unless they’re deliberately made thread-safe.
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 andimport TargetName-Swift.h next to add support in your Swift file you need to inherit if from NSObject or use @objc flag.
What if you have multiple targets in your codebase? As you cannot import, TargetNameA-Swift.hTargetNameB-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,Window,Devices and Simulators options, below is the screen for reference.
Step 3: Just enable the optionConnect 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.