Der Code hier geht an Jameson Quave.Typ "Zeichensatz" hat kein Mitglied "utf8"
URL: www.jamesonquave.com/blog/developing-ios-apps-using-swift-tutorial-part-2/
Ich habe versucht, es zu bearbeiten mit Swift 3. Die Frage, die ich bin arbeiten aufweist, wird die Fehlermeldung für diese Linie:
if let escapedSearchTerm = itunesSearchTerm.addingPercentEncoding(withAllowedCharacters: .urlquery)
(es .utf8
im Code besagt)
ich bin nicht sicher, was ich in dem .urlquery
Abschnitt platzieren muß
Der Fehlercode, den ich bekomme, ist der Titel. Ich habe versucht, nach Antworten googlen und String.Encoding.utf8
gefunden, die auch nicht funktioniert haben. Der ursprüngliche Code hatte NSUTF8StringEncoding
.
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var appsViewTable: UITableView!
var tableData = []
func searchItunesFor(searchTerm: String) {
//The iTunes API wants multiple terms seperated by + symbols, so replace spaces with + signs
let itunesSearchTerm = searchTerm.replacingOccurrences(of: " ", with: "+", options: NSString.CompareOptions.caseInsensitive, range: nil)
//Now escape anything else that isn't URL-friendly
if let escapedSearchTerm = itunesSearchTerm.addingPercentEncoding(withAllowedCharacters: .utf8) {
let urlPath = "http://itunes.apple.com/search?term=\(escapedSearchTerm)&media=software"
let url = NSURL(string: urlPath)
let session = URLSession.shared
let task = session.dataTaskWithURL(url!, completionHandler: {data, response, error -> Void in
printIn("Task completed")
if(error != nil) {
// If there is an error in the web request, print it to the console
printIn(error.localizedDescription)
}
var err: NSError?
if let jsonResult = NSJSONSerialization.JSONObjectiveWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &err) as? NSDictionary {
if(err != nil) {
// If there is an error parsing JSON, print it to the console
printIn("JSON Error \(err!.localizedDescription)")
}
if let results: NSArray = jsonResult["results"] as? NSArray {
dispatch_async(dispatch_get_main_queue(), {
self.tableData = results
self.appsTableView!.reloadData()
})
}
}
})
// The task if just an object with all these properties set
// In order to actually make the web request, we need to "resume"
task.resume()
}
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Versuchen Sie es mit 'String.Encoding.utf8.rawValue' – Tj3n