A little tentative view of Swift

Source: Internet
Author: User
Tags notification center

This article transferred from: http://onevcat.com/2014/06/my-opinion-about-swift/

Thanks to the original author

Although 4:30 to get up and wait for admission, the result is just sitting in the back of the position to watch the big screen to participate in this year's Keynote. In fact, this year OS X and IOS have a lot of update highlights. But it was clear that the thunder and the light had been snatched from Swift's birth. This part of the content is not an NDA. So I can say it in advance.

Swift is an Apple-created language designed specifically for Cocoa and Cocoatouch, intended to replace OBJC.

In the morning, there were a lot of friends who said that in fact they had written for a very long time and returned to a site where the first thing to say is that the Swift parallel scripting language and Apple's Swift is not a thing, and both can be said to have no relation. Apple is also very friendly with the swift Parallel scripting language site link behind its swift introduction page to alert those poor kids who really want to search and have a swift that has been misled by SEO.

Personally, after playing Swift for a few hours, I was deeply fond of the new language. This article is a brief introduction to Swift from the point of view of a person who has just begun to learn (in fact, everyone is just beginning to learn), because today we are actually on the same starting line, so there may be a lot of inaccuracies in understanding. If you make a mistake, please do it lightly.

What is Swift

A lot of people are seeing Swift at first sight. This is a scripting language. Swift is indeed very similar to some scripts because of the very many grammatical features. But the first thing to understand is that, at least in Apple development, Swift is not executed in a scripting language, and all swift code will be LLVM compiled into native code, executed at a very high efficiency. According to the official benchmark data given today, execution is 3.9 times times faster than Python. About 1.4 times times faster than OBJC. I believe the official data is definitely a bit of water, but even so, Swift brings a lot of reverie and anticipation. Swift, like the original OBJC, is a type-safe language, and variables and methods have a clear return, and the variables need to be initialized before they are used. In terms of grammar, Swift has migrated to the industry's well-known, highly advanced grammatical system. These include closures, multiple returns, generics, and a large number of functional programming concepts, and the function eventually becomes a one-class citizen to be able to save as a variable (although the detailed implementation and use of the method and JS that the traditional meaning of the same seems to be different).

A preliminary look at the syntax borrowed a lot of the human design of Ruby, but with the help of Apple's own powerful LLVM, it is necessary to get rid of ruby more than one or two levels in performance.

There is one more aspect. Swift's code is also able to Interactive to "explain" the operation. The new Xcode adds the so-called Playground to interactively correspond to the swift code entered by the developer, but uses Swift's command-line tools to run the SWIFT statement interactively. The attentive friend may have noticed, and here I put the "explanation" two words on the double cited.

This is because even on the command line. Swift is not in fact interpreted as running, but rather in each of the instructions behind the SWIFT code that has been compiled from the beginning of the line and then run. This practice still allows people to "feel" is doing interactive interpretation of the run, the language of the compiler speed and optimization level, visible. At the same time, Playground also records the various situations in which each statement runs, called a group of timeline. Be able to use timeline to run the code to gradually check, eliminating the time of the breakpoint debug , is also very convenient.

For more specific examples such as Swift's syntax, you can see Apple's release of the Swift programming Language in IBooks, or you're a developer, and you can look at pre-release's documentation

Cool. Can I use Swift today?

As the successor of Apple's OBJC, Swift, as a ios/mac developer, is considered necessary and worthwhile to learn and use.

Swift can now be mixed with the original OBJC or C-series code (note that unlike OBJC and C + + or C in the same. mm file, the Swift file cannot be written in the same file as the OBJC code. You need to separate the two types of code). The compiled binaries are capable of executing on iOS 7 and iOS 8 devices (iOS 6 and earlier are not supported).

Although I have not tried it, the app binary package, which uses the new clang to compile swift, should now be able to submit to the app Store only if your target is IOS 7 and above.

A very good news is that all of the documents in Xcode 6 should have the OBJC and swift two language versions. Therefore, the document support should not be a problem. and follow the pace of the Apple developer community consistently. It is reasonable to believe that in the near future, Apple is likely to decisively drop OBJC's support and turn to Swift. So, my personal advice on the answer to this question in the title is to learn as quickly as possible. Start using it as soon as possible.

If you have a certain scripting language base (Ruby is best, Python or JS is very good), and better understand the idea of the COCOA framework, the transition to the new language should be completely not a problem. You will find that there have been so many objc that have been very depressing to achieve, and it is easy to do it in a new language.

I'm not shy about the efforts of Apple's countless project designers and language design geniuses. Swift absorbs the essence of many languages. It should be the latest in the world (it's not nonsense) and the most advanced programming language (one of them). And I think it's Apple's confidence in the language that it will be able to say that the company is still in its heyday, and that it is so bold to change the language. Since Apple is bound to be better than you and me, the benefits of switching languages must be far greater than the drawbacks that are worth the risk.

In this sense. Today's announcement will be a blockbuster in the program development industry. It will also be written into the register, and you and I are actually in the midst of it, becoming the witness of this history.

How do I start?

Very easy, although all over the years WWDC under the control of the NDA so that we can not discuss too much content, but this time the Swift is an NDA outside the content. Apple has released enough resources for us to start learning. The first is the official Swift introduction page, where you can learn some of the basic features and details of Swift.

Then there is the swift book downloaded from IBooks. You don't have to read through the book. And just a high-speed look at the content of the tour section before 35 pages. will be able to start applying it to development. Because it is not subject to NDA restrictions, StackOverflow's swift tag and Google should be immediately filled with relevant issues and content. Follow up and trust with other developers to learn and progress from scratch, you will be very quick and skilled in developing with Swift.

(as is true.) It's too good to be useful. It's hard to imagine that I'm writing a beautiful closure or nesting function or returning more, that kind of inner excitement and joy ... )

Summary

This WWDC can be said to be a summary and outbreak of Apple's previous years ' layout. From the start of the MAC integrated phone and SMS, and ubiquitous Handoff, to the back of the Notification Center widget and System framework extension, and more Family Share, and so on, can say that Apple through its own control of the industrial chain and ecological The circle is intact. Let IDevice or Mac user viscosity has been enhanced than ever before. For a person, maybe an Apple device will make him very easy to buy a second third; for a family, a member may have an Apple device. Others will also be promoted by propaganda and convenience.

This is a coup and is a trend that Apple has been doing in recent years.

In fact, Rome was not built in a day, and in the development of languages, Apple was in fact carefully crafted for many years. In terms of language, Apple, who had no prior experience at all, resolutely chose to leave the GCC camp and reinvent itself to make Clang and LLVM layouts. And in the last few years to OBJC small repair after a revolutionary outbreak.

Abandon a mature development community in the great time of the day Jin million. Instead of turning to a new programming language, making such a decision can only say that the company's boldness is impressive and admirable. On the other hand, Apple has a reason to attract a lot of other developers to the Apple development camp, and because of the syntax and learning curve of OBJC, Swift is obviously a lot easier, and for developers in other camps, it's a great opportunity to enter.

The propaganda of this WWDC is in the right language. Apple has provided us with better tools, why don't we continue our journey and realize our dreams?

Write the code. The world.


A little tentative view of Swift

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.