As I understand it, you need to somehow get rid of checking for nil . But I don’t understand how to do this in a specific case, and how you can change the code to avoid this error.

  func loadArticles() { let feedURL = URL(string: self.feedURL)! if let parser = FeedParser(URL: feedURL) { // or FeedParser(data: data) // Parse asynchronously, not to block the UI. parser.parseAsync(queue: DispatchQueue.global(qos: .userInitiated)) { (result) in // Do your thing, then back to the Main thread DispatchQueue.main.async { // ..and update the UI switch result { case let .atom(feed): break // Atom Syndication Format Feed Model case let .rss(feed): // Really Simple Syndication Feed Model print("rss obtained!") self.articlesArray = feed.items! self.tableView.reloadData() case let .json(feed): // JSON Feed Model print("json obtained!") case let .failure(error): print(error) } } } } else { print("error parsing feed URL") } } 
  • one
    Ask your question on a regular stackoverflow. At this forum questions are asked in Russian - 0rt

1 answer 1

That's what you need to do, you have to check for nil right here if let parser = FeedParser(URL: feedURL) { there will always be true . Check instead feedURL

 func loadArticles() { let feedURL = URL(string: self.feedURL) if let url = feedURL { let parser = FeedParser(URL: feedURL) // or FeedParser(data: data) // Parse asynchronously, not to block the UI. parser.parseAsync(queue: DispatchQueue.global(qos: .userInitiated)) { (result) in // Do your thing, then back to the Main thread DispatchQueue.main.async { // ..and update the UI switch result { case let .atom(feed): break // Atom Syndication Format Feed Model case let .rss(feed): // Really Simple Syndication Feed Model print("rss obtained!") self.articlesArray = feed.items! self.tableView.reloadData() case let .json(feed): // JSON Feed Model print("json obtained!") case let .failure(error): print(error) } } } } else { print("error parsing feed URL") } } 
  • thank. it turned out to be simpler than I thought). Also xcode says you need to put an exclamation mark let parser = FeedParser (URL: feedURL!) - kr4nk