gpt4 book ai didi

ios - 由于信号段错误导致命令失败 11 Parse SDK 或 Facebook graph API 疑似罪魁祸首

转载 作者:行者123 更新时间:2023-11-29 01:05:30 26 4
gpt4 key购买 nike

我在构建我的应用程序时遇到“命令因信号而失败:段错误:11”错误。我怀疑触发此错误的代码出现在自定义类的 viewDidLoad 方法中,该类的完整代码如下。

import UIKit
import Bolts
import Parse
import FBSDKLoginKit
import FBSDKCoreKit
import FBSDKShareKit
import ParseFacebookUtilsV4

class SignUpViewController: UIViewController {

@IBAction func signUp(sender: AnyObject) {
}

@IBOutlet weak var userImage: UIImageView!


@IBOutlet weak var interestedInWomen: UISwitch!


override func viewDidLoad() {
super.viewDidLoad()


let graphRequest = FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, gender"])
graphRequest.startWithCompletionHandler( {

(connection, result, error) -> Void in

if error != nil {
print(error)

} else if let result = result {

PFUser.currentUser()?["gender"] = result["gender"]!
PFUser.currentUser()?["name"] = result["name"]!
PFUser.currentUser()?.saveInBackground()


var userId = result["id"] as String

var facebookProfilePictureUrl = "https://graph.facebook.com/" + userId + "picture?type=large"

if let fbipicUrl = NSURL(string: facebookProfilePictureUrl) {

if let data = NSData(contentsOfURL: fbipicUrl) {

self.userImage = UIImage(data: data)

}

}

}
})
}

可以在此处查看错误日志的一些输出(输出更多,但这部分目前与我相关):

    1.  While type-checking 'viewDidLoad' at /Users/oivind/Dropbox/søndagsåpent/ParseServerStarterProject/ParseStarterProject/SignUpViewController.swift:28:14
2. While type-checking expression at [/Users/oivind/Dropbox/søndagsåpent/ParseServerStarterProject/ParseStarterProject/SignUpViewController.swift:33:9 - line:62:10] RangeText="graphRequest.startWithCompletionHandler( {

(connection, result, error) -> Void in

if error != nil {
print(error)

} else if let result = result {

PFUser.currentUser()?["gender"] = result["gender"]!
PFUser.currentUser()?["name"] = result["name"]!
PFUser.currentUser()?.saveInBackground()


var userId = result["id"] as String

var facebookProfilePictureUrl = "https://graph.facebook.com/" + userId + "picture?type=large"

if let fbipicUrl = NSURL(string: facebookProfilePictureUrl) {

if let data = NSData(contentsOfURL: fbipicUrl) {

self.userImage = UIImage(data: data)

}

}

}
})"
3. While type-checking declaration 0x7ffb2a8175b8 at /Users/oivind/Dropbox/søndagsåpent/ParseServerStarterProject/ParseStarterProject/SignUpViewController.swift:47:17
4. While type-checking expression at [/Users/oivind/Dropbox/søndagsåpent/ParseServerStarterProject/ParseStarterProject/SignUpViewController.swift:47:30 - line:47:46] RangeText="result["id"] as S"
5. While type-checking expression at [/Users/oivind/Dropbox/søndagsåpent/ParseServerStarterProject/ParseStarterProject/SignUpViewController.swift:47:30 - line:47:41] RangeText="result["id"]"

我使用的是最新版本的 Xcode 7.3(但不是测试版)。

到目前为止我发现,如果我注释掉这部分代码,应用程序将构建得非常好:

    var userId = result["id"] as String
var facebookProfilePictureUrl = "https://graph.facebook.com/" + userId + "picture?type=large"
if let fbipicUrl = NSURL(string: facebookProfilePictureUrl) {
if let data = NSData(contentsOfURL: fbipicUrl) {
self.userImage = UIImage(data: data)
}
}

但我终究无法弄清楚到底是什么导致了这个错误。

这是我关于 SO 的第一个问题,我已经搜索了一段时间,我发现了一个类似的线程,它似乎引导我朝着正确的方向前进,但那里的答案并没有完全帮助我解决我的问题,另一个似乎有一些相关建议的线程可以在这里找到:

Command failed due to signal: Segmentation fault: 11

奇怪的是,在构建错误出现后,Xcode 中也出现了一个错误,每当我编辑这个特定的 swift 文件时,突出显示该颜色的语法就会每隔 60 秒左右崩溃一次。现在这可能只是一个随机事件,但我也可能在某种程度上是相关的(也许这段代码的某些部分非常困惑,以至于它不仅不会构建而且还会使部分 Xcode 崩溃 :P )

最佳答案

好的,经过几个小时的故障排除后,我能够将错误隔离到导致错误的行;

var userId = result["id"] as String

问题是我不得不强制解包结果数组的内容,所以对我来说,解决方案是几乎不修改该行,使其看起来像这样;

let userId = result["id"]! as! String

现在我不知道为什么编译器会崩溃。我本来希望有一个更具描述性的错误消息(或者也许我只是还没有阅读 Xcode 错误日志的经验)。

无论哪种方式,错误都会消失,并且应用程序会按照我想要的方式编译,所以我很高兴。

关于ios - 由于信号段错误导致命令失败 11 Parse SDK 或 Facebook graph API 疑似罪魁祸首,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36432199/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com