Ich schreibe bereits mein erstes Projekt damit & dachte mir, dass ich mal ein paar (gekürzte) Snippets daraus veröffentliche.
Das ganze ohne Copyright etc. & rechtlich ist das ganze auch okay, Swift unterliegt keinem NDA.
XPath Queries mit Hilfe von TFHpple auswerten:
Code:
let parser = TFHpple(HTMLData: html)
let summary = parser.searchWithXPathQuery(summaryQuery) as Array<TFHppleElement>
return summary.map { $0.firstChild.content }
Code:
func getData(completionHandler : (_: NSURLResponse!, _: NSData!, _: NSError!) -> ()) {
NSURLConnection.sendAsynchronousRequest(self.request, queue: self.queue, completionHandler: completionHandler)
}
Code:
enum SampleEnum : Int {
case Internal = 0
case External
var description : String {
switch self {
case .Internal:
return "EnumValue A"
case .External:
return "EnumValue B"
}
}
}
Code:
override func tableView(_: UITableView!, titleForHeaderInSection section: Int) -> String! {
return SampleEnum.fromRaw(section)!.description
}
didSet für Properties in einer UITableViewCell:
Code:
class NDTableViewCell: UITableViewCell {
var item : NDItem? {
didSet {
if let item = self.item {
titleLabel.text = "\(item.title) blabla"
detailLabel.text = "\(item.location), \(item.type.toRaw())"
}
}
}
@IBOutlet var titleLabel : UILabel
@IBOutlet var detailLabel : UILabel
}
Code:
let 🌍 = "🐶🐺🐱🐭🐹🐰🐸🐯🐨🐻🐮🐗🐵🐒🐴🐑🐘🐼🐧🐦🐤🐥🐣🐔🐍🐢🐠🐳"
let 🚢 = Array<Character>(🌍).map{ 💕 in 💕 + 💕 }
🚢
Code:
let (title, value) = getData() println(title)
Code:
let tuple = getData() println(tuple.0)






