My app development project this summer is Instant Poetry 2, which was originally an app written by Ray when he was an independent iOS developer. Now I need to completely rewrite it using Swift and iOS 8 APIs. It has been a rich learning experience for me – not only getting to dive into the intricacies of Swift and iOS 8, but also thinking about how I can better pass on these lessons to others in the future. Here are four things I learned while developing my first Swift app. 4) Swift is still evolving The Swift language itself has changed quite a bit over the summer. I started writing apps in beta 3, and each Xcode version upgrade brought syntax changes and tweaks to Cocoa method signatures. If you plan to develop apps using Swift, you need to pay attention to these changes and keep up with the pace of Swift's evolution. But I think it's worth the effort. Using the latest and greatest tools is important, and watching the language evolve will be a great learning experience in itself. Apple is always paying attention to and listening to developers' feedback and problem reports about Swift, so you even have the opportunity to participate in the process of shaping the language. 3) Swift exposes the bad side of Cocoa Did you expect to get a Swift array of SKProduct objects? Sorry, Cocoa will give you an implicitly unwrapped optional array containing AnyObject. Did you mean to pass a Swift array of [NSObject: AnyObject] to the method? Sorry, what Cocoa really wants is an NSDictionary, or something that will silently fail. You can sense the tension between Swift and Cocoa: Swift wants to do something, but it has to compromise to fit in with Cocoa. Let’s face it, Cocoa isn’t always pretty when viewed through a Swift lens!
There is bad news and good news here. The bad news is that we are in the middle of a transition, and part of what Apple does with every Swift/Xcode update is to clean up the Swift-Cocoa interfaces to make them more compatible. The good news is that Apple is very good at transitions, you can recall the transition from PowerPC to Intel processors, the transition from classic Mac OS to OS X, etc. One day in the future, Cocoa will also natively support the Swift language. 2) Swift and Objective-C are a happy couple Really, this is a corollary to my previous point – you may notice some weird things about Swift because it needs to work with the Objective-C runtime and Objective-C APIs, so it has to make compromises.
From a practical development perspective, using Objective-C third-party libraries and extensions in my Swift app is very simple. I just need to import their header files into my bridging header, and they will work normally. If you have a favorite library written in Objective-C, or an existing app to which you want to add a Swift class or two, this isn’t a big problem. 1) Swift is fun I really enjoy playing and working with Swift. It's extremely expressive. Features like optional chaining and nil coalescing let you write shorter code. What surprised me the most was how much I enjoyed using enums - it's really a win-win, making your code more readable, with added benefits like type checking and instance exhaustiveness.
As a fan of Objective-C and Ruby, I think Swift is like a hybrid that combines the advantages of these two languages. If you have learned Objective-C and Cocoa, you will have no difficulty reading Swift code. If you haven't started learning yet, start developing a simple application with Swift now! Additional experience: Extension will change the world! At least that’s how it works in Apple’s world. In iOS 8, Apple introduced app extensions, which allow developers to customize sharing options, notifications, keyboards, and photos through app extensions. In Instant Poetry 2, I used a Photo Extension that allowed users to add words to pictures directly in the Photo app. This was not possible before iOS 8. Applications are no longer confined to their own sandboxes. It seems that the new open Apple will allow apps to do more things from more places. What a wonderful thing. Even with the upcoming Apple Watch, it’s an extension of the iPhone screen, and I can’t wait to see what we can do with Watch Kit. Maybe my next Swift app will be related to Apple Watch! ~ So what will the future look like? My prediction is that the rough edges of Swift will be smoothed out over time, and soon, Swift apps will be everywhere, and on Github, there will be far more Swift projects than Objective-C. However, if you start developing Swift apps now, you will face some challenges. Due to the rapid evolution of Swift, I think it will take a lot of work to migrate a Swift 1.0 project to Swift 2.0, although it is definitely easier than migrating from Objective-C to Swift. But that’s why we love technology, right? Learning new things, keeping up with trends, using the latest languages and APIs, that’s what keeps me excited. ***, if you want to see what Instant Poetry 2 can do, you can download it for free from the App Store. Have you started your Swift development journey yet? If so, I’d like to hear about your experience. Original English text: http://www.raywenderlich.com/86278/four-things-learned-making-first-swift-app |
<<: How do technical founders choose non-technical partners?
>>: [2014 WOT Shenzhen Station Lecturer Interview] Hong Zhixiong: Html 5 games will be popular
Chris2020 Charm System Private Tutoring Course &q...
After being in the arena for a long time You will...
The Yellow River is the mother river of the Chine...
WeChat Mini Program is an application that users ...
In our daily lives, we enjoy the deliciousness an...
Data from the third quarter of 2020 show that the...
Event operation is the most commonly used promoti...
Editor's Note In the past 2021, all walks of ...
Our classmates at Alibaba have always had a hat o...
For most people, Apple and its iOS empire give pe...
With the end of the Spring Festival, the topic of...
According to the Physicists' Organization web...
On March 25, the three IT giants Intel, Google an...
Produced by: Science Popularization China Author:...
Duomai Alliance · Douyin search top optimization,...