代码:
for var curIdx = self.groupTopicItemList.count – 1; curIdx >= 0 ; curIdx -= 1 { |
swift 3中出现警告:
C-style for statement is deprecated and will be removed in a future version of Swift
ios – C-style for statement is deprecated and will be removed in a future – Stack Overflow
swift/diag_c_style_for.swift at master · apple/swift
[swift-users] WARNING: Title underline too short
What’s new in Swift 2.2: learn all the changes in one video – Hacking with Swift
测试代码:
//: Playground – noun: a place where people can play import UIKit print("we want got: 9 to 0") let totalCount = 10 let totalIndx = totalCount – 1 print("C style version:") //C-style for statement is deprecated and will be removed in a future version of Swift for var curIdx = totalIndx; curIdx >= 0 ; curIdx -= 1 { print("[\(curIdx)]") } print("stride to version:") //for curIdx in totalCount.stride(to: 0, by: -1){ for curIdx in totalIndx.stride(to: –1, by: –1){ print("[\(curIdx)]") } print("stride througn version:") for curIdx in totalIndx.stride(through: 0, by: –1) { print("[\(curIdx)]") } //print("count down version:") //for curIdx in totalCount…1 { // print("[\(curIdx)]") //} //fatal error: Can’t form Range with end < start print("reverse version:") for curIdx in (0…totalIndx).reverse() { print("[\(curIdx)]") } |
输出效果:
we want got: 9 to 0 C style version: [9] [8] [7] [6] [5] [4] [3] [2] [1] [0] stride to version: [9] [8] [7] [6] [5] [4] [3] [2] [1] [0] stride througn version: [9] [8] [7] [6] [5] [4] [3] [2] [1] [0] reverse version: [9] [8] [7] [6] [5] [4] [3] [2] [1] [0] |
最后代码改为:
//for var curIdx = self.groupTopicItemList.count – 1; curIdx >= 0 ; curIdx -= 1 { for curIdx in (0…(self.groupTopicItemList.count – 1)).reverse() { // for var i = 0; i < SecTrustGetCertificateCount(trust); i += 1 { for i in 0…(SecTrustGetCertificateCount(trust) – 1) { // for var sectionIdx = contactSectionItemList.count – 1; sectionIdx >= 0 ; sectionIdx -= 1 { for sectionIdx in (0…(contactSectionItemList.count – 1)).reverse() { // for var contactIdxInSection = contactSectionItemList[sectionIdx].contactItemList.count – 1; contactIdxInSection >= 0 ; contactIdxInSection -= 1 { for contactIdxInSection in (0…(contactSectionItemList[sectionIdx].contactItemList.count – 1)).reverse(){ |
转载请注明:在路上 » 【已解决】swift 3警告:C-style for statement is deprecated and will be removed in a future version of Swift