当我尝试显示“50%”时,取自
预测>区域>预测期>文本>probability_of_precipitation
它在我的故事板标签上出现“nil”。
我有这个 XML 片段,它位于公共 ftp 地址(如下面的代码所示)
<forecast>
<area aac="VIC_FA001" description="Victoria" type="region"/>
<area aac="VIC_PW001" description="Mallee" type="public-district" parent-aac="VIC_FA001"/>
<area aac="VIC_PT043" description="Mildura" type="location" parent-aac="VIC_PW001">
<forecast-period index="0" start-time-local="12pm" end-time-local="12:30pm" start-time-utc="1:00pm" end-time-utc="1:30pm">
<element type="forecast_icon_code">16</element>
<text type="precis">Shower or two. Possible storm.</text>
<text type="probability_of_precipitation">50%</text>
</forecast-period>
</area>
</forecast>
这是我的代码:
let urlStringMax = "ftp://ftp2.bom.gov.au/anon/gen/fwo/IDV10753.xml"
if let urlMax = NSURL(string: urlStringMax)
{
if let data = try? NSData(contentsOfURL: urlMax, options: [])
{
let xml = SWXMLHash.parse(data)
let precipForecast = xml["forecast"]["area"][2]["forecast-period"][0]["text"][type="probability_of_precipitation"].element?.text
maxTemp.text = "\(precipForecast)"
}
}