2016-08-16 7 views
7

最近、Xcode 8 beta 6(8S201h)ではこれが問題になっています。他UIApplicationLaunchOptionsShortcutItemKeyはSwift 3にはありませんか?

enter image description here

誰でもこの問題を持つ:ここで

UIApplicationLaunchOptionsShortcutItemKey 

はエラーですか?

var performShortcutDelegate = true 
if let shortcutItem = launchOptions[UIApplicationLaunchOptionsKey.shortcutItem] as? UIApplicationShortcutItem { 
    print("ok") 
    self.shortcutItem = shortcutItem 
    performShortcutDelegate = false 
} 
return performShortcutDelegate 
+0

は 'guard'を使用してみてください:http://stackoverflow.com/questions/33689933/ambiguous-reference-to-member -subscript-on-dictionary –

+0

no luck :(同じエラー –

+0

あなたはまだメンバーサブスクリプトへのあいまいな参照を取得していますか?あなたのコードは、表示されているとおりに正しいと見なされるので、囲む関数と関係します。また、あなたのショートカットコードの周りに 'if #available(iOS 9.0、*){}'ブロックを含める必要があります。より多くの情報/文脈が参考になります:) –

答えて

5

定数が変更されています(documentationを参照)。また、含まれている値を使用する前に、launchOptionsをアンラップする必要があります。

コンテキストの囲み機能が含まれています。

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 
    if let launchOptions = launchOptions { 
     if #available(iOS 9.0, *) { 
      if let shortcutItem = launchOptions[UIApplicationLaunchOptionsKey.shortcutItem] as? UIApplicationShortcutItem { 
       print("Shortcut: \(shortcutItem)") 
      } 
     } 
    } 
    return true 
} 
+1

これが['application(_:willFinishLaunchingWithOptions:)'](https://developer.apple.com/reference/uikit/uiapplicationdelegate/1623032-application)にある場合、 'launchOptions'ディクショナリはすでにキータイプ' UIApplicationLaunchOptionsKey'を持っていることがわかります。だから、 'launchOptions [.shortcutItem]'だけを使うことができます。 – rickster

+1

いいえ、私はまだ同じ正確なエラーを取得します。 –

+0

質問を更新して、コードとそれに含まれる機能を含めることはできますか? (理想的には、スクリーンショットではなくインラインコードとして貼り付けてください) –

1

launchOptionsディクショナリタイプが[UIApplicationLaunchOptionsKey:AnyObject]に変更されました。

private func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: AnyObject]?) -> Bool { 

    ... 

} 
0

Xcode8を使用して私のためにその仕事。これを試してみて、swift3

//Check for ShortCutItem 
    if #available(iOS 9.0, *) { 
     if let shortcutItem = launchOptions?[UIApplicationLaunchOptionsKey.shortcutItem] as? UIApplicationShortcutItem { 
     } 
    } 
関連する問題