Are all SwiftUI Views intermediaries for UIKit views? - swiftui

Are all SwiftUI Views intermediaries for UIKit views? If so what are they wrappers for?
I think NavigationView -> UINavigationController etc...

Absolutely NOT.
First of all, there is no such thing as UIKit for other Apple platforms. So for example, you will see other counterparts like AppKit for macOS, which is enough to say NO to your question.
Second of all, Apple is hardly trying to build all SwiftUI components natively. But until all of them are available, they are using other platforms' existing components instead.
Maybe they will decide to not do it someday, who knows...
This repository can help you see which is linked with which for now

Related

How do I set the blur intensity of a system material in SwiftUI 3?

SwiftUI 3 introduced the concept of system materials – akin to a UIVisualEffectView with a UIBlurEffect.
Text("Hello world!")
.padding()
.background(.thinMaterial)
How do I change the intensity of blur applied by a system material?
SwiftUI currently does not offer a way to achieve this. It is, however, possible to achieve using SwiftUIX.
Install SwiftUIX via the Swift Package Manager.
In your code, import SwiftUIX.
Use VisualBlurEffectView with the .intensity(_:) modifier.
Text("Hello world!")
.background {
VisualEffectBlurView(blurStyle: .systemThinMaterial)
.intensity(0.5)
}
Disclaimer: Both this answer and the question were written to document SwiftUIX (an MIT-licensed open-source package) in a Q/A style format. As of writing this question I am currently not aware of any simple way to achieve this via UIKIt, and will gladly amend the answer to prescribe an official approach if/when one becomes available. I'd also love to just dump the code specific to this component, but it relies on a number of extensions/hacks that are spread across the SPM package that would be impractical to isolate just for the purpose of bundling a copy-paste solution to this answer.

What is the NSUbiquitousKeyValueStore equivalent for watchOS?

App Groups is sadly not supported on watchOS still and NSUbiquitousKeyValueStore is available for every platform except watchOS. I've read the Keeping Your watchOS Content Up to Date and mentions iCloud and they make it sound so easy but don't provide an example. It seems I have to create a whole client-side CloudKit infrastructure to support it and seems like overkill, then requires the rest of the platforms to do the same just because watchOS is the odd ball.
Is there a simple key/value iCloud store equivalent in watchOS that I'm missing? It seems really difficult to share cloud data when you add watchOS to the mix. I tried using the iPhone as a source of truth and communicate with watchOS, but was very clunky and requires them to be in range with each other or they become out of sync. Any help or guidance would be greatly appreciated!
NSUbiquitousKeyValueStore is available starting with watchOS 9.0
Doc: https://developer.apple.com/documentation/foundation/nsubiquitouskeyvaluestore

Is it possible to use SwiftUI for UI in an AR-App using SceneKit?

I am currently working on an AR-App using SceneKit. I can't use RealityKit because I need Image Recognition which it doesn't support at this time.
With this tutorial I found a way to integrate SwiftUI into the AR-Scene but not as a typical UI-/HUD-Element.
Is it there a way to use SceneKit for Image Recognition and SwiftUI as UI?
In a certain way you can. Here's a Medium story on this topic. Also this SO post might be useful.

Is it possible to design for CarPlay with SwiftUI?

I have been playing around with SwiftUI since the beta launched and was curious if anyone has figured out way to design for CarPlay in Xcode using SwiftUI? It doesn't seem to be available in Apple's list of devices and so far I haven't been able to find a way to enable it as a secondary screen.
Currently using Xcode 11 Beta 5. Tried seeing if CarPlay could be added as a .previewDevice, but that is specifically for hardware.
You don't need MFi for CarPlay, you need CarPlay entitlement.
Still not sure about SwiftUI and CarPlay.
I am sure SwiftUI will not support some specific CarPlay categories such as Media Playback and Messaging & VoIP, but maybe with Navigation or Automaker.
You won't be able to see CarPlay in Xcode because it's only for people who are enrolled with Apple MFi Program. This gives you access to the tools, documentation, technical specs and the license itself to develop for CarPlay. Please see here for the MFI program and here for the MFI FAQ.
A very good write up on StackOverflow can also be found here.
It is also currently unknown if CarPlay can be developed with SwiftuI because people who develop CarPlay apps need to sign a NDA. But I think Apple will continue to push SwiftUI so I don't see why it's not possible

Is SwiftUI framework declarative or imperative or neither?

I'm having a discussion with a collegue, who insists the SwiftUI is imperative. To me, it seems very declarative. Is he right?
As noted in numerous WWDC 2019 videos (e.g., SwiftUI Essentials and Introducing SwiftUI), SwiftUI is declarative. Apple repeatedly contrasts it to traditional, imperative approaches. The first line of their SwiftUI documentation says that it is for “declaring your app's user interface”. Apple’s SwiftUI Essentials WWDC 2019 video describes SwiftUI as their “new declarative framework.”
Admittedly, SwiftUI can be married with imperative techniques, too. For example, one can combine SwiftUI views with UIKit imperatively generated views/apps. In another example, when one adds a tap handler to a view element, one can subtly shift from the “what” of declarative programming to the “how” of imperative programming, as you outline a series of steps to be taken to achieve some task. Perhaps your colleague is alluding to one of these aspects of SwiftUI.
But it is inaccurate to contend that SwiftUI is an imperative framework. It is essentially declarative.
SwiftUI uses the programming paradigm known as declarative programming.
A major advantage of learning and using SwiftUI is allowing for cross-platform development for the different operating systems within the Apple ecosystem. No more having to learn four different frameworks if you want to build an app that has components on Apple Watch, Apple TV, MacBook Pro, and finally your iPhone.
It is important to know that SwiftUI does not replace UIKit. Instead, it is built on top of providing and an additional layer of abstractions for us.
Imperative mainly focuses on the how a program is doing something. Declarative in my mind means that SwiftUI plainly states what is going on via its syntax. In Apple's marketing blurb of SwiftUI they show a sample of code that is very declarative in my opinion. You can tell that in a view you can target a body and display images and vertically stack some text with in the body. I think its stating what is going on without low level syntax like:
#IBOutlet weak var CaptionLabel: UILabel!
#IBAction func Submit(_ sender: Any) {
CaptionLabel.text = "Hello World"
}
Based on the syntax above there is a lot of how something is working. You can see #IBAction which is declaring to the Interface builder that this is how a function is being set to a button press. To me this is kind of the how it is working not really what is happening. In the new SwiftUI behind the scenes maybe its still #IBAction and #IBOutlets but in my opinion Apple has made the syntax more declarative to humans and doesn't concern us with the behind the scenes things that are going on. I feel this way since SwiftUI is built on top of UIKit. The gauge I kind of use is if the syntax is human readable and its abstracting away a lot of the low level details of how its working then its more declarative.