gpt4 book ai didi

ios - NSString 没有名为 bridgeToObjectiveC 的成员

转载 作者:搜寻专家 更新时间:2023-11-01 05:59:27 25 4
gpt4 key购买 nike

我在下面的代码中遇到编译器错误。我已经导入了所需的 Foundation 库,所以我不确定到底出了什么问题,请有人建议我可能做错了什么,或者我可以做些什么来解决这个问题?

谢谢

import UIKit
import Foundation

class ViewController: UIViewController {


@IBOutlet var areaTxt: UITextField!
@IBOutlet var resultLbl: UILabel!

@IBAction func goBtn(sender: AnyObject) {

if(countElements(areaTxt.text) > 0){
var removedSpaces = areaTxt.text.stringByReplacingOccurrencesOfString(" ", withString: "");
var url = "http://weather-forecast.com/locations/" + removedSpaces + "/forecasts/latest";
self.getWeatherReportForArea(url);
}else{
let alert = UIAlertView()
alert.title = "Alert"
alert.message = "The user location is empty"
alert.addButtonWithTitle("Ok")
alert.show()
}
}

func getWeatherReportForArea(area: String){
var url = NSURL(string: area);
let task = NSURLSession.sharedSession().dataTaskWithURL(url) { (data, response, error) in
var urlContent = NSString(data: data, encoding: NSUTF8StringEncoding);

if(urlContent.bridgeToObjectiveC().containsString("<span class=\"phrase\">")){

var contentArray = urlContent.componentsSeparatedByString("<span class=\"phrase\">");
var newContentArray = contentArray[1].componentsSeparatedByString("</span>");

var value = newContentArray[0].stringByReplacingOccurrencesOfString("&deg;", withString: "º");

dispatch_async(dispatch_get_main_queue()){

self.resultLbl.text = value;
}

}else{

}
}

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.
}
}

最佳答案

bridgeToObjectiveC() 已在 Xcode 6 Beta 5 中移除。现在桥接是透明的,只需使用

if urlContent.containsString("<span class=\"phrase\">") {
...
}

关于ios - NSString 没有名为 bridgeToObjectiveC 的成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26057900/

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