Wie dieser XML-Code unten gebildet wird, erhält mein Code sowohl die n13 Zeitperioden als auch die n7 Zeiträume, ist es möglich, meine Ergebnisse auf nur die n13 Daten zu beschränken irgendwie?Wie NSXMLParser auf Elemente nach einem bestimmten Element zu beschränken
<time-layout time-coordinate="local" summarization="12hourly">
<layout-key>k-p12h-n13-1</layout-key>
<start-valid-time period-name="This Afternoon">2016-06-30T12:00:00-04:00</start-valid-time>
<start-valid-time period-name="Tonight">2016-06-30T18:00:00-04:00</start-valid-time>
<start-valid-time period-name="Friday">2016-07-01T06:00:00-04:00</start-valid-time>
<start-valid-time period-name="Friday Night">2016-07-01T18:00:00-04:00</start-valid-time>
<start-valid-time period-name="Saturday">2016-07-02T06:00:00-04:00</start-valid-time>
<start-valid-time period-name="Saturday Night">2016-07-02T18:00:00-04:00</start-valid-time>
<start-valid-time period-name="Sunday">2016-07-03T06:00:00-04:00</start-valid-time>
<start-valid-time period-name="Sunday Night">2016-07-03T18:00:00-04:00</start-valid-time>
<start-valid-time period-name="Independence Day">2016-07-04T06:00:00-04:00</start-valid-time>
<start-valid-time period-name="Monday Night">2016-07-04T18:00:00-04:00</start-valid-time>
<start-valid-time period-name="Tuesday">2016-07-05T06:00:00-04:00</start-valid-time>
<start-valid-time period-name="Tuesday Night">2016-07-05T18:00:00-04:00</start-valid-time>
<start-valid-time period-name="Wednesday">2016-07-06T06:00:00-04:00</start-valid-time>
</time-layout>
<time-layout time-coordinate="local" summarization="12hourly">
<layout-key>k-p24h-n7-1</layout-key>
<start-valid-time period-name="This Afternoon">2016-06-30T12:00:00-04:00</start-valid-time>
<start-valid-time period-name="Friday">2016-07-01T06:00:00-04:00</start-valid-time>
<start-valid-time period-name="Saturday">2016-07-02T06:00:00-04:00</start-valid-time>
<start-valid-time period-name="Sunday">2016-07-03T06:00:00-04:00</start-valid-time>
<start-valid-time period-name="Independence Day">2016-07-04T06:00:00-04:00</start-valid-time>
<start-valid-time period-name="Tuesday">2016-07-05T06:00:00-04:00</start-valid-time>
<start-valid-time period-name="Wednesday">2016-07-06T06:00:00-04:00</start-valid-time>
</time-layout>
mein DidStartElement Code:
if weAreInsideAnItem == true {
if (elementName as NSString).isEqualToString("start-valid-time") {
if let periodAsNSString: NSString = attributeDict["period-name"] {
guard let periodAsString: String = periodAsNSString as String else {return}
tempForecastTimes.append(periodAsString)
}
}
}
Wie schleifen Sie über die Knoten? –
Nicht verknüpft, aber das 'if (elementName as NSString) .isEqualToString (" foo ") {...}' Muster kann vereinfacht werden zu 'if elementName ==" foo "{...}'. – Rob