Disable IQKeyboardManager in ViewController in Swift - swift

To disable IQKeyboardManager in a viewcontroller in Swift, you apparently need to get a reference to the instance and then disable it. However, I cannot figure out a way to reference it. I originally import the library in the appDelegate which is written in Objective-C as
import IQKeyboardManagerSwift
Give me the error:
No Such Module IQKeyboardManagerSwift
If I merely try to put the lines below in viewDid Load:
IQKeyboardManager.shared().isEnabled = false
IQKeyboardManager.shared().isEnableAutoToolbar = false
Then I get error
IQKeyboardManager not found.
How do you disable IQKeyboardManager for a specific view controller in Swift?

The documentation mentions a possible solution: (the syntax may be a bit different depending on the version of the framework you're using)
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
IQKeyboardManager.shared().isEnabled = true
IQKeyboardManager.shared().enabledDistanceHandlingClasses.append(EnabledViewController.self)
IQKeyboardManager.shared().disabledDistanceHandlingClasses.append(DisabledViewController.self)
return true
}
if you need the toolbar disabled/enabled as well
IQKeyboardManager.shared().enabledToolbarClasses.append(ToolbarEnabledViewController.self)
IQKeyboardManager.shared().disabledToolbarClasses.append(ToolbarDisabledViewController.self)

Related

Firebase errors, adding using SPM

I have installed Firebase SDK using SPM and i got this, what should i do?
IMAGE!
import UIKit
import Firebase
#main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
FirebaseApp.configure()
return true
}
The Firebase team is actively working with the gRPC team on this issue and expect to resolve it in the next month or two. It's being tracked at https://github.com/firebase/firebase-ios-sdk/issues/9790.
In the meantime, the gRPC warnings do not affect Firebase functionality and can safely be ignored.

How would you fix Xcode Firebase Integration With SwiftUI saying: format:#"`[FIRApp configure];` (`FirebaseApp.configure()` in Swift) could not find "

I am clueless as to what I need to fix this problem.
I have Firebase running in my workspace in Xcode and I followed the Firebase instructions which are:
import UIKit
import Firebase
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions:
[UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
return true
}
}
But the issue is when I run the project the simulation is white. And goes to FirApp.m and says the following code.
if (!options) {
[NSException raise:kFirebaseCoreErrorDomain
format:#"`[FIRApp configure];` (`FirebaseApp.configure()` in Swift) could not find "
#"a valid GoogleService-Info.plist in your project. Please download one "
#"from %#.",
kPlistURL];
I was following CodingWithChris with this tutorial --> https://youtu.be/1HN7usMROt8?t=2363
You must make sure the GoogleService-Info.plist does not have a look like this GoogleService-Info.plist(5) when you download it again or it will not work.
To deal with black screen the error was the following:
Failed to instantiate the default view controller for UIMainStoryboardFile 'MainStoryboard' - perhaps the designated entry point is not set?
In the storyboard, make sure to uncheck the "Is initial View Controller" because it might be getting confused with multiple view controllers.
In the app go to app target and press the Info tab. There is minus or add in the value of "Main storyboard file base name" you need to use the minus to make it go away. Then on the "General tab" clear do the same thing for "Main Interface".

iOS Application with Firebase doesn't start with a slow internet connection

Since I upgraded to the new Firebase, my application doesn't start with a slow internet connection. It does when it is has a good connection and also when it hasn't got any connection at all. I think that I've set up everything properly since it wouldn't work at all if I made a mistake with the setup.
Here's my AppDelegate code:
import UIKit
import Firebase
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptionslaunchOptions: [NSObject: AnyObject]?) -> Bool {
UITabBar.appearance().tintColor = UIColor.redColor()
FIRApp.configure()
FIRDatabase.database().persistenceEnabled = true
return true
}
}
iOS includes a mechanism called watchdog, which will terminate any application that fails to launch in a certain time window. Any blocking task you do in application(_:didFinishLaunchingWithOptions:) has the potential to cause your app to be terminated if it takes too long. You should consider performing such tasks asynchronously.
You can put breakpoints or print statements in your code to determine which line is taking too long.

Parse+Facebook SDK Issues - Use of Unresolved Identifier 'PFFacebookUtils'

I understand that there have been similar posts about this issue, but nothing seems to be working.
I'm trying to enable my users to sign-up/in with Facebook, but I am having trouble getting the Facebook SDK working.
I have added the 'FBSDKCoreKit.Framework' framework as the Facebook guide says to do, as well as the 'ParseFacebookUtils.framework'. When I try and initialize facebook in my AppDelegate.swift, here..
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
Parse.setApplicationId("", clientKey: "")
PFFacebookUtils.initialize()
return true
I get the error that says "Use of unresolved identifier 'PFFacebookUtils'". I followed all the steps under 'Setup' in the Parse Docs.
This is all in Swift, and so here is my Bridging Header File...
// Use this file to import your target's public headers that you would like to expose to Swift
#import <Parse/Parse.h>
#import <ParseUI/ParseUI.h>
#import <Bolts/BFTask.h>
#import <ParseFacebookUtils/PFFacebookUtils.h>
#import <FBSDKCoreKit/FBSDKCoreKit.h>
What am I doing wrong? Very frustrated, but I will eventually figure it out.
Try this:
import Bolts
import ParseFacebookUtilsV4
import FBSDKCoreKit
import FBSDKLoginKit
From what I think, you might have used ParseFacebookUtilsV4.Framework (which is the latest support for Swift I am assuming) instead of ParseFacebookUtils.Framework (old or may be the one that requires objective C bridging headed).
So if you want your app to work as per the code you have, use the ParseFacebookUtils.Framework and avoid ParseFacebookUtilsV4.Framework. But if you want to use ParseFacebookUtilsV4.Framework, you have to do some changes in your swift Appdelegate:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
}
func applicationDidBecomeActive(application: UIApplication) {
FBSDKAppEvents.activateApp()
}
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool {
return FBSDKApplicationDelegate.sharedInstance() .application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
}
Bridging header changes:
#import <FBSDKCoreKit/FBSDKCoreKit.h>
Not sure about the Utils import, but if needed, replace the old import code #import ParseFacebookUtils/PFFacebookUtils.h in your bridging header with this one
#import <ParseFacebookUtilsV4/PFFacebookUtils.h>
Notice the small change with addition of V4.
I hope I may have helped you in someway.
Make sure you've set your bridging header correctly.
If you click your project in the "Project Navigator", then click your target, click Build Settings, and scroll down to "Swift Compiler - Code Generation", you should see a row for Objective-C Briding Header.
In this row, you need to enter your bridging header:
ProjectName/Your-Bridging-Header.h
This happened to me when I enabled frameworks in cocoapods (use_frameworks!) -- once I added "import ParseFacebookUtilsV4" Xcode was able to find PFFacebookUtils.

How does xCode decide in which file to begin code execution?

I'm using xCode 6 to write a simple game in Swift. I have a variety of files in the project. How does xCode know where to begin when executing the code? It seems to me that it automatically starts with the file that, following various tutorials, I have called "GameViewController.swift." But how does it decide to use this file first? Does it scan the source files for a UIViewController object and start there?
For iOS, Swift looks for a class with the #UIApplicationMain attribute, and uses that as the Application's delegate.
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
...
}
Using that attribute is equivalent to calling the UIApplicationMain function and passing the class’s name as the name of the delegate class. That in turn will handle loading your default Storyboard and load its initial view controller.
If no #UIApplicationMain is found, Swift looks for a file called main.swift and for a function called main inside of that and calls it.
if you are using storyboards, you have a setting called "Main Interface" on your target. This offers a dropdown list where you can select the storyboard file. i.e. Main.storyboard. This setting will be written to the Info.plist file that will be loaded at start time.
In this file a view controller is set as the initial view controller and will be loaded first.
To give you an idea of Apple architecture here's an example of a Cocoa app which applies to iOS Objective-C as well:
Every application starts at main but the developer entry point is usually AppDelegate. This applies to Swift as well, even if main has disappeared from the application lifecycle. Bear in mind, that main existed just to launch the app or few minor tweaks.
If you're using Storyboards, you'll be able to set the starting screen of your app from there, conversely if everything is done in code AppDelegate will be responsible of it at this point:
func application(application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {