The code being:
class Singleton {
class var sharedInstance:Singleton {
struct Static {
static var instance:Singleton? = nil
static var token:dispatch_once_t = 0
}
dispatch_once(&Static.token)
{
Static.instance = Singleton ()
}
return Static.instance!
}
var prayerArray = Array<PrayerSound>()
}
and:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let prayer = PrayerSound(namazName: cellLabel, pathString: filePath!, checked: checked)
sinleton.prayerArray[cellindex] = prayer
}
–numberOfSectionsInTableView:and–tableView:numberOfRowsInSection:methods' bodies?dispatch_oncepart is not needed at all. This singleton syntax usesdispatch_onceautomatically behind the scenes.