6 ms·
The title here is misleading. Most of this applies to Objective-C. There's nothing wrong with the article as far as programming advice goes, but it has nothing
by setpatchaddress 7y ago
The title here is misleading. Most of this applies to Objective-C. There's nothing wrong with the article as far as programming advice goes, but it has nothing to do with Swift idioms.
> So, to make our code more “Swifty” from a performance point of view, sometimes all that we have to do [is literally the same thing we would do in Objective-C]
Is anyone writing consistently good, up-to-date Swift documentation for experienced programmers? Some of the early books haven't been updated since the earliest Swift versions.
SwiftUI is very poorly documented by Apple and much of the third-party SwiftUI docs are for the obsolete WWDC version.
- saagarjha 7y ago> Most of this applies to Objective-C. Objective-C’s type system is much poorer than Swift’s, and it lacks a number of expressive operations. The “before” examples are generally how a lot of people would actually write code in Objective-C.
- refulgentis 7y agoWhich ones? I wrote ObjC for 7 years, Swift for 3. I only looked at the first two examples, they both were generic programming advice, nothing to do with the language
- saagarjha 7y agoThe first three. Objective-C doesn't have enums with associated values and it's common to store things in heterogeneous collections or stringly-keyed collections. Creating protocols for generic constraints is also rare–informal protocols (respondsToSelector, anyone?) are instead quite prevalent. And Objective-C's "collection" APIs are much less powerful than Swift's: I might use a regex replacement instead of four calls to replacingOccurrences(of:with:), but it's the same principle.
- deleted 7y ago[deleted]
- metalgearsolid 7y agoTo answer your question: objc.io
- oflannabhra 7y agoI’ll tack on a couple sources to this: http://pointfree.co http://pointfree.co - high quality content, emphasizing functional programming. https://oleb.net/blog/ https://oleb.net/blog/ - blog of Ole Begemann, co author of Advanced Swift (good resource itself) https://appventure.me https://appventure.me - Benedikt Terhechte’s topical guides to Swift features https://andybargh.com/blog/ https://andybargh.com/blog/ Andy Bargh’s topical articles
- plorkyeran 7y agoThe first example utilizes a feature of Swift's type system which obj-c does not have (enums with associated values) to write code which is better than could be done in obj-c. This seems like a perfectly good example of improving code by making it more "Swifty", as one of the distinguishing features of Swift is that it has a more powerful type system than most mainstream languages. The second example is strange. It's improving the code by making it call the correct method from the standard library rather than the wrong one. I guess that's not bad advice, but I have no idea what it has to do with Swift in particular. The third one is a missed opportunity. Swift has some unusual ideas around how things should be named (partially inherited from Smalltalk via obj-c, but also partially new), but instead of talking about that it's just generic "give things useful names" advice that has little to do with Swift.