GPT帮忙翻译的代码,就是不执行某句话
if let maxPageDic = UserDefaults.standard.object(forKey: KDocumentProgressTecentMaxPage) as? [String: Any],
!maxPageDic.isEmpty {
if let maxPage = maxPageDic["maxPage"] {
if type(of: maxPage) == Int.self {
print("maxPage 是 Int")
} else {
print("maxPage 不是 Int,实际类型是 \(type(of: maxPage))")
}
}
if let total = maxPageDic["total"] {
if type(of: total) == Int.self {
print("total 是 Int")
} else {
print("total 不是 Int,实际类型是 \(type(of: total))")
}
}
if let learnID = maxPageDic["learnID"] {
if type(of: learnID) == Int.self {
print("learnID 是 Int")
} else {
print("learnID 不是 Int,实际类型是 \(type(of: learnID))")
}
}
if let relation_id = maxPageDic["relation_id"] {
if type(of: relation_id) == Int.self {
print("relation_id 是 Int")
} else {
print("relation_id 不是 Int,实际类型是 \(type(of: relation_id))")
}
}
if let maxPage = maxPageDic["maxPage"] as? NSNumber,
let learnID = maxPageDic["learnID"] as? String,
let totalNum = maxPageDic["total"] as? NSNumber,
let relationId = maxPageDic["relation_id"] as? NSNumber {
var progress = (maxPage.intValue * 100) / totalNum.intValue
if maxPage.intValue >= totalNum.intValue - 3 {
progress = 100
}
if maxPage.intValue > 0 {
let parameters: [String: Any] = [
"learn_id": learnID ,
"progress": progress,
"last_learn": maxPage
]
// 使用 weak self 避免循环引用
let weakSelf = self
let urlString = String(format: "client/plan/learn/progress/%@", relationId)
let task = LMSNewAPIClient.apiManager()?.putRequestAPI(urlString, parameters: parameters, success: { (dataTask, json) in
if let jsonDict = json as? [String: Any],
let status = jsonDict["status"] as? Int, status == 1 {
// weakSelf?.updateProgress?(NSNumber(value: progress))
}
UserDefaults.standard.removeObject(forKey: KDocumentProgressTecentMaxPage)
}, failure: { (dataTask, error) in
// 处理错误
})
// self.autoCancelRequestOnDealloc(task)
}
}
}
}