Android &swift iOS Development: Language vs. frame comparison

Source: Internet
Author: User
Tags try catch

Reprinted from: Http:// &utm_medium=articles_link&utm_content=link_text

From Android to Swift iOS development: Language vs. frame comparison

I've been developing Android since 2009 and started contacting Swift at the end of 2014, when the group once did a demo App and felt that the technology was not mature enough to be officially released. At the beginning of 2016, we formally used Swift to develop the Sales assistant app products, accumulated a rich experience in swift Project combat, the open source framework is the SWIFT version, the use of a lot of protocol-oriented and functional programming. IOS app developers are basically the previous Android version of the developer, while maintaining Android and iOS 2 versions, high efficiency. Today's shared theme is how Java/android developers can quickly get started with Swift iOS development. The main contents are as follows:

    1. Why from Java/android to Swift

    2. Why is swift language worth learning?

    3. Java vs Swift Syntax comparison

    4. Android and iOS UI development comparison

    5. Android vs Swift iOS Framework comparison

    6. Comparison of development tools

Why from Java/android to Swift

Cost and efficiency, due to the current functionality of the Android and iOS app products, a team development can reduce the cost of business synchronization and communication, and avoid product functional differences and communication costs for Android and iOS two teams.

Swift syntax is closer to Java, relative to objective C easy to get started, I had an iOS project in 2012, learned OC, because can not tolerate OC strange grammar finally gave up, but this learning swift iOS process is smooth, the main threshold of learning is Xcode IB's use.

Why isn't React Native?

React Native We also want to use the project. But the learning curve of Rn thought and grammar is a bit steep, and many people with web development experience don't necessarily like it. In addition many Android developers did not learn JS, learning react native cost will be higher. Learning react native Ultimately, it is necessary to have a certain understanding of the native development. Finally, in some functionally complex app,react native user experience is less than native.

Why isn't HTML5 Hybrid App?

The user experience is not good enough for engineers who are unfamiliar with web development and have higher learning costs.

Previously we used ionic to do mixed app, the effect on iOS can be, but Android low-end machine compare card, affect the experience.

We now also have the app is react native do, probably last November on-line, the user experience is good, but the developers are basically the front-end development.

Why is swift language worth learning?

Swift is now the language of Apple's main push, and the new language in 2014 is 10 years younger than "new" languages like Scala. 2015 autumn has been open source. Currently available on Linux, the Android NDK has recently been supported, and there are swiftygpio libraries on the Raspberry Pi that can control some hardware with Gpio. Object C is old and Ugly,oc was introduced by Apple in 1983, too stale and bloated.

Swift syntax is similar to Scala,javascript ES6, Java,oc, C + +, Python, which I sort by syntax similarity.

(RedMonk and Tiobe's language rankings, Swift is on the list)

Swift has been younger for many years than Scala, Clojure and other languages.

Swift supports multi-paradigm programming: protocol-oriented, object-oriented, and functional programming. Finally, we can also learn functional programming ideas through SWIFT, which is supported by JAVA8.

Java vs. Swift syntax comparison basic syntax

Swift's switch syntax is similar to Java and C + +, but it does not break and will automatically exit switch when he hits a case. For several different cases of the same case, you can use a few consecutive condition, separated by commas.

The For loop and Java are basically the same, but no parentheses are required. For loop, the. < is more convenient to use. The underscore symbol _ (the variable in the substitution loop) can ignore the specific value and does not provide access to the value when the loop is traversed. For-in is somewhat similar to the in-Java for Each loop.

There are significant differences between the try catch and do while and Java in Swift 2.2.

Functions and closures

The definition of the SWIFT function is very different from Java, and the SWIFT function is defined as Func foo (arg:type), Return Type:

    • The function in Swift is a one-class citizen and can be used as a return value and parameter; Swift supports closures, and JAVA8 supports lambda closures.

    • Swift supports tuples, and swift functions can support multiple return values through the return tuple.

    • Swift functions can be nested, meaning that functions can also be defined inside a function, which Java does not support.

    • The SWIFT function can receive indeterminate parameters, which are basically similar to Java.

    • Swift function parameters can have default values, similar to Python, where Java functions are not available with default values.

Commonly used functional programming methods Map,reduce, Flatmap,filter,sort, compared to understanding the abstract functional programming concept, I think it is more important to start with these functions first.

struct vs. class

struct is a value class, class is a reference type, the Java language does not have a struct, but the c/c++/c# language has, but cannot take the method.

Swift Development recommends using a struct instead of a class. The swift language implementation consists of hundreds of structs, with only a few class.

The Swift class construction method is init (), the destructor is Deinit (), and the class method call is basically the same as in Java.

Self is equivalent to this in Java, which needs to be declared as weak when it passes through a closure with a life-cycle inconsistency.

Enum enum

Android development Google official does not recommend the use of enum, affecting performance.

Swift's enum, like Java, is essentially a class that can contain functions.

Swift enum syntax is simpler.

Swift enum supports extended extension.

Interface vs. Protocol

The extension extension is the addition of new functionality (functionality) to an existing class, struct, or enumeration type. This includes the ability to extend a type without having permission to get the original source code (that is, reverse modeling). Extensions are similar to classifications in Objective-c (categories).

The extensions in Swift can:

    • Adding computed properties and calculating static properties

    • Defining instance methods and type methods

    • To provide a new constructor

    • Define Subscript

    • Defining and using a new nested type

    • Make an existing type conform to an interface

The extensions in Swift are powerful, either the struct class enum or the class of the system can be extended. It is important to note that the scope of the extension method is not discussed here.

Multithread Multithreading

The multithreading of iOS is relatively simple compared to Java, and GCD can be understood in a day's time. Java's concurrency package is a bit more complicated.

Android,ios UI Development Comparison

iOS Development Apple officially recommends using storyboard to develop the UI, the benefits are more intuitive, through the interface to better understand and maintain the app. Now that the Xcode7 version is getting better with AutoLayout and sizeclasses, the multi-resolution adaptation is simple, and it is recommended that you discard the traditional approach of using frame code writing interfaces.

Of course, storyboard also has the following drawbacks:

Interface mainly relies on IB generation, Xib code is difficult to maintain, Xcode open storyboard or xib will make changes to the file, even if we do not make actual changes, Git will show the file changes.

Multi-person assistance, while modification leads to conflict, merging difficulties.

Storyboard contains more pages and takes up too much memory, causing Xcode to stutter and crash.

Error location difficult, error is not clear, novice difficult to locate the error. For example, accidentally deleted Iboutlet will be difficult to locate.

Storyboard UI Development Practices

According to the business module divided into multiple storyboard, each module responsible for avoiding cross.

Each storyboard does not exceed 10 pages and can be re-divided by refactor storyboard function.

Use container in a Storyboard reusable UI module, with Xib in multiple Storyboard multiplexing UI modules.

Complex input forms, it is recommended to write code with the Swiftyform framework.

It is easier to use the size classes for long resolution adaptation.

Android vs Swift iOS Framework comparison

The SWIFT framework is now a lot, and Swift can also use the OC Open source framework, but it is not recommended. We mainly compare the network request framework, JSON parsing and picture caching framework that are commonly used in projects.

While Android development is now generally developed using network frameworks such as Okhttp,retrofit and volley, the iOS development OC ERA uses afnetworking library development, and Swift Development recommends the use of Alamofire and Moya libraries.

Moya the Alamofire Network request Library is encapsulated, development does not need to write network model, management and so on. Make your code more concise. Moya can replace the network abstraction layer Apimanager that you write. Moya offers some very good features:

    • Compile time Check API interface call correctness

    • Clearly defined interfaces for different APIs through enum enum types

    • Having the interface test stub as a class citizen makes unit testing simple.

    • Support Reactivex extension for easy and rxswift integration.

    • Moya is more than Android Retrofit the simulation data debugging function.

Currently the app is basically using JSON as the message protocol, Android development we generally use Gson to parse, in the swift development, compared with Objectmapper,argo+curry,swiftyjson, We decided to use Objectmapper as the JSON parsing framework. The features supported by Objectmapper are as follows:

    • Supports converting objects to JSON, converting JSON into class objects

    • Support for nested objects (single object, Object list collection, and dictionary)

    • Support for custom conversion functions

    • Support struct struct

    • Support Realm and Alamofire integration, Alamofireobjectmapper

Realm is the most popular iOS development database for mobile-based design, instead of SQLite and Android version.

Examples of Use:

Let user = Mapper<user> (). Map (jsonstring)
Let jsonstring = Mapper (). tojsonstring (user, prettyprint:true)

Realm is the most popular iOS development database for mobile-based design, instead of SQLite and Android version.

Picture caching framework, Android development commonly used glide and FRESCO,OC development is generally recommended with sdwebimage,swift development hanekeswift.

Comparison of development tools

Android's current mainstream development tool is Android studio,2014 years ago as Eclipse ADT.
iOS development always uses Xcode. For java/android developers, Xcode is difficult to get started with, especially when interface Builder,xib and view code generate event methods directly through wires, challenging development habits, and having trouble locating problems. And Android developers are accustomed to handwritten XML interface code.

Compared to Android studio, Xcode is fast, but not stable enough, and it's normal to crash a few times a day.
On the emulator side, Android emulator is a virtual machine, startup and installation speed is slow, iOS is simulator, fast, but some features can not be simulated. It is recommended to use a real machine for development.

Package Manager & Build Tools Comparison

Android development early with ant to do some task processing, some teams behind the use of Java EE project with maven,android Studio after the advent of Google recommended gradle. Android's build tools are much more powerful than iOS features.

iOS development early with Cocoapods, now recommended with Carthage, the future of Apple's official launch of Swift 3.0 will promote the official Swift package Manager.

Carthage Advantage is relatively concise, the disadvantage is that some frameworks are not supported, especially the domestic bat some open source libraries.

Finally introduce the next Xcode Package Manager Alcatraz, mainly provide Xcode plug-ins, templates and color mode, compared to Android Studio, the current plug-in is still relatively small.

Thank Xuchuan for the review of this article.

Android &swift iOS Development: Language vs. frame comparison

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: 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.