使用join()的原始代码显示了Instruments中的内存泄漏。我使用了一个循环,它似乎解决了这个问题。好奇,如果这似乎是一个框架问题?
//in ViewDidLoad
let saveButton = UIBarButtonItem(barButtonSystemItem: .Save, target: self, action: "saveBtnAc")
self.navigationItem.rightBarButtonItem = saveButton
//end ViewDidLoad
//using a loop to join the string instead of join()
func doJndString(theArray: [String]) -> String {
var updatedAryJnd = String()
var count = 0
let lastItemCount = theArray.count - 1
while (count < lastItemCount) {
updatedAryJnd += (theArray[count] + "§")
count++
}
updatedAryJnd += theArray[lastItemCount]
return updatedAryJnd
}
//button action
func saveBtnAc() {
var myAry = [""]
if let items1 = setupItem?.valueForKey("itemsAry1") as? String {
myAry = items1.componentsSeparatedByString("§")
}
myAry[itemClkdVar] = myTxtOutlet.text
//I get a leak when using the following join()
//let updatedAryJnd = "§".join(myAry)
//setupItem!.setValue(updatedAryJnd, forKey: "itemsAry1")
//change above to this and no leak
setupItem!.setValue(doJndString(myAry), forKey: "itemsAry1")
var error: NSError? = nil
if !contextOb!.save(&error) {
println("had an error")
}
}