λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°

swift λ¬Έλ²•πŸ–€

[SWIFT] enumerated() ν•¨μˆ˜

연속적인 μŒμ„ λ¦¬ν„΄ν•˜μ—¬ 각각의 μš”μ†Œμ— μ ‘κ·Ό ν•  수 있게 ν•΄μ£ΌλŠ” ν•¨μˆ˜ 

Return

(n,x)둜 이루어진 μˆœμ„œμŒμ„ 리턴

n : 0λΆ€ν„° xκΉŒμ§€μ˜ 연속적 숫자 , x : ν•΄λ‹Ήμˆœμ„œμ˜ μš”μ†Œ

 

μ‚¬μš© μ˜ˆμ‹œ

for (n, c) in "Swift".enumerated() {

         print("\(n): '\(c)'")

}

// Prints "0: 'S'"

// Prints "1: 'w'"

// Prints "2: 'i'"

// Prints "3: 'f'"

// Prints "4: 't'"