Hi
I'm trying to add 3d touch quick actions to an app but i keep on getting "fatal error: unexpectedly found nil while unwrapping an Optional value" whenever i try to edit a UITextfield or a UIButton using the quick action list, the app crash on launch
heres the code using Xcode Version 7.0.1 (7A1001) with swift
I'm trying to add 3d touch quick actions to an app but i keep on getting "fatal error: unexpectedly found nil while unwrapping an Optional value" whenever i try to edit a UITextfield or a UIButton using the quick action list, the app crash on launch
heres the code using Xcode Version 7.0.1 (7A1001) with swift
Code:
import UIKit
@available(iOS 9.0, *)
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
@IBOutlet weak var Button: UIButton!
@IBOutlet weak var Field: UITextField!
var window: UIWindow?
var shortcutItem: UIApplicationShortcutItem?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
var performShortcutDelegate = true
if let shortcutItem = launchOptions?[UIApplicationLaunchOptionsShortcutItemKey] as? UIApplicationShortcutItem {
self.shortcutItem = shortcutItem
performShortcutDelegate = false
}
return performShortcutDelegate
}
func application(application: UIApplication, performActionForShortcutItem shortcutItem: UIApplicationShortcutItem, completionHandler: (Bool) -> Void) {
completionHandler( handleShortcut(shortcutItem) )
}
func handleShortcut( shortcutItem:UIApplicationShortcutItem ) -> Bool {
var succeeded = false
if( shortcutItem.type == "First" ) {
succeeded = true
Button.setTitle("whatever", forState: UIControlState.Normal) //the error
Field.text = "some text" //the error
//whatever variable outlet i try change gives error there
}
if( shortcutItem.type == "Second" ) {
succeeded = true
// haven't added anything there yet so app launch normally and does nothing
}
if( shortcutItem.type == "Third" ) {
succeeded = true
}
if( shortcutItem.type == "Fourth" ) {
succeeded = true
}
return succeeded
}
func applicationDidBecomeActive(application: UIApplication) {
guard let shortcut = shortcutItem else { return }
handleShortcut(shortcut)
self.shortcutItem = nil
}
}
code sourcefunc handleShortcut( shortcutItem:UIApplicationShortcutItem ) -> Bool {
var succeeded = false
if( shortcutItem.type == "First" ) {
succeeded = true
Button.setTitle("whatever", forState: UIControlState.Normal) //the error
Field.text = "some text" //the error
//whatever variable outlet i try change gives error there
}
if( shortcutItem.type == "Second" ) {
succeeded = true
// haven't added anything there yet so app launch normally and does nothing
}
if( shortcutItem.type == "Third" ) {
succeeded = true
}
if( shortcutItem.type == "Fourth" ) {
succeeded = true
}
return succeeded
}