2015-12-01 4 views
0

Я обновляемом мой проект от Swift 1.2 до Swift 2.Миграция Swift 2 «Использование неразрешенного идентификатора„***“»

Я использую эту возможность, чтобы обновить много Либерал, что я использую, в в частности, Аламофир.

Но теперь я получил эту ошибку на многих из моего запроса:

Использование неразрешенного идентификатора 'notifTypeJSON'

Вот код одного из FUNC:

func getNotifications(failure failure: (NSError) ->(), success: ([Notification]) ->()) { 
    Alamofire.request(Router.Notifications) 
     .validate() 
     .responseJSON { response in 
      if let error = response.result.error { 
       failure(error) 
      } else { 
       var json = JSON(response.data!) 
       let status = json["error"].intValue 
       if status != 0 { 
        failure(self.createError(status)) 
       } else { 
        var notifications = [Notification]() 
        let notificationsList = json["notification"] 
        for (index: String, notifTypeJSON: JSON) in notificationsList { 
         if let notifJSON = notifTypeJSON[NotificationTypes.Generic.rawValue].dictionaryObject { 
          notifications.append(GenericNotification(json: notifJSON)) 
         } 
         else if let notifJSON = notifTypeJSON[NotificationTypes.Follow.rawValue].dictionaryObject { 
          notifications.append(FollowNotification(json: notifJSON)) 
         } 
         else if let notifJSON = notifTypeJSON[NotificationTypes.Comment.rawValue].dictionaryObject { 
          notifications.append(CommentNotification(json: notifJSON)) 
         } 
         else if let notifJSON = notifTypeJSON[NotificationTypes.Like.rawValue].dictionaryObject { 
          notifications.append(LikeNotification(json: notifJSON)) 
         } 
        } 
        DDLogInfo("SeetyAPI getNotifications() success") 
        success(notifications) 
       } 
      } 
    } 
} 

ответ

1

В Swift 2 мы изменили способ замены словаря с помощью кортежа: типы должны быть в отдельном кортеже.

Пример До:

for (key:String, value:Int) in xxx { 

Пример После:

for (key, value):(String, Int) in xxx { 

Так что для вас, вам нужно будет заменить это:

for (index: String, notifTypeJSON: JSON) in notificationsList { 

с этим:

for (index, notifTypeJSON):(String, JSON) in notificationsList { 
Смежные вопросы