4

I am using Firebase in my SwiftUI/Combine app, and I have noticed several warnings that I would like to troubleshoot. They're not breaking things, but I'd like to resolve them. I am getting these warning using Xcode 12.4 with the latest Swift Package Dependencies: GoogleUtilities 7.2.2 and and Firebase 7.7.0.

This is the first warning as it appears in the console:

[GoogleUtilities/AppDelegateSwizzler][I-SWZ001014] App Delegate does not conform to UIApplicationDelegate protocol.

For reference, this is how I am configuring Firebase:

import SwiftUI
import Firebase

@main
struct MyApp: App {
    
    @StateObject var authState = AuthState()
    
    init() {
        FirebaseApp.configure()
    }
    
    var body: some Scene {
        
        WindowGroup {
            RootView()
                .environmentObject(authState)
        }
    }
}

This is the second warning, which appears after I set a navigation bar title using the .navigationBarTitle modifier.

[LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x280c8cfa0 'BIB_Trailing_CB_Leading' H:[_UIModernBarButton:0x109219b60]-(6)-[_UIModernBarButton:0x109218760'Fullres']   (active)>",
    "<NSLayoutConstraint:0x280c8cff0 'CB_Trailing_Trailing' _UIModernBarButton:0x109218760'Fullres'.trailing <= _UIButtonBarButton:0x109217100.trailing   (active)>",
    "<NSLayoutConstraint:0x280c8dd60 'UINav_static_button_horiz_position' _UIModernBarButton:0x109219b60.leading == UILayoutGuide:0x2816bcfc0'UIViewLayoutMarginsGuide'.leading   (active)>",
    "<NSLayoutConstraint:0x280c8ddb0 'UINavItemContentGuide-leading' H:[_UIButtonBarButton:0x109217100]-(0)-[UILayoutGuide:0x2816bcee0'UINavigationBarItemContentLayoutGuide']   (active)>",
    "<NSLayoutConstraint:0x280c88f00 'UINavItemContentGuide-trailing' UILayoutGuide:0x2816bcee0'UINavigationBarItemContentLayoutGuide'.trailing == _UINavigationBarContentView:0x109214320.trailing   (active)>",
    "<NSLayoutConstraint:0x280c8e530 'UIView-Encapsulated-Layout-Width' _UINavigationBarContentView:0x109214320.width == 0   (active)>",
    "<NSLayoutConstraint:0x280c892c0 'UIView-leftMargin-guide-constraint' H:|-(0)-[UILayoutGuide:0x2816bcfc0'UIViewLayoutMarginsGuide'](LTR)   (active, names: '|':_UINavigationBarContentView:0x109214320 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x280c8cfa0 'BIB_Trailing_CB_Leading' H:[_UIModernBarButton:0x109219b60]-(6)-[_UIModernBarButton:0x109218760'Fullres']   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.

Has anyone attempted to resolve these warnings?

New Dev
  • 48,427
  • 12
  • 87
  • 129

1 Answers1

7

The first message is caused by the fact that Firebase tries to find an AppDelegate, but as your app follows the new SwiftUI app life cycle, it doesn't have one.

You can eliminate this warning by adding an AppDelegate like this:

import SwiftUI
import Firebase

class AppDelegate: NSObject, UIApplicationDelegate {
  func application(_ application: UIApplication,
                   didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
    FirebaseApp.configure()
    return true
  }
}

@main
struct MyApp: App {
  @UIApplicationDelegateAdaptor(AppDelegate.self) var delegate   
  @StateObject var authState = AuthState()
    
  var body: some Scene {      
    WindowGroup {
      RootView()
        .environmentObject(authState)
    }
  }
}

For more details, see my article on the topic.

As a side note, we're looking into other ways for initialising the Firebase SDK (as swizzling has its challenges) - see this comment on a similar GitHub issue.

As for the second warning, this is unrelated to Firebase. If your search StackOverflow, you'll find a number of other people have run into this issue as well. This question looks very similar and has an accepted answer that you might want to try.

Peter Friese
  • 6,709
  • 31
  • 43
  • Thank you. But I'm wondering: Was it your intention to call `FirebaseApp.configure()` in both the SwiftUI app life cycle initializer and the `AppDelegate`, as you have done? Would including an empty AppDelegate work instead? I believe Apple has deprecated `AppDelegate` so I'm eager to use it as minimally as possible. Thanks! – Anton Mar 28 '22 at 13:30
  • 1
    Calling `FirebaseApp.configure()` in both locations was a mistake I made when copying the code. You should only call this once. If you use an AppDelegate, call `.configure` in the AppDelegate. I am not aware that Apple has officially deprecated AppDelegate. I've updated the code snippet - thanks for spotting this! – Peter Friese Mar 28 '22 at 14:56