joined πŸ“™

YaR LabΒ·2024λ…„ 3μ›” 28일
0

swiftΒ πŸ“™

λͺ©λ‘ 보기
15/16
post-thumbnail

1️⃣ μ •μ˜

  • Sequence νƒ€μž…μ„ μ‚¬μš©ν•˜λŠ” 객체λ₯Ό 이어 λΆ™μ΄λŠ” λ©”μ„œλ“œ
func joined() -> FlattenSequence<Self>
func joined<Separator>(separator: Separator) -> JoinedSequence<Self> where Separator : Sequence, Separator.Element == Self.Element.Element

2️⃣ μ„€λͺ…

let arr = ["hello", "world", "swift"]
let joinedString = arr.joined(separator: " ")
print(joinedString) // "hello world swift"
  • joined λ©”μ„œλ“œλŠ” λ°˜ν™˜ νƒ€μž…μ΄ String이 μ•„λ‹ˆλΌ String.Element이기 λ•Œλ¬Έμ—, 이 λ©”μ„œλ“œλ₯Ό ν˜ΈμΆœν•œ μ΄ν›„μ—λŠ” joinedκ°€ λ°˜ν™˜ν•œ 결과물을 λ‹€μ‹œ String으둜 ν˜•λ³€ν™˜ ν•΄μ£Όμ–΄μ•Ό 함
let arr = ["hello", "world", "swift"]
let joinedString = arr.joined(separator: " ")
let finalString = String(joinedString)
print(finalString) // "hello world swift"

μΆœμ²˜πŸ“š

🍎Apple Docs: joined()
🍎Apple Docs: joined(separator:)

0개의 λŒ“κΈ€