Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 261 Vote(s) - 3.52 Average
  • 1
  • 2
  • 3
  • 4
  • 5
#warning: C-style for statement is deprecated and will be removed in a future version of Swift

#1
I just download a new Xcode (7.3) with swift 2.2.

It has a warning:

> C-style for statement is deprecated and will be removed in a future version of Swift.

How can I fix this warning?
Reply

#2
Removing `for init; comparison; increment {}` and also remove `++` and `--` easily. and use Swift's pretty for-in loop



// WARNING: C-style for statement is deprecated and will be removed in a future version of Swift
for var i = 1; i <= 10; i += 1 {
print("I'm number \(i)")
}
------------
**Swift 2.2:**

// new swift style works well
for i in 1...10 {
print("I'm number \(i)")
}
------------
**For decrement index**

for index in 10.stride(to: 0, by: -1) {
print(index)
}

Or you can use `reverse()` like

for index in (0 ..< 10).reverse() { ... }


------------
**for float type `(there is no need to define any types to index)`**

for index in 0.stride(to: 0.6, by: 0.1) {
print(index) //0.0 ,0.1, 0.2,0.3,0.4,0.5
}

--------------
**Swift 3.0:**

**From `Swift3.0`, The `stride(to:by:)` method on Strideable has been replaced with a free function, `stride(from:to:by:)`**

for i in stride(from: 0, to: 10, by: 1){
print(i)
}

For decrement index in `Swift 3.0`, you can use `reversed()`

for i in (0 ..< 5).reversed() {
print(i) // 4,3,2,1,0
}

[![enter image description here][1]][1]


-------------------
Other then `for each` and `stride()`, you can use `While Loops`

var i = 0
while i < 10 {
i += 1
print(i)
}

*`Repeat-While Loop:`*

var a = 0
repeat {
a += 1
print(a)
} while a < 10

check out Control flows in [The Swift Programming Language Guide][2]


[1]:

[2]:

[To see links please register here]

Reply

#3
For this kind "for" loop:

for var i = 10; i >= 0; --i {
print(i)
}

You can write:

for i in (0...10).reverse() {
print(i)
}

Reply

#4
> Blockquote

Use this instead

if(myarr.count)
{
for i in 1...myarr?.count {
print(" number is \(i)")
}
}
Reply

#5
I got the same error with this code:

for (var i = 1; i != video.getAll().count; i++) {
print("show number \(i)")
}

When you try to fix it with Xcode you get no luck... So you need to use the new swift style (for in loop):

for i in 1...video.getAll().count {
print("show number \(i)")
}
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through