by binaryapparatus · 9y ago · 0 comments
while (*d++ = *s++);
Or sort in Haskell: qsort [] = []
qsort (x:xs) = qsort (filter (< x) xs) ++ [x] ++ qsort (filter (>= x) xs) func strcpySwift(_ d:UnsafeMutablePointer<CChar>,
_ s:UnsafeMutablePointer<CChar>) {
for i in 0... {
d[i] = s[i]
if s[i] == 0 {
return
}
}
}
Haskell-style sort in Swift is pretty nice: func qsort<T:Comparable>(_ arr:[T]) -> [T] {
var xs = arr[...]
guard let x = xs.popFirst() else {
return []
}
return (qsort(xs.filter{$0 <= x})) + [x] +
(qsort(xs.filter{$0 > x}))
}Back to the one idiomatic C example. The few places where it’s terse does not make up for the many other places where it’s not. You also have memory management with malloc for additional code. If you compare nontrivial code, Swift is a more modern, safer, less verbose, etc way to develop iOS apps vs Objective C.