11 ms·
Apple’s use of Swift and SwiftUI in iOS 15
- symlinkk 5y agoI’m sure Swift is great but I wouldn’t want to devote a significant amount of time learning a language that is effectively only for a single platform.
- grouphugs 5y ago
- cglong 5y ago> an app I developed, Clatters, where I use Swift, SwiftUI, Objective-C and C, the most appropriate programming language being used to solve each specific problem. Slightly OT, but when might one choose to write part of a new app in Objective-C instead of Swift? From my understanding, Swift can call any ObjC code.
- qaq 5y agoWhen you need something like NSTableView that has no SwiftUI equivalent
- vedosity 5y agoAt my employer we use Objective-C++ to interface with some shared C++ code. Swift can use C directly but it can be useful to wrap a C library in an Obj-C interface to be easier to use in Swift.
- panic 5y agoI’d compare choosing Objective-C over Swift to choosing C over C++. Swift offers a higher level of abstraction, but Obj-C feels more lightweight.
- wott 5y ago> Obj-C feels more lightweight. That is something I wouldn't have thought I'd hear one day ;-)
- thought_alarm 5y agoThe Swift naming convention makes it more difficult to learn, discover, and use large, complex APIs like AppKit and UIKit, so I'll often revert back to Objective-C when writing AppKit (and to a lesser extent, UIKit) when given the choice. It's common for me to still mix the two languages in a single app. For example, this the AppKit API for pulling a URL off of the pasteboard: +[NSURL URLFromPasteboard:] It's easy to find, since it has both URL and Pasteboard in the name. The Swift version gets melted down to this: URL(from:) which is obfuscated nonsense. Unless you already know that API exists, you'll never find it. The Swift version of AppKit is littered with this kind of obfuscation. Since I don't code in AppKit very regularly, I usually just throw my hands up and switch to Obj-C whenever I start running into these kinds of road blocks. The Obj-C naming convention has advantages and disadvantages, but has always been considered verbose. The Swift designers considered this a problem in need of a solution. As is almost always the case in software development and language design, the solution was a giant overreaction and overcorrection that just replaced one problem with another.
- matchbok 5y agoHuh? That makes no sense. The Swift API is init?(from pasteBoard: NSPasteboard) Which should autocomplete/hint while writing code. The documentation is in the type, not littered within the function name. Much more easier to read and write. The "pasteboard" is still very much in the function declaration. Compared to the obj-C version: + (NSURL *)URLFromPasteboard:(NSPasteboard *)pasteBoard; Not sure why they insist on no spacing, or sane formatting, for Obj-c. I still can't read most Obj-c - it's horribly designed.
- thought_alarm 5y ago> Which should autocomplete/hint while writing code It does not. Parameter types and alternate parameter names are ignored by Xcode autocomplete. If you want to use init(from:), you have to already know that it exists and does something good. Typically, you only find a method like that by looking at the Obj-C header. And that method is declared in the NSPasteboard header, not NSURL.
- thewebcount 5y agoI use Objective-C when using interfaces that require lots of C-style parameters. In particular Metal requires unsafe pointers to vertex and fragment data and I find the contortions you have to use to get Swift to send such data to Metal to be too much work. It’s just more straightforward in Objective-C. It can be done in Swift, but it ain’t pretty. (Or at least, it wasn’t the last time I tried, which admittedly was about a year ago. Maybe it’s better now?)
- armadsen 5y agoI prefer to use Objective-C when using a C API that involves heavy use of pointers (buffer pointers, pointers to structs, requires mallocing things, etc.). It’s not that Swift can’t be used, it’s just that doing all of that is painful in Swift, and completely straightforward in ObjC. I also occasionally need to use C++, which ObjC makes easy in the form of Objective-C++. Swift doesn’t (yet?) have any ability to interface with C++.
- pupdogg 5y agoComing from a Ruby background, I got into Swift by first learning SwiftUI right around when COVID started. I know that sounds backwards but it actually made understanding Swift a lot easier. Overall, I was impressed (specifically with SwiftUI) as it was fairly easy to understand. Sometimes I wish I could do web layouts using SwiftUI. Clojures, Grand Central Dispatch, and Decodable in Swift took a bit longer to get used to.
- mhoad 5y agoI went down a similar path during covid from Ruby and decided to look at native development options for the first time and landed on Flutter instead. I have to say reading through this thread I am so glad I didn’t go down the Swift route it sounds incredibly frustrating which is honestly the opposite of what my Flutter journey has been so far.
- viktorcode 5y agoSearch around, there are projects on GitHub which are using result builders for the web. SwiftUI is a result builder too. Not a web developer, so can't tell if those projects are really useful.
- VWWHFSfQ 5y agois anybody doing anything with swift outside of iphone or mac app development? I recall there was some effort to make it something more than that but I think that's been mostly abandoned at this point since there are so many much better languages already
- boboguitar 5y agoThere was a large effort to bring it into machine learning in place of python, but the team that was over that was restructured and it looks dead.
- ksec 5y agoIBM tried to make it work for web and server. Google tried to use it for ML. Both were abandoned.
- gh123man 5y agoI am! I'm building a complete backend in Swift for an app i'm working on. It's actually been really great so far. I develop on my mac in xcode and deploy on linux via docker. See: https://vapor.codes/ https://vapor.codes/ I'm a little bias because I really like Swift as a language but Vapor is growing and there are lots of plugins to fill the gaps.
- gregkerzhner 5y agoI love Swift too, but dislike Xcode enough to where I wouldn't use it unless I was doing iOS. Even in a medium sized project basic functionality like syntax highlighting or clicking into functions is unreliable. You get used to it being an iOS dev, but switching into something like Intellij is a sobering wake up call where that stuff just works.
- robertwt7 5y agoIs swift docs still bad? I remember developing for swift was a pain when you need to look for docs. Most of my resource came from Raywenderlich instead of official apple docs lol. I have since moved away, but current company wants to move from RN to Native dev so i'm confused if i should be onboard with mobile or move to other dev teams. I find it weird how big companies like Microsoft and Apple have these small flaws. Apple has really bad docs, but good in using its own tech. Microsoft on the other hand has good docs, but almost never uses its own tech (yes, i'm talking about xamarin).
- protomyth 5y agoYes. Worse is most examples are outdated and don't compile. Plus, we are now in an era where third party publishers are not putting out books to cover the gaps like before.
- worik 5y agoThere are very few examples in Apple documentation
- finiteseries 5y agoSwift.org is decent, framework docs are still very bad. Bridging RN - Apple is a hell of a market at the moment though, getting the transition on your resume is worth a look.
- novok 5y agoApple’s iOS libs (not swift ui) although not well documented in parts, is probably the most complete and self consistent set of ui dev libraries around to develop against. Android and web are far more chaotic. I haven’t done windows dev so maybe that is better but nobody does windows desktop anyway. Worst part of it is the lack of a full open source stack and build speed / xcode stability for swift, but its not bad if your just 1-5 engineers in one app. But if you scale to 30+ with +1 million lines after a few years it starts getting real bad unless you architect your app with devapps like airbnb did: https://medium.com/airbnb-engineering/designing-for-productivity-in-a-large-scale-ios-application-9376a430a0bf https://medium.com/airbnb-engineering/designing-for-producti...
- ardit33 5y agoThis was a great write up. My hunch is that older binaries will stay Objective-C forever, until the app is completely replaced. It will linger around, similar to C and C++. There is no major win to just write something in a different language, but using he same frameworks/ui system. Swift is used in brand new apps, and eventually will take over. Swift UI is just too immature, and it is still doesn't provide some of the more advanced components. Great for a toy app, but not for a production level. I hope Apple keeps improving on it, and it doesn't return another niche like IB (Interface Builder), which is used only for small apps, and larger corps just don't use it. ----- Out of all the binaries in iOS 15: 89% are using Objective-C 17% are using C++ 13% are using Swift 8% are entirely written in C 2% are using SwiftUI If Swift was a better designed language, it would have taken over by now. The fact that after 7.5 years, Objective-C still persist, means Swift has soured many devs by its complexity, and sheer amount of shortcuts, (like Scala), and it is not necessary loved or is that much more productive, or gets people exited for. *but used a necessary tool as it is the way most community will move forward.
- novok 5y agoSwift / objc interop is very natural, so if it ain’t broke, why fix it wrt to swift rewrites.
- simondotau 5y agoEven if you imagined a world where Swift existed and ObjC didn’t, it would still make sense for ObjC to be invented. In fact it would be an utterly inspired way to build a glue layer between Swift and the masses of C (and C-compatible) libraries out there.
- dev_tty01 5y ago> If Swift was a better designed language, it would have taken over by now. So, a company that is selling over two hundred million devices per year that depend on a stable software stack, should have thrown away millions of lines of working code just to port it all over to a language that was still undergoing massive evolution over that 7.5 year period. Really? Sorry, but that would have been a disaster.
- ksec 5y ago>Out of all the binaries in iOS 15: 89% are using Objective-C 17% are using C++ 13% are using Swift 8% are entirely written in C 2% are using SwiftUI Objective C looks healthy.
- kgc 5y agoWouldn't most binaries not have UI anyways? Probably better to compare Swift UI to previous UI frameworks.
- tambourine_man 5y agoSwift was conceived and sold as an all purpose language. To an extreme degree, in fact. Lattner has said many times that it's intended from scripting to system programing[1]. Currently it's good at neither. I think a language that's simultaneously productive at this two extremes is impossible, but it was their goal. [1] https://developers.slashdot.org/story/17/01/23/085232/slashdots-interview-with-swift-creator-chris-lattner https://developers.slashdot.org/story/17/01/23/085232/slashd... “In short, I would NOT say that Swift is an extremely compelling systems programming or scripting language today, but it does aspire to be great for this in the years ahead.” Jan 2017
- urthor 5y agoI’ve had very few complaints with Swift as a backend language in all honesty. I can see it as a backend/systems language. It is not a scripting language. The issue is the stewardship of the ecosystem. The fact the Foundation library is closed source is a complete joke in this day and age. Apple’s lack of effort towards fostering a broader community for its language is a comedy of errors. A Swift developer will spend much time dealing with undocumented closed source packages. It’s almost comedic how retro it is. It’s like coding in the 1980s.
- adamnemecek 5y ago> The fact the Foundation library is closed source is a complete joke in this day and age. Foundation is open source https://github.com/apple/swift-corelibs-foundation https://github.com/apple/swift-corelibs-foundation
- stefan_ 5y agoThe distinction this article wants to make does not exist. Even if your app chrome is written in Swift, what good is that if any image you show can end up in someones C PDF parser that Apple includes wholesale. Think of it as "Swift + Objective-C + C++ + C" versus "Objective-C + C++ + C".
- arthurofbabylon 5y agoI'd love to see the language breakdown for new development. The binary analysis pulls in a lot of legacy code, so it doesn't really reflect emerging code composition.
- seanalltogether 5y agoWhats really surprising is if you look at the results, the only pure swift binary (that isn't under libswift*) is a protocol buffers library, rather then adapting the existing c++ one maintained by google. /System/Library/PrivateFrameworks/CloudKitCodeProtobuf.framework/CloudKitCodeProtobuf |Swift https://blog.timac.org/2021/1219-state-of-swift-and-swiftui-ios15/iOS15.txt https://blog.timac.org/2021/1219-state-of-swift-and-swiftui-...
- ChrisMarshallNY 5y agoObjC isn't going anywhere, anytime soon. The same for UIKit and IB. Lots of people want them to go away, but we don't always get what we want.
- syspec 5y agoO
- Shadonototra 5y agoSwift and SwiftUI are very nice I don't get to use macOS anymore, but i'm envious of them whenever i need to write some UIs native, fast, memory efficient, memory safe and easy to build nice things
- jordansmithnz 5y agoWhile ObjC is far from dead, I’m not sure these metrics paint an accurate picture. For a Swift-first app or binary, there are a few reasons that you might see ObjC as part of the binary: - easier interop with ObjC - Xcode code generation (CoreData, Intents, etc) - legacy code (no real benefit to rewriting if it works fine with Swift) I’d expect most Swift-first binaries to have even a small amount of ObjC for one of the reasons above. I’d also expect that binaries already containing ObjC would rarely drop it, even if new development is done in Swift.
- pjmlp 5y agoMetal is a mix of Objective-C and C++, while most examples use Swift, they are actually bindings to the implementation.
- ternaryoperator 5y agoSwift is a language that feels right to me in ways that others don't. I code on Linux and Windows, not on Macs. Swift on Linux works OK, but it's there that you really see how few pure Swift libraries there are. For example, on the project we were exploring, the only Swift library for handling zip files--and we asked the community several times--was a personal project with 14 stars. That was not going to work for our enterprise. The port of Swift to Windows barely functions and in every dimension is in worse shape. It's a shame b/c the language is truly beautifully designed.
- tonyedgecombe 5y agoI don’t think the story is ever going to change much on non Apple platforms. It just doesn’t make sense for them.
- zapnuk 5y ago> It just doesn’t make sense for them. It does though. As least for me. Better support on Windows and Linux would increase the number swift developers which would the in turn result in more and better open source libraries. For Apple this could mean that their own open source libraries could get better, they have more tools/libraries to choose from, or simply that they have a greater pool of talent for hiring. Looking at Go (and Rust) I think this is somewhat shown. There are a lot of different factors, but I think the development tools of Go is the #1 reason why it is basically the only "new" language in a long time that gained a large enough popularity to become mainstream - as in you actually find jobs developing in Go. Which is in some ways sad. It seems like Swift could be the very good fit for backend/serverless development. I guess the real question is how much effort would it take to get the development tools like editor support to the next level?
- auggierose 5y agoSwift is designed to be a lock-in to Apple development for Apple. If it was otherwise, why WOULDN'T you also provide compilation to Wasm and Javascript, etc., if you are a company with the resources of Apple? Don't get me wrong, Swift is great, but it is a big lock-in. I have programmed for the last 4 years or so almost exclusively in Swift, but I am now switching to TypeScript in general. Writing my libraries in TypeScript, I will still be able to access them from Swift and other languages via embedded browser engines.
- rectang 5y ago> C++ and C still play an important role. These languages are typically used by binaries related to audio, video, telephony, web, and other low-level frameworks. Even so, a C Audio API like AudioGraph was deprecated a few years back and its replacement, AVAudioEngine, is Objective-C/Swift. The skills that you develop while working with one of these platforms, the familiarity you develop with the libraries, the conventions, the ecosystem, the tools, none of that effort is portable.
- aaaaaaaaaaab 5y agoAVAudioEngine is laughably buggy and incomplete though.
- logbiscuitswave 5y agoMy professional development work is primarily done with Visual Studio and C#, but I’ve been working on some projects in my downtime with Swift and SwiftUI. I’ve found them to be pretty delightful in many ways - frustrating in others. Xcode, of course is a big wildcard. Often times I find myself spending more time just fighting with the IDE than getting any real work done. Maybe I’m just used to Visual Studio, but Xcode has some really baffling design decisions or omissions that never fail to confound me. SwiftUI is really cool and it’s really simple to string together some pretty UX. I really like its approach to data binding and sharing. It makes it really easy to share models across many different views with minimal fuss. That being said, it still feels immature with its out of the box controls. Just the other day I found myself wanting a simple wrapping horizontal stack control only to find nothing like this was provided out of the box. Layout can also be really frustrating - getting things where I want them is often very fiddly. Swift itself is also quite nice - although it’s evolving really, really fast and tutorials/howtos and such go stale really quickly. Swift can and will drop language feature at the drop of a hat. Just today I wanted to do a simple C++ style for loop only to find this was removed completely from the language. I’m also perpetually frustrated by the terseness or incompleteness of Apple’s docs. I would prefer to read docs rather than watch hours of WWDC presentations just to understand how something works but that seems to be the best way to get this information.
- CamelRocketFish 5y agoHorizontal stack control - https://www.appcoda.com/learnswiftui/swiftui-gridlayout.html https://www.appcoda.com/learnswiftui/swiftui-gridlayout.html Is that what you need?
- logbiscuitswave 5y agoThis isn’t exactly what I was looking for - basically I wanted an HGrid with a bunch of items that would automatically wrap rather than overflow. (In the WPF world that I’m more accustomed to this would be called a “WrapPanel”). I eventually found a package on GitHub called WrappingHStack that did exactly what I needed but this struck me as odd that something like this wasn’t out of the box functionality.
- mwattsun 5y agoI always wondered why the creator of Rust switched to Swift and just now found my answer by Graydon Hoare himself: https://old.reddit.com/r/rust/comments/7qels2/i_wonder_why_graydon_hoare_the_author_of_rust/ https://old.reddit.com/r/rust/comments/7qels2/i_wonder_why_g... tl;dr it has nothing to do with the relative merits of the two languages --- Edit: I watched a couple of Lex Fridman podcasts this week with Chris Lattner (creator of Swift) that I thought were interesting Chris Lattner: Compilers, LLVM, Swift, TPU, and ML Accelerators | Lex Fridman Podcast #21 https://www.youtube.com/watch?v=yCd3CzGSte8 https://www.youtube.com/watch?v=yCd3CzGSte8 Chris Lattner: The Future of Computing and Programming Languages | Lex Fridman Podcast #131 https://www.youtube.com/watch?v=nWTvXbQHwWs https://www.youtube.com/watch?v=nWTvXbQHwWs
- pram 5y ago“I've always been a language pluralist -- picture my relationship towards languages like a kid enjoying a wide variety of building blocks, musical instruments or plastic dinosaurs -- and I don't think evangelism or single-language puritanism is especially helpful.” What a great statement!
- spaetzleesser 5y agoDoes this mean that Apple is using the same libraries they are asking third party developers to use? I used to do Windows development and it always bugged me that MS wasn’t using MFC and later on Winforms or WPF for their own apps. The libraries would be much better if they dogfooded their own stuff.
- balls187 5y ago> Does this mean that Apple is using the same libraries they are asking third party developers to use? Yes and now. Apple still has and uses private APIs, which by license agreement 3rd party developers cannot and should not use. Additionally SwiftUI is only ~3 years old, so it does not yet have 1:1 parity needed to fully migrate all of Apple's apps over. That said, I to was disappointed that Microsoft had their own internal UI libraries for WindowsPhone7/8 which were not exposed to developers, such as the Map tile libraries.
- pjmlp 5y agoVisual Studio used MFC until it was rewriten in WPF. SQL Server Studio used MFC until it was rewriten in WPF. The Ribbon on WPF was originally designed on Office, then made availalble as a COM library on Windows 7 and wrapped as WPF bindings. MFC was replaced by ATL, given how much Windows and Office teams love COM, and they keep loving it, via WRL and now C++/WinRT and WIL.
- pier25 5y agoWait... Apple is still adding new stuff in Objective C? And after about 7 years only 13% of the iOS binaries are in Swift? Quite ironic considering Apple is constantly deprecating stuff and pushing everyone to the latest thing.
- pjmlp 5y ago> Apple’s use of Swift is progressing faster than ever. Last year Swift surpassed C. This year Swift is getting closer to C++. Which is yet another reason why clang is now lagging behind the other compilers, for Apple C++17 is good enough[0], and all other contributors don't seem to be in a hurry to contribute C++20 features to upstream. [0] - IO and driver Kit use the embedded C++ subset, whereas MSL is a C++14 dialect.
- dgellow 5y agoAre Swift and SwiftUI different languages? I naively assumed SwiftUI was just a library to create and render UI components, but I’m not familiar with iOS/macOS development. Just surprised to see a distinction between the two in the article.
- vlozko 5y agoYou’re correct in that SwiftUI is just another library built on top of Swift. SwiftUI heavily takes advantage of a relatively new Swift feature: result builders. So while SwiftUI code is technically Swift code, at times it does feel like a different language as control flow operates differently.
- randomNumber7 5y agoAll the @State, @Published etc. pragmas look to me like they hacked the compiler to do the stuff they couldn't do in a regular library....
- viktorcode 5y agoThose are just property wrappers; another feature of the language accessible to everyone.
- b3morales 5y agoIncorrect. The SwiftUI property wrappers, most notably @State, use internal knowledge and non-public reflection. They are not stably implementable by outsiders.
- bsaul 5y agoswiftui is the latest UI framework for building user interface. it's not a language. However it uses a lot of swift constructs that makes it feel like a Domain Specific Language to describe UIs (like html).
- Someone 5y agoI would love to see a (rough) breakdown in bytes of code, and then by new libraries vs old libraries (maybe split out by iOS version) That would require distinguishing the code emitted by the swift compiler from that emitted by clang. I don’t know how hard that is. Are function prologues and epilogue different, for example? Can we semi-reliably infer that from function names? Do they prefer using different registers first?
- bsaul 5y agothere are definitely a few problems crippling swift adoption in the mobile app dev community (which seems like the easier market for growth) but to me the most important one is this: it's still a apple frontend PL only. There are absolutely no story for cross-platform development, not even business logic (foundation on android is non-existent). After 18 months developping a first version of an app using swift ( for optimal performance and OS integration) i am now investigating more seriously the different options for reusing the maximum amount of code, and so far the result is : 0. 0 code reuse in today's world is absolutely unbearable. I'm at the point where i'm seriously thinking about tools for automatically converting the code to kotlin.
- simonh 5y agoI really don't see this as an issue to be honest. Swift is the first class native development language for the Apple ecosystem, (eventually) superseding Objective-C. That's it's one job. Anything beyond that is a bonus. I don't expect Google to port the Android runtime, SDK and tooling to iOS either.
- b3morales 5y agoThat's probably the view of Apple execs, but it is not the rhetoric that comes out of the Swift Org itself: https://www.swift.org/ https://www.swift.org/ > a programming language to empower everyone to turn their ideas into apps on any platform. https://www.swift.org/about/ https://www.swift.org/about/ > the best available language for uses ranging from systems programming, to mobile and desktop apps, scaling up to cloud services > a web-based REPL can when working with Linux server-side code > it is now free to be ported across a wide range of platforms, devices, and use cases. Our goal is to provide source compatibility for Swift across all platforms ... extend the cross-platform capabilities of Swift ... source compatibility for Swift code across all platforms ... > Open-source Swift can be used on Linux to build Swift libraries and applications > We’d love your help to bring Swift to even more computing platforms.
- bsaul 5y agoExcept google chose kotlin which is developped by another company, which itself has interest to widen the language support to the maximum. As a consequence we have kotlin native and kotlin multiplatform. Apple used an 100% in-house solution but with the official long-term of having it run on the widest range of platform, and an open-source model. In reality, the language is driven toward things nobody gives a damn (swiftUI would have been almost just as good without the syntax sugar), whereas the official initial goals don't have any steam from Apple.