By S.R | 2/18/2017 | General |Beginners

iOS Development & Swift

iOS Development & Swift

In this tutorial, we will introduce you to one of the major mobile application platforms, None other than Apple’s iOS. We will cover a little history of iOS, programming languages that we can use to develop applications for iOS, types of application that we can create, and useful services that we can use during development. We will also talk about web development and the cloud using Swift.

History

iOS was created and developed by Apple Inc. for their own hardware (iPhone, iPad, iPod Touch, AppleTV, Apple Watch). Since 2013 iOS is the second most popular mobile operating systems after Andorid. It was first released in 2007 for the iPhone and iPod Touch and in 2010 for the iPad. iOS was first unveiled with for iPhone at the Macworld Conference & Expo on the January 9th, 2007 and released in June of same year.

 

Initially, third-party applications were not supported. Steve Jobs' reasoning was that developers could build web applications that "would behave like native apps on the iPhone". But on October 17th, 2007 Apple announced that an SDK (Software Development Kit) was under development and they planned to put it in developers' hands in February of the next year. March 6th, 2008 was the day when Apple Inc. officially released the beta version of its mobile operating system under the name “iPhone OS”. In June 2010, Apple rebranded iPhone OS as "iOS".

Programming Languages

iOS supports multiple programming languages (C, C++, Objective C, Swift), with Objective C and Swift being the prefered languages for most app developers. The initial SDK for developers that Apple released only supported C, C++, Objective C but later Apple released their own programming language(Swift) for iOS and MacOS development and took everyone by surprise. Swift is far ahead of the other programming languages used for iOS development. It has all the modern programming language capabilities a developer could ask for. Swift is designed to work with Apple's Cocoa and Cocoa Touch frameworks and the large body of extant Objective-C (ObjC) code written for Apple products. Apple made developer's lives quite easy with Swift by adding functionality to support Objective C in Swift. Now a question arises which should i follow Objective C or Swift? Go through the advantages of Swift over Objective C and you will get your answer.

 

Advantages of Swift over Objective C

1. Swift is easier to read

Objective C suffers all the hurdles that we expect from a language built on C. To differentiate its own keyword from C, Objective C introduced new keyword the @ symbol and since Swift is not built in C it has unified all the keywords and removed all @ symbols.

 

There is no need of semicolons to end lines or parentheses to surround conditional expressions. Methods and function calls is swift use the comma-separated list of parameters within parentheses. The result is a cleaner, more expressive language with a simplified syntax and grammar.

 

Swift code more closely resembles natural English, in addition to other modern popular programming languages. This readability makes it easier for existing programmers from JavaScript, Java, Python, C#, and C++ to adopt Swift.

2. Swift is easier to maintain

Legacy is what holds Objective C back is that the language cannot evolve without C evolving. Objective C requires programmers to maintain two code files in order to improve the build time and efficiency of the executable app. Swift drops the two-file requirement. Xcode and the LLVM compiler can figure out dependencies and perform incremental builds automatically in Swift. The repetitive task of separating the header file  from the implementation file is a thing of the past. Swift combines the Objective-C header (.h) and implementation files (.m) into a single code file (.swift).

 

Objective-C’s two-file system imposes additional work on programmers and it’s work that distracts programmers from the bigger picture. In Objective-C you have to manually synchronize method names and comments between files, hopefully using a standard convention.

3. Swift is safer

One interesting aspect of Objective-C is the way in which pointers, particularly nil (null) pointers are handled. In Objective-C, nothing happens if you try to call a method with a pointer variable that is nil. The expression or line of code becomes a no-operation, and while it might seem beneficial that it doesn’t crash,but it has been a huge source of bugs. A no-op leads to unpredictable behavior, which causes a random crash or stop natural behavior.

Optional types make the possibility of a nil optional value very clear in Swift code, which means it can generate a compiler error as you write bad code. This creates a short feedback loop and allows programmers to code with intention. Problems can be fixed as code is written, which greatly reduces the amount of time and money that you will spend on fixing bugs related to pointer logic from Objective-C.

4.  Swift requires less code

Swift reduces the amount of code that is required for repetitive statements and string manipulation. In Objective-C, working with text strings is very verbose and requires many steps to combine two pieces of information. Swift adopts modern programming language features like adding two strings together with a “+” operator, which is missing in Objective-C. Support for combining characters and strings like this is fundamental for any programming language that displays text to a user on a screen.

 

The type system in Swift reduces the complexity of code statements -- as the compiler can figure out types. As an example, Objective-C requires programmers to memorize special string tokens (%s, %d, %@) and provide a comma-separated list of variables to replace each token. Swift supports string interpolation, which eliminates the need to memorize tokens and allows programmers to insert variables directly inline to a user-facing string.

5. Swift is faster

Dropping legacy C conventions has greatly improved Swift. Benchmarks for Swift code performance continue to point to Apple’s dedication to improving the speed at which Swift can run app logic.

According to Primate Labs, makers of the popular GeekBench performance tool, Swift was approaching the performance characteristics of C++ for compute-bound tasks in December 2014 using the Mandelbrot algorithm.

In February 2015, Primate Labs discovered that Xcode 6.3 Beta improved Swift’s performance of the GEMM algorithm, a memory-bound algorithm with sequential access of large arrays, by a factor of 1.4. The initial FFT implementation, a memory-bound algorithm with random access of large arrays, had a 2.6-fold performance improvement.

Swift is nearly on par with C++ for both the FFT and Mandelbrot algorithms. According to Primate Labs, the GEMM algorithm performance suggests the Swift compiler cannot vectorize code that the C++ compiler can—an easy performance gain that could be achieved in the next version of Swift.

Types Of iOS Applications

We believe that a lot of people have only a very basic understanding of iOS mobile applications, and they don’t know about it’s featured applications. So we’ve decided to explain the main types of iOS applications along with some featured applications as well.

1. Main types of iOS applications

  • App Store: App Store is a mobile application publishing platform created and maintained by Apple Inc. for iOS, allowing users to explore and download applications developed in the iOS Software Development Kit or Mac Software Development Kit from the iTunes Store. Users can download some application for free while others are for pay. Applications can be directly downloaded to iOS devices via the App Store or to a computer via iTunes on the Mac OS X platform or the Windows platform. All iOS Apps have to choose a primary category and an optional subcategory for listing in App Store.

Here is the list of App Categories:

  1. Books
  2. Business
  3. Catalogs
  4. Education
  5. Entertainment
  6. Finance
  7. Food & Drink
  8. Games
  9. Health & Fitness
  10. Lifestyle
  11. Medical
  12. Music
  13. Navigation
  14. News
  15. Photo & Video
  16. Productivity
  17. Reference
  18. Social Networking
  19. Sports
  20. Travel
  21. Utilities
  22. Weather

 

Apps can also select optional sub category from the same list. You can also select two Games Subcategories.

 

Here is the list of App Categories:

  1. Action
  2. Adventure
  3. Arcade
  4. Board
  5. Card
  6. Casino
  7. Dice
  8. Educational
  9. Family
  10. Kids
  11. Music
  12. Puzzle
  13. Racing
  14. Role Playing
  15. Simulation
  16. Sports
  17. Strategy
  18. Trivia
  19. Word

 

  • Built-in program: Different kinds of applications are preinstalled in the latest version of iOS (some applications may vary with devices): Phone, Mail, Safari, Music, Video, SpringBoard, SMS, Calendar, Photo, Camera, FaceTime, Photo Booth, Stocks, Apple Map, Weather, Memos, Magazines, Reminders, Clock, Calculator, Compass, Voice Memorandum, App Store, Game Center, Settings, Address Book, iTunes, Voice Control, Siri etc.

 

  • Web applications: In the Apple Worldwide Developers Conference held in 2007, Apple announced that iPhone and iPod Touch will support some third-party applications through Safari. These applications are called Web Applications and they can be created through AJAX Web technology. The look and feel of the app might be similar to the native app but there is a big difference in performance. Since safari is itself a native app it is not able to use all the resources that a web app needs to give a better performance.

 

iOS Useful Services

1. AFNetworking

AFNetworking has everything that we need for making network requests. It was written with blocks in mind since the beginning (remember that blocks were introduced only on iOS 4.0), as well as GCD and NSOperation. It also uses ARC now and it requires iOS 5.0 or above.

2. MBProgressHUD

Sometimes, our apps are required to do long tasks, such as I/O (mainly networking, or even files) or hard processing. However, the user must have some form of visual feedback, so he won’t think the app has crashed. MBProgressHUD provides this, by creating a HUD (a transparent display that shows info to the user), usually with an UIActivityIndicator on it (but it’s customizable!).

3. TestFlight

TestFlight is a service to easily distribute your beta builds to your tester. The tester receives an email with a link, and it just works. Besides providing distribution, it also allows you to get crash reports, get feedback that your testers give from inside the app and even put checkpoints. It now has a desktop app, that uploads builds even faster.

 

4. RestKit

RestKit is a library created to reduce the code (and work) needed to get your app integrated with a REST remote API. It can do the network stuff, parse the results (XML or JSON) and map them into your own custom classes.

 

5. SocketRocket

Websockets allow bidirectional communication over a single TCP connection. Only some modern browsers support it, but it’s really powerful in real-time applications. Pooling seems so wrong now, doesn’t it?

 

You can find many more such useful libraries here

  1. https://github.com/vsouza/awesome-ios
  2. https://github.com/matteocrippa/awesome-swift



Web Development And Cloud

Today’s applications do not run on a single platform. Rather, some parts run on resource-limited devices, and other parts run on a vast and mysterious cloud of servers. This separation has led to a schism in how we build these applications because different platforms have different requirements: the mobile portions must conserve battery power, while the server portions must handle a large number of requests simultaneously. Consequently, programmers use different languages for different parts of applications for instance, JavaScript for the browser, and Java for the server.

However, constructing an application out of multiple languages is fraught with drawbacks: different teams in the same organization speak different languages literally and must master different developer ecosystems. Precious time must be spent translating concepts across language barriers and a few developers must know all of the languages in order to be effective. Test cases and data models must be replicated in different languages, introducing bugs and incurring future maintenance efforts. Because third-party libraries cannot be shared across groups, each team must learn different APIs to obtain merely the same functionality.

Swift was introduced by Apple in 2014 and replaced Objective-C as the recommended language for all new applications running on Apple devices. Later, when Swift became open source in 2015, it spread to new platforms. Currently, Swift is available on x86, ARM (including Raspberry Pi), and zOS architectures, as well as Linux, macOS, tvOS, watchOS, and iOS operating systems. So, it is now possible to write a whole end-to-end mobile application front-end, middle, back, and even toaster all in Swift. So we wanted to help you, the developer, who is most likely writing in Java or JavaScript, to consider a switch to Swift.

Why adopt Swift?

  • The Swift language may well be better than what you are currently using.
  • You can develop and debug in a consistent environment. Integrated development environments (IDEs) offer a tremendous amount of functionality such as text editing, static analysis, code completion, debugging, profiling, and even source-control integration. Switching back and forth between say, Eclipse and Xcode is a bit like switching between French horn and electric guitar: neither easy nor productive.

 

  • You can reuse code. When each bit of functionality is expressed exactly once, there is less work, more understanding, and fewer bugs.
  • You can leverage Swift’s features such as optional types, value types, and functional programming facilities to detect many bugs at compile time that would otherwise be hard to find.
  • Since Swift uses the LLVM compiler toolchain for producing native-code binaries, your applications have the potential for competitive performance in terms of speed, startup time, and memory usage. However, examination of performance is outside the scope of this article.
  • You will find an active and approachable community of Swift developers who are creating web posts, books, and videos. In 2016, Swift was cited as the second “Most Loved” language in a StackOverflow survey, and the third most upward trending technology.

 

So there you have it. Hope you enjoyed this introduction to iOS and will perhaps consider giving Swift a try. Already a fan of Swift? Leave us a comment below and share your thoughts.

By S.R | 2/18/2017 | General

{{CommentsModel.TotalCount}} Comments

Your Comment

{{CommentsModel.Message}}

Recent Stories

Top DiscoverSDK Experts

User photo
3355
Ashton Torrence
Web and Windows developer
GUI | Web and 11 more
View Profile
User photo
3220
Mendy Bennett
Experienced with Ad network & Ad servers.
Mobile | Ad Networks and 1 more
View Profile
User photo
3060
Karen Fitzgerald
7 years in Cross-Platform development.
Mobile | Cross Platform Frameworks
View Profile
Show All
X

Compare Products

Select up to three two products to compare by clicking on the compare icon () of each product.

{{compareToolModel.Error}}

Now comparing:

{{product.ProductName | createSubstring:25}} X
Compare Now