Apple Watch拡張機能の場合、AlertControllerを表示していて、「プリセット2」の代わりに「プリセットオプション(2)」のような表示が表示されます。私はオプションを取り除くにはどうすればよい文字列表示のオプションの取得
ここif let s = info["description"]
{
let action = WKAlertAction(title: "OK", style: WKAlertActionStyle.Default, handler: {() -> Void in
//
})
//let arr = s.componentsSeparatedByString("_")
let arr = s.characters.split("_", maxSplit: Int.max, allowEmptySlices: false).map(String.init)
self.presentAlertControllerWithTitle("Preset \(arr[0])", message: "\n\(arr[1])", preferredStyle: WKAlertControllerStyle.Alert, actions: [action])
}
がある(文字列がそれらを持っていたとは思いませんでした)どのように情報[「説明」]導き出される:配列の
func session(session: WCSession, didReceiveMessage message: [String : AnyObject])
{
if let info = message as? Dictionary<String,String>{
if let s = info["description"]
{
...
ただ、今後の参考のために、任意の変数はオプションとすることができます。 – JAL
Preset \(arr [0])のようにアンラップを強制してみてください! –
@ VishalSonawane **いいえ。**本当に良い理由がある場合を除き、決してアンラップを強制しないでください。 – JAL