ios - Xcode 7.3 更新后出现语法错误

标签 ios xcode swift

昨天我安装了新的 Xcode 7.3,我的问题开始了。

我必须对 swift 3 进行许多更改。 我通过 Xcode 的“自动更正”解决了许多更改。

但是有两件事无法自动解决:

问题 1 enter image description here

问题2

 for ( var x = 1; x < self.ACData.count; x ++ ) {

但我应该这样做:

enter image description here

如果我应用更正,我会得到以下结果:

for ( x in 2 ..< self.ACData.count ) {

这使我出现语法错误。 有人可以帮我吗? :)

更新

let app:UIApplication = UIApplication.sharedApplication()
  for oneEvent in app.scheduledLocalNotifications! {
    let notification: AnyObject = oneEvent
    let userInfoCurrent = notification.userInfo as! [NSObject: AnyObject]
    if userInfoCurrent["UUID"] == nil {
      app.cancelLocalNotification(notification as! UILocalNotification)
    }
}

最佳答案

问题 1:

不要沮丧,没有必要。您可以为 NSObject 输入一个字符串,因此只需编写以下内容:

let userInfoCurrent = notification.userInfo!

问题2:

去掉括号。这确实是修复它所要做的全部事情,不要写:

for ( x in 2 ..< self.ACData.count )

这不是正确的快速方式,它应该是:

for x in 2 ..< self.ACData.count {

更新:

根据上面显示的代码,我认为最好的方法是:

let app:UIApplication = UIApplication.sharedApplication()
for oneEvent in app.scheduledLocalNotifications! {
    let notification: AnyObject = oneEvent
    guard let userInfoCurrent = notification.userInfo,
          let uuid = userInfoCurrent["UUID"] else {
          app.cancelLocalNotification(notification as! UILocalNotification)        
          return //or continue, don't know if you want to keep looping after this
    }
    // Do something with UUID if it's not necessary you can update the code as follows:
    // guard let userInfoCurrent = notification.userInfo where userInfoCurrent["UUID"] != nil else {
}

我希望这能起作用

关于ios - Xcode 7.3 更新后出现语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36172078/

相关文章:

ios - 在WKWebview中突出显示文本时发生JavaScript异常

iphone - 更改标签并添加值

xcode - MACOSX El Capitan 上的 qt-everywhere-opensource-src-5.5.1 安装

ios - 使用带有 NavigationView 的 ScrollView 我得到空白的灰色空间

ios - 从 UIScrollView Swift 禁用水平滚动

ios - 为 UI 获取唯一值,同时保留重复项以在 map 上显示数据

ios - 如何在谷歌地图 iOS 上放置一个文本字段

ios - 为什么数据不在 View Controller 之间传递? swift 3

ios - 如何多次显示 admob 插页式广告?

ios - 防止用户在文本字段内选择或移动光标