SwiftUI: Cannot find type UIApplicationDelegate' in scope [closed] - swiftui

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed yesterday.
Improve this question
I am a beginner in Firebase. To get started, I wanted to implement the following tutorial:
https://youtu.be/F9Gs_pfT3hs
But I get the following error message:
Cannot find type 'UIApplicationDelegate' in scope
Can anyone help me? Thank you
My code so far:
import SwiftUI
import FirebaseCore
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
FirebaseApp.configure()
return true
}
}
#main
struct firebase3App: App {
#UIApplicationDelegateAdapter(AppDelegate.self) var delegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
}

Related

SwiftUI: Create a custom view that behaves like a SwiftUI List, taking multiple views in a closure and arranging them [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 months ago.
Improve this question
I am currently trying to create a custom view in SwiftUI that basically behaves like a SwiftUI List or Form. What I want is to achieve is something like the following:
CustomView {
Text("TBD")
Text("TBD")
Image(systemName: "heart")
}
The output of this custom view should then be a vertical list of the views that were passed in, plus some additional elements, like dividers. Something like what you would get from the following code:
VStack(alignment: .leading) {
Text("TBD")
Divider()
Text("TBD")
Divider()
Image(systemName: "heart")
}
The problem is that I have no idea how to create a generic view that would take any number of other views and then arrange them in such a way - Im not even sure if it is possible.
If there is anyone around that has experience with creating something like this, I would appreciate any hints or explanations.
Thanks!
Here is an example that works for 3 views:
struct CustomView: View {
let children: [AnyView]
init<C1: View, C2: View, C3: View>(#ViewBuilder content: () -> TupleView<(C1, C2, C3)>) {
self.children = [AnyView(content().value.0),
AnyView(content().value.1),
AnyView(content().value.2)]
}
var body: some View {
VStack(alignment: .leading) {
children[0]
Divider()
children[1]
Divider()
children[2]
}
}
}
I believe you need an init for each number of Views you want to support. Read more about this here:
https://forums.swift.org/t/swiftui-viewbuilder-result-is-a-tupleview-how-is-apple-using-it-and-able-to-avoid-turning-things-into-anyview/28181/14

I'm trying to convert a MSAL login from UIKit to SwiftUI and not sure how I can implement the MSALWebviewParameters into SwiftUI

I've implemented a lot of the MSAL into SwiftUI, but I'm running into a hiccup with MSALWebviewParameters which needs aUIViewController.
This is the current code portion that works with UIKit.
#objc func buttonTapped(_ snder: UIButton) {
do {
<Some Code that works>
let webViewParameters = MSALWebviewParameters(authPresentationViewController: self)
let interactiveParameters = MSALInteractiveTokenParameters(scopes: ["user.read"], webviewParameters: webViewParameters)
application.acquireToken(with: interactiveParameters) { (result, error) in
}
What I'm trying to do is move that function into an ObservableObject, but these three lines depend on a UIViewController. My end goal is to move this function into a classObservableObject

How do I send user inputs to a database using the forms feature in swift UI? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
I’m new to swift UI and programming in general. I’ve learnt the basics so far and now I want to be able to setup a simple form in my app. I can design the form no problem. But I’m not sure what function to call CIA the button action or the code to get that information from the user to a database. Can someone help to explain how to set that up and which database to use to collect the user information?
I can't set the database up for you, as each database has its unique ways of doing so. However, I am giving you a basic structure that would help you link your SwiftUI view to the back-end(your database).
Setting up your form
import SwiftUI
struct ContentView: View {
#State var firstName = ""
#State var lastName = ""
#State var age = ""
var body: some View {
TextField("Enter First Name", text: $firstName)
TextField("Enter Last Name", text: $lastName)
TextField("Age", text: $age)
Button(action: {
addUser(firstName: firstName, lastName: lastName, age: Int(age) ?? 0)
}) {
Text("Save to database")
}
}
}
Saving result to back-end:
import CoreData
func addUser(firstName: String, lastName: String, age: Int) {
/*
code here would be using Core Data structure
do not copy paste, only used as reference
*/
let newUser = User(context: context)
newUser.firstName = firstName
newUser.lastName = lastName
newUser.age = age
do {
try context.save()
print("Successfully saved to Core Data.")
} catch {
print(error.localizedDescription)
}
}
Keep in mind that you would have to do your own research on how to save results using your own database. The code in addUser() would not work if you are using something other than Core Data. In your case, I would suggest you to try Firebase and perhaps, you could use Firebase Firestore as it seems like it suits your needs.

How can I delay the obscuring/masking of characters in SwiftUI's SecureField so that each typed character shows for ~1sec before it's hidden? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
When using SwiftUI's SecureField the user's input it obscured / masked / turned into • immediately, which makes it difficult to confirm that one has actually typed the password correctly. Several of our users have complained about this, and it seems that most people expect to see the character they typed for about a second or so before it disappears, which gives them visual confirmation that they tapped the correct letter and can now move on w/o worrying.
Is it possible to add a delay in there and show the last typed character for a moment?
I don't think this is possible in SwiftUI at the moment, but here's the hack we've been using in the meantime. It stacks a SecureField on top of a TextField and toggles their opacities when the user clicks on the eye (to show the text). Granted, it shows the entire String and not the last letter, but it works.
I'm sure there are open source libraries of ways to do this in UIKit that you could convert, but I'll let someone else answer that.
struct SecureTextFieldView: View {
#State var text: String = ""
#State var showText: Bool = false
var body: some View {
ZStack {
TextField("Password", text: $text)
.opacity(showText ? 1.0 : 0.0)
SecureField("Password", text: $text)
.opacity(showText ? 0.0 : 1.0)
}
.padding()
.background(
Color(UIColor.secondarySystemBackground).cornerRadius(10)
)
.overlay(
Image(systemName: "eye.fill")
.foregroundColor(showText ? .black : .gray)
.padding(.trailing)
.onLongPressGesture(minimumDuration: 20, maximumDistance: 30, pressing: { (_) in
showText.toggle()
}, perform: {})
, alignment: .trailing
)
.padding()
}
}
struct SecureTextFieldView_Previews: PreviewProvider {
static var previews: some View {
SecureTextFieldView()
}
}

How to accept CloudKit shares with the new SwiftUI app lifecycle?

In the iOS 13 world, I had code like this:
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
func windowScene(_ windowScene: UIWindowScene, userDidAcceptCloudKitShareWith cloudKitShareMetadata: CKShare.Metadata) {
// do stuff with the metadata, eventually call CKAcceptSharesOperation
}
}
I am migrating my app to the new SwiftUI app lifecycle, and can’t figure out where to put this method. It used to live in AppDelegate pre-iOS13, and I tried going back to that, but the AppDelegate version never gets called.
There doesn’t seem to be a SceneDelegateAdaptor akin to UIApplicationDelegateAdaptor available, which would provide a bridge to the old code.
So, I’m lost. How do I accept CloudKit shares with SwiftUI app lifecycle? 🙈
You can still use AppDelegate with SwiftUI's new life-cycle until Apple releases APIs to handle this natively in SwiftUI’s App Life-cycle.
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
return true
}
}
#main
struct MyApp: App {
#UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
Read this for more