Swift RSS Feed不会显示页面

时间:2016-11-03 16:15:44

标签: ios swift rss swift3 rss-reader

当我运行应用程序时,UITableView会显示文章,但是当我点击它时会崩溃并告诉我它发现了一个致命的错误:在解开一个Optional值时意外地发现了nil。我知道它正在谈论变量链接,但我不确定为什么它没有得到文章的链接。这不是我的代码,但任何人都可以免费使用它,它是在较旧的swift中制作的,所以我不得不更新它,但卡住了。它也是我能找到的最新的rss阅读器文件或者tut因为我找不到比Swift 2.3更新的文件。这是错误所在的页面:

import UIKit 

class DetailsViewController: UIViewController, UIWebViewDelegate {

// outlet - activity indicator
@IBOutlet var spinner: UIActivityIndicatorView!

// outlet - web view
@IBOutlet var myWebView: UIWebView!

// refresh button
@IBAction func refreshButtonClicked(sender: UIBarButtonItem) {
    self.refreshWebView()
}


// link to browse (this value set by parent controller)
var link: String?               <-----***ERROR HERE***-----




// MARK: - view functions

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.

    // set webview delegate
    self.myWebView.delegate = self

    // start spinner
    self.spinner.startAnimating()

    // load url in webview
    if let fetchURL = NSURL(string: self.link! ) {
        let urlRequest = NSURLRequest(url: fetchURL as URL)
        self.myWebView.loadRequest(urlRequest as URLRequest)
    }

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}




// MARK: - Webview delegate

func webViewDidFinishLoad(_ webView: UIWebView) {

    // stop spinner
    self.spinner.stopAnimating()
}

func webView(_ webView: UIWebView, didFailLoadWithError error: Error) {

    // stop spinner
    self.spinner.stopAnimating()

    // show error message
    self.showAlertMessage(alertTitle: "Error", alertMessage: "Error while loading url.")
}




// MARK: - Utility function

// refresh webview
func refreshWebView(){

    // start spinner
    self.spinner.startAnimating()

    // reload webview
    self.myWebView.reload()

}

// show alert with ok button
private func showAlertMessage(alertTitle: String, alertMessage: String ) -> Void {

    // create alert controller
    let alertCtrl = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: UIAlertControllerStyle.alert) as UIAlertController

    // create action
    let okAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler:
        { (action: UIAlertAction) -> Void in
            // you can add code here if needed
    })

    // add ok action
    alertCtrl.addAction(okAction)

    // present alert
    self.present(alertCtrl, animated: true, completion: { (void) -> Void in
        // you can add code here if needed
    })
}

}

我在链接文件中唯一的代码就是这个(抱歉它不会让我在代码视图中直接使用它):

import Foundation

//RSS Feed URL
let RSS_FEED_URL = "http://feeds.foxnews.com/foxnews/latest"

这是日志:

2016-11-04 13:14:41.004372 SwiftRSSReader[6518:3724227] subsystem:     com.apple.UIKit, category: HIDEventFiltered, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0
2016-11-04 13:14:41.007117 SwiftRSSReader[6518:3724227] subsystem: com.apple.UIKit, category: HIDEventIncoming, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0
2016-11-04 13:14:41.015095 SwiftRSSReader[6518:3724218] subsystem: com.apple.BaseBoard, category: MachPort, enable_level: 1, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 0, enable_private_data: 0
2016-11-04 13:14:41.026425 SwiftRSSReader[6518:3723899] subsystem: com.apple.UIKit, category: StatusBar, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0
2016-11-04 13:14:41.090044 SwiftRSSReader[6518:3723899] subsystem: com.apple.BackBoardServices.fence, category: App, enable_level: 1, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 0, enable_private_data: 0
2016-11-04 13:14:41.093159 SwiftRSSReader[6518:3723899] subsystem: com.apple.libsqlite3, category: logging, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0
2016-11-04 13:14:41.107322 SwiftRSSReader[6518:3724218] subsystem: com.apple.network, category: , enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 2, enable_private_data: 0
2016-11-04 13:14:41.107763 SwiftRSSReader[6518:3724218] [] tcp_connection_create_with_endpoint_and_parameters 1 feeds.foxnews.com 80
2016-11-04 13:14:41.108168 SwiftRSSReader[6518:3724218] [] tcp_connection_start 1 starting
2016-11-04 13:14:41.108508 SwiftRSSReader[6518:3724218] [] nw_connection_create creating connection to feeds.foxnews.com:80
2016-11-04 13:14:41.108839 SwiftRSSReader[6518:3724218] [] tcp_connection_start starting tc_nwconn=0x7fa7118007a0
2016-11-04 13:14:41.109044 SwiftRSSReader[6518:3724220] [] __nw_connection_start_block_invoke 1 starting
2016-11-04 13:14:41.109509 SwiftRSSReader[6518:3724220] [] nw_endpoint_handler_start [1 feeds.foxnews.com:80 initial path (null)]
2016-11-04 13:14:41.109766 SwiftRSSReader[6518:3724220] [] nw_connection_endpoint_report [1 feeds.foxnews.com:80 initial path (null)] reported event path:start
2016-11-04 13:14:41.110667 SwiftRSSReader[6518:3724220] [] nw_endpoint_handler_path_change [1 feeds.foxnews.com:80 waiting path (satisfied)]
2016-11-04 13:14:41.110866 SwiftRSSReader[6518:3724220] [] nw_connection_endpoint_report [1 feeds.foxnews.com:80 waiting path (satisfied)] reported event path:satisfied
2016-11-04 13:14:41.111125 SwiftRSSReader[6518:3724220] [] nw_connection_endpoint_report [1 feeds.foxnews.com:80 waiting path (satisfied)] skipping state update
2016-11-04 13:14:41.111438 SwiftRSSReader[6518:3724220] [] nw_endpoint_proxy_handler_should_use_proxy Looking up proxy for hostname: feeds.foxnews.com, ifindex: 0
2016-11-04 13:14:41.112162 SwiftRSSReader[6518:3724220] subsystem: com.apple.SystemConfiguration, category: SCPreferences, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 2, enable_private_data: 0
2016-11-04 13:14:41.113320 SwiftRSSReader[6518:3724220] [] -[NWConcrete_nw_endpoint_resolver startWithHandler:] [1 feeds.foxnews.com:80 waiting resolver (satisfied)]
2016-11-04 13:14:41.113565 SwiftRSSReader[6518:3724220] [] nw_connection_endpoint_report [1 feeds.foxnews.com:80 in_progress resolver (satisfied)] reported event resolver:start_dns
2016-11-04 13:14:41.114189 SwiftRSSReader[6518:3724220] [] nw_resolver_create_dns_service_on_queue Starting host resolution feeds.foxnews.com:80, flags 0x4000d000
2016-11-04 13:14:41.114658 SwiftRSSReader[6518:3724220] [] nw_resolver_host_resolve_callback flags=0x2 ifindex=0 error=NoSuchRecord(-65554) hostname=feeds.foxnews.com. addr=::.0 ttl=60
2016-11-04 13:14:41.114846 SwiftRSSReader[6518:3724220] [] nw_resolver_start_query_timer Starting 1s query timer to receive all address families for feeds.foxnews.com:80
2016-11-04 13:14:41.115130 SwiftRSSReader[6518:3724220] [] nw_endpoint_resolver_update [1 feeds.foxnews.com:80 in_progress resolver (satisfied)] resolver is in_progress
2016-11-04 13:14:41.115388 SwiftRSSReader[6518:3724220] [] nw_endpoint_resolver_update [1 feeds.foxnews.com:80 in_progress resolver (satisfied)] Updated endpoint list is ()
2016-11-04 13:14:41.115852 SwiftRSSReader[6518:3724220] [] nw_resolver_host_resolve_callback flags=0x2 ifindex=0 error=NoError(0) hostname=ghs.l.google.com. addr=216.58.192.211:0 ttl=43
2016-11-04 13:14:41.116201 SwiftRSSReader[6518:3724220] [] nw_resolver_cancel_query_timer Cancelling query timer for feeds.foxnews.com
2016-11-04 13:14:41.116452 SwiftRSSReader[6518:3724218] [] nw_endpoint_resolver_update [1 feeds.foxnews.com:80 in_progress resolver (satisfied)] resolver is complete
2016-11-04 13:14:41.116768 SwiftRSSReader[6518:3724218] [] nw_endpoint_resolver_update [1 feeds.foxnews.com:80 in_progress resolver (satisfied)] Adding endpoint handler for 216.58.192.211:80
2016-11-04 13:14:41.116976 SwiftRSSReader[6518:3724218] [] nw_endpoint_resolver_update [1 feeds.foxnews.com:80 in_progress resolver (satisfied)] Updated endpoint list is (216.58.192.211:80)
2016-11-04 13:14:41.117217 SwiftRSSReader[6518:3724218] [] nw_connection_endpoint_report [1 feeds.foxnews.com:80 in_progress resolver (satisfied)] reported event resolver:receive_dns
2016-11-04 13:14:41.117478 SwiftRSSReader[6518:3724218] [] nw_endpoint_resolver_start_next_child [1 feeds.foxnews.com:80 in_progress resolver (satisfied)] starting child endpoint 216.58.192.211:80
2016-11-04 13:14:41.117796 SwiftRSSReader[6518:3724218] [] nw_endpoint_resolver_start_next_child [1 feeds.foxnews.com:80 in_progress resolver (satisfied)] starting next child endpoint in 174ms
2016-11-04 13:14:41.118019 SwiftRSSReader[6518:3724218] [] nw_endpoint_handler_start [1.1 216.58.192.211:80 initial path (null)]
2016-11-04 13:14:41.118301 SwiftRSSReader[6518:3724218] [] nw_endpoint_resolver_receive_report [1 feeds.foxnews.com:80 in_progress resolver (satisfied)] received child report:[1.1 216.58.192.211:80 initial path (null)]
2016-11-04 13:14:41.118504 SwiftRSSReader[6518:3724218] [] nw_connection_endpoint_report [1.1 216.58.192.211:80 initial path (null)] reported event path:start
2016-11-04 13:14:41.118977 SwiftRSSReader[6518:3724218] [] nw_endpoint_handler_path_change [1.1 216.58.192.211:80 waiting path (satisfied)]
2016-11-04 13:14:41.119170 SwiftRSSReader[6518:3724218] [] nw_endpoint_resolver_receive_report [1 feeds.foxnews.com:80 in_progress resolver (satisfied)] received child report:[1.1 216.58.192.211:80 waiting path (satisfied)]
2016-11-04 13:14:41.119438 SwiftRSSReader[6518:3724218] [] nw_connection_endpoint_report [1.1 216.58.192.211:80 waiting path (satisfied)] reported event path:satisfied
2016-11-04 13:14:41.119640 SwiftRSSReader[6518:3724218] [] nw_endpoint_proxy_handler_should_use_proxy Looking up proxy for hostname: <nil>, ifindex: 0
2016-11-04 13:14:41.120510 SwiftRSSReader[6518:3724218] [] -[NWConcrete_nw_endpoint_flow startWithHandler:] [1.1 216.58.192.211:80 waiting socket-flow (satisfied)]
2016-11-04 13:14:41.120854 SwiftRSSReader[6518:3724218] [] nw_endpoint_flow_setup_socket [1.1 216.58.192.211:80 in_progress socket-flow (satisfied)] creating socket
2016-11-04 13:14:41.121166 SwiftRSSReader[6518:3724218] [] nw_endpoint_flow_attach_protocols [1.1 216.58.192.211:80 in_progress socket-flow (satisfied)]
2016-11-04 13:14:41.122065 SwiftRSSReader[6518:3724218] [] nw_endpoint_flow_attach_protocols [1.1 216.58.192.211:80 in_progress socket-flow (satisfied)] Attached flow protocol
2016-11-04 13:14:41.122285 SwiftRSSReader[6518:3724218] [] nw_endpoint_resolver_receive_report [1 feeds.foxnews.com:80 in_progress resolver (satisfied)] received child report:[1.1 216.58.192.211:80 in_progress socket-flow (satisfied)]
2016-11-04 13:14:41.122611 SwiftRSSReader[6518:3724218] [] nw_connection_endpoint_report [1.1 216.58.192.211:80 in_progress socket-flow (satisfied)] reported event flow:start_connect
2016-11-04 13:14:41.141808 SwiftRSSReader[6518:3724218] [] nw_socket_handle_socket_event Event mask: 0x800
2016-11-04 13:14:41.142315 SwiftRSSReader[6518:3724218] [] nw_socket_handle_socket_event Socket received CONNECTED event
2016-11-04 13:14:41.142601 SwiftRSSReader[6518:3724218] [] nw_socket_setup_notsent_lowat Set TCP_NOTSENT_LOWAT(16384)
2016-11-04 13:14:41.142889 SwiftRSSReader[6518:3724218] [] nw_endpoint_flow_protocol_connected [1.1 216.58.192.211:80 in_progress socket-flow (satisfied)] Output protocol connected
2016-11-04 13:14:41.144100 SwiftRSSReader[6518:3724218] [] nw_endpoint_flow_connected_path_change [1.1 216.58.192.211:80 ready socket-flow (satisfied)]
2016-11-04 13:14:41.144380 SwiftRSSReader[6518:3724218] [] nw_endpoint_flow_connected_path_change [1.1 216.58.192.211:80 ready socket-flow (satisfied)] Connected path is satisfied
2016-11-04 13:14:41.144646 SwiftRSSReader[6518:3724218] [] nw_endpoint_resolver_receive_report [1 feeds.foxnews.com:80 in_progress resolver (satisfied)] received child report:[1.1 216.58.192.211:80 ready socket-flow (satisfied)]
2016-11-04 13:14:41.145038 SwiftRSSReader[6518:3724218] [] nw_connection_endpoint_report [1.1 216.58.192.211:80 ready socket-flow (satisfied)] reported event flow:finish_connect
2016-11-04 13:14:41.150405 SwiftRSSReader[6518:3724218] [] nw_connection_endpoint_report [1 feeds.foxnews.com:80 ready resolver (satisfied)] reported event flow:finish_connect
2016-11-04 13:14:41.150630 SwiftRSSReader[6518:3724218] [] nw_endpoint_resolver_receive_report [1 feeds.foxnews.com:80 ready resolver (satisfied)] received child report:[1.1 216.58.192.211:80 ready socket-flow (satisfied)]
2016-11-04 13:14:41.150887 SwiftRSSReader[6518:3724218] [] nw_connection_endpoint_report [1.1 216.58.192.211:80 ready socket-flow (satisfied)] reported event flow:changed_viability
2016-11-04 13:14:41.151135 SwiftRSSReader[6518:3724218] [] nw_connection_endpoint_report [1 feeds.foxnews.com:80 ready resolver (satisfied)] reported event flow:changed_viability
2016-11-04 13:14:41.151518 SwiftRSSReader[6518:3724220] [] __tcp_connection_start_block_invoke 1 sending event TCP_CONNECTION_EVENT_CONNECTED in response to state ready and error (null)
2016-11-04 13:14:41.151724 SwiftRSSReader[6518:3724220] [] tcp_connection_event_notify 1 event: TCP_CONNECTION_EVENT_CONNECTED, reason: nw_connection event, should deliver: true
2016-11-04 13:14:41.152148 SwiftRSSReader[6518:3724220] [] tcp_connection_get_statistics DNS: 3ms/7ms since start, TCP: 22ms/35ms since start, TLS: 0ms/0ms since start
2016-11-04 13:14:44.430023 SwiftRSSReader[6518:3723899] subsystem: com.apple.UIKit, category: Touch, enable_level: 0, persist_level: 0, default_ttl: 1, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0
2016-11-04 13:14:44.430900 SwiftRSSReader[6518:3723899] subsystem: com.apple.UIKit, category: Gesture, enable_level: 0, persist_level: 0, default_ttl: 1, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0
2016-11-04 13:14:44.432417 SwiftRSSReader[6518:3723899] subsystem: com.apple.UIKit, category: GestureEnvironment, enable_level: 0, persist_level: 0, default_ttl: 1, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0
2016-11-04 13:14:44.432979 SwiftRSSReader[6518:3723899] subsystem: com.apple.UIKit, category: GestureExclusion, enable_level: 0, persist_level: 0, default_ttl: 1, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0
2016-11-04 13:14:46.863562 SwiftRSSReader[6518:3723899] subsystem: com.apple.SystemConfiguration, category: SCNetworkReachability, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 2, enable_private_data: 0
objc[6518]: Class PLBuildVersion is implemented in both /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/AssetsLibraryServices.framework/AssetsLibraryServices (0x11cd23910) and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/PhotoLibraryServices.framework/PhotoLibraryServices (0x11cb4d210). One of the two will be used. Which one is undefined.
2016-11-04 13:14:47.044666 SwiftRSSReader[6518:3723899] subsystem: com.apple.siri, category: Intents, enable_level: 1, persist_level: 1, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 0, enable_private_data: 0

致命错误:在展开Optional值时意外发现nil (lldb)

0 个答案:

没有答案