Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 未解析标识符(swift)的使用_Ios_Swift_Identifier - Fatal编程技术网

Ios 未解析标识符(swift)的使用

Ios 未解析标识符(swift)的使用,ios,swift,identifier,Ios,Swift,Identifier,尝试在Xcode中运行项目时收到错误。由于某种原因,“userid”函数将无法构建,而且我对编程相当陌生,因此我不知道如何实现这一点。简单地说,给我一个错误的那一行应该允许用户登录instagram帐户以使用该应用程序。我得到了一个错误,读 使用未解析标识符“userID” 这是我的密码: if (result.result.isSuccess) { let json = JSON(result.result.value!) if (self.loginTy

尝试在Xcode中运行项目时收到错误。由于某种原因,“userid”函数将无法构建,而且我对编程相当陌生,因此我不知道如何实现这一点。简单地说,给我一个错误的那一行应该允许用户登录instagram帐户以使用该应用程序。我得到了一个错误,读

使用未解析标识符“userID”

这是我的密码:

      if (result.result.isSuccess) {
      let json = JSON(result.result.value!)

      if (self.loginType == .Instagram) {
        if let accessToken = json["access_token"].string, _ = json["user"]["id"].string {
          print("Logged into Instagram")
          let user = NSEntityDescription.insertNewObjectForEntityForName("User", inManagedObjectContext: self.coreDataStack.context) as! User
          user.userID = userID
          user.accessToken = accessToken
          user.placesType = "Establishment"
          user.uberAccessToken = ""
          self.coreDataStack.saveContext()
          self.performSegueWithIdentifier("unwindToMapView", sender: ["user": user])
        }
      } else if (self.loginType == .Uber) {
        if let accessToken = json["access_token"].string {
          print("Logged into Uber")
          if let fetchRequest = self.coreDataStack.model.fetchRequestTemplateForName("UserFetchRequest") {
            do {
              let results = try self.coreDataStack.context.executeFetchRequest(fetchRequest) as! [User]
              let user = results.first!
              user.uberAccessToken = accessToken
              user.uberAccessTokenExpiryDate = NSDate().dateByAddingTimeInterval((60 * 60 * 24) * 30)
              user.uberMostRecentRequestID = ""
              self.coreDataStack.saveContext()
              self.performSegueWithIdentifier("unwindToUberView", sender: ["user": user])
            } catch {
              self.showAlertWithMessage("Please try again!", title: "Couln't Fetch User", button: "Ok")
              print("Couldn't fetch user")
              self.close()
你的问题在于

if let accessToken = json["access_token"].string, _ = json["user"]["id"].string {
您正在将用户id分配给
而不是
用户id
。 试试这个:

if let accessToken = json["access_token"].string, userID = json["user"]["id"].string {

用户ID应该来自哪里?您不需要定义itI,它会假定您需要执行
let userID=json[“user”][“id”].string
在您的
if
语句中。将下划线字符替换为
userID
@vadian我要替换哪个下划线?这很有效,因此应用程序会生成,但每次输入登录信息时它都会崩溃,所以我正在查看问题所在,感谢您的建议如果您有新问题,自由地问一个新问题;包括控制台日志和相关代码。注意强制展开的选项;)好的,谢谢!这个平台对于问题以及如何“假设”提问非常敏感,我会记住这一点。是的:)但是我不想把你链接到“提问”按钮。还是一本不错的推荐书;)哦,顺便说一下,如果这回答了你的问题,请随意接受答案:)