3 ms·
Regarding iOS and macOS kits, all of the documentation is in Objective-C. The libraries' Obj-C is imported and usable with Swift-only code, but the Swift docume
by developer2 9y ago
Regarding iOS and macOS kits, all of the documentation is in Objective-C. The libraries' Obj-C is imported and usable with Swift-only code, but the Swift documentation lazily links you to examples in the Obj-C docs. You have to perform trial-and-error by manually converting the Obj-C examples into the equivalent Swift (which often entails renamed classes, methods, types, etc.).
If your projects typically do a lot of string parsing, get ready for a world of hell. Swift 4 didn't improve upon the very basic ability to extract a substring from the middle of a string. It takes 3-4 lines of code, with throwaway explicitly defined variables, to do the equivalent of a str.substr(start, end|length). It boggles the mind that you can't do a str.utf8.substr(3, 5) in Swift.
- futurix 9y agoDid you forget to switch documentation from Objective-C to Swift?
- mahyarm 9y agoString operations are also really slow in swift. Python is the same speed or faster
- dep_b 9y agoI only remember a very early review of string operation speeds that was pretty bad at times indeed. But that was about Swift 1 and the string implementation has been changed a few times. Do you have any recent source?
- mahyarm 9y agoPersonal experience making the same command line util in python and swift 3 that was parsing code with the same C library (sourcekit) and then doing a bunch of string manipulation after that. Optimized swift 3 & python were the same speed, with %80 of the time being spent in the C library. I would expect swift would at least be 2x faster in that %20 portion that wasn't sourcekit library.
- dep_b 9y agoI think strings in Swift are primarily meant to be very correct above being fast or easy to use. It's more strict than both Python 2 and 3. Handling of languages that use really complex character compositions springs to mind.
- mahyarm 9y agoThere is no obvious way to turn that off fortunately, when you don't need it.
- LeoNatan25 9y agoI think it's coming. Part of the String Manifesto Apple has is that they want to give both worlds.
- Rodd45 9y agoI haven't tried Swift yet but that is my buddy's first impression when he tried it.
- aplummer 9y agoI think most people just use a string extension to allow str.substring(with: 7..<11) or something similar.