我的应用中只剩下几个警告消息。我借用了一些代码,这恰好是带有警告信息的区域。应用程序运行良好,没有问题,但我想找出为什么那些警告消息存在。
两个单独的swift文件中出现相同的警告消息,因为它们使用类似的代码。
WriteViewController.swift
从未使用变量'memoNum'的初始化;考虑将赋值替换为'_'或删除它 变量'i'的初始化从未使用过;考虑将作业替换为'_'或将其删除
@IBAction func save(){
/*----------------------------------------*/
var memoNum = memo.count // <—- error
var i: Int = 0 // <—- error
print(memo)
let id:AnyObject = convertUnixTimeFromDate(NSDate())
let newDic = ["id":id,"contents":writeView.text]
print("newDic=\(newDic)¥¥¥")
print(memo)
print(memoArray)
let memoDictionary = ["id":id,"contents":writeView.text]
var tempArr : Array = memoArray as Array
print("beforeReverse=\(tempArr)")
var tempArr2 = Array(tempArr.reverse())
print("afterReverse=\(tempArr2)")
var tArray : NSArray = tempArr2 as NSArray
memoArray = tArray.mutableCopy() as! NSMutableArray
memoArray.addObject(memoDictionary)
tempArr = memoArray as Array
print("beforeReverse=\(tempArr)")
tempArr2 = tempArr.reverse()
print("afterReverse=\(tempArr2)")
tArray = tempArr2 as NSArray
memoArray = tArray.mutableCopy() as! NSMutableArray
/*--------------------------------------------------*/
UD.setObject(memoArray, forKey: "array")
print(memo)
UD.synchronize()
writeView.text=""
self.view.endEditing(true)
writeView.resignFirstResponder()
let alert2 = UIAlertController()
alert2.addAction(UIAlertAction(title: "Save", style: UIAlertActionStyle.Cancel, handler: nil))
self.presentViewController(alert2, animated: true, completion: nil)
}
EditViewController.swift
从未使用变量'TD'的初始化;考虑将赋值替换为'_'或删除它 从未使用变量'TDArray'的初始化;考虑将作业替换为'_'或将其删除
@IBAction func edit(){
var i: Int
print(memo)
if(searchString == ""){
var dic = memo[cellNum] as! Dictionary<NSObject, AnyObject>
print("dic=\(dic)")
dic["contents"] = editView.text as String
memo[cellNum]=dic
memoArray[cellNum]=memo[cellNum]!
}else{
var TD : Dictionary<NSObject,AnyObject> = [:] // <—— error
var TDArray : NSMutableArray = [] // <—— error
let edtTxt = editView.text as String
var dic = tmpDictionaryArray[cellNum] as! Dictionary<NSObject,AnyObject>
dic["contents"] = edtTxt
tmpDictionaryArray[cellNum]=dic
let tmpId: Double = dic["id"] as! Double
print("memo=\(memo)")
for(var k=0;k<memo.count;k++){
let Tmp = memo[k] as! NSDictionary
print("Tmp=\(Tmp)")
let double : Double = Tmp["id"] as! Double
print("tmpId=\(tmpId)")
print("double=\(double)")
if(double == tmpId){
var dic = memo[cellNum] as! Dictionary<NSObject,AnyObject>
dic["contents"] = edtTxt
memo[k] = dic
memoArray[k]=memo[k]!
print("Tmp=\(Tmp)")
print("memo=\(memo)")
}
}
print("tmpDA=\(tmpDictionaryArray)")
}
print(memo)
UD.setObject(memoArray as NSArray, forKey: "array")
print(memo)
UD.synchronize()
self.view.endEditing(true)
//Notification
let ns = NSNotificationCenter.defaultCenter()
ns.postNotificationName(MyNotification, object: nil)
self.dismissViewControllerAnimated(true, completion: nil)
}