简体   繁体   English

斯威夫特:意外地发现零

[英]Swift: Unexpectedly found nil

I'm not sure where the nil value is here. 我不确定nil值在哪里。 I also tried explicitly allocating the error var and still had the issue. 我还尝试显式分配错误var,但仍然存在问题。 The code is taken almost directly from Twitter documentation. 该代码几乎直接取自Twitter文档。

let statusesShowEndpoint = "https://api.twitter.com/1.1/users/profile_banner.json?"
let params = ["screen_name":"twitter"]
var clientError :NSError?

let request = Twitter.sharedInstance().APIClient.URLRequestWithMethod(
            "GET", URL: statusesShowEndpoint, parameters: params,
           error: &clientError)

    if request != nil {
        Twitter.sharedInstance().APIClient.sendTwitterRequest(request) {
                (response, data, connectionError) -> Void in
                if (connectionError == nil) {
                    var jsonError : NSError?
                    let json : AnyObject? =
                    NSJSONSerialization.JSONObjectWithData(data,
                        options: nil,
                        error: &jsonError)
                }
                else {
                    println("Error: \(connectionError)")
                }
        }
    }
    else {
        println("Error: \(clientError)")
    }

I get this error on the request: 我在请求中收到此错误:

fatal error: unexpectedly found nil while unwrapping an Optional value

I haven't spent much time with the twitter api, but the http endpoint you are trying to access requires that you have the qAuth authority have you done this? 我没有花很多时间在twitter api上,但是您尝试访问的http端点要求您具有qAuth权限,您这样做吗? as the http link is coming back "bad authentication data" when i try to access it 当我尝试访问它时,http链接返回“身份验证数据错误”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM