- RubyMotion iOS Develoment Essentials
- Abhishek Nalwaya Akshat Paul
- 749字
- 2021-08-13 16:43:53
Why RubyMotion?
So far we have learned what RubyMotion is, but the question that comes to mind is, why should we use RubyMotion? There are many reasons why RubyMotion is a good choice for building robust iOS apps. The following sections detail a few that we think matter the most.
If you are not an Objective-C fan
For a newbie developer, Objective-C is an arduous affair. It's complicated to code; even for doing a simple thing, we have to write many lines of code. Though it is a powerful language and one of the best object-oriented ones available, it is time consuming and the learning curve is very steep. On the other hand, Ruby is more expressive, simple, and productive in comparison to Objective-C. Because of its simplicity, developers can shift their focus onto problem solving rather than spending time on trivial stuff, which is taken care by Ruby itself. In short, we can say RubyMotion allows us to use the power of Objective-C with the simplicity of Ruby.
Ruby classes used in RubyMotion are inherited from Objective-C classes. If you are familiar with the concept of object-oriented programming, you can understand its power. This means we can directly use Apple iOS SDK classes from your RubyMotion code. We will be discussing more on this in the next chapter.
Tip
Ruby classes in RubyMotion have the same ancestor as Objective-C.
It is not a bridge
RubyMotion apps get direct access to iOS SDK APIs, which means the size of application and performance created using RubyMotion is comparable to the one created using Objective-C. It implements Ruby on top of the Objective-C runtime and iOS Foundation classes. RubyMotion uses a state-of-the-art static compiler based on Low Level Virtual Machine (LLVM), which converts the Ruby source code into a blazing fast machine code. The original source code is never present in the application bundle. A typical application weighs less than 1 MB, but the size can increase depending on the use case.
Managed memory
One of the key features of RubyMotion is that it takes care of memory management. Just like ARC (Automatic Reference Counting) with Xcode 4.4 and above, we don't have to take the pain of releasing the memory once an object is no longer used. RubyMotion does the magic and we don't need to think about it. It handles it on its own.
Terminal-based workflow
RubyMotion has a terminal-based workflow; from creation of the application to deployment, everything can be done through terminals. If you are used to working on terminals, you know it adds to speedier development.
Easy debugging with REPL
The terminal window where you run Rake also gives you the option to debug with REPL (Read Evaluate Print Loop), which lets you use Ruby expressions that are evaluated on the spot, and the results are reflected on the simulator while the application is still running. The ability to make live changes to the user interface and internal application data structures at runtime is extremely useful for testing and troubleshooting issues with the application, as this saves a lot of time and is much faster than a traditional edit-compile-run loop. If this confuses you right now, don't worry, as we will discuss more on this powerful feature in later chapters.
Tip
REPL is similar to IRB in Ruby.
It is extendable
We can use RubyMotion salted gems easily by just adding them in the Rakefile
. What are RubyMotion salted gems? We can't use all the gems that are available for Ruby right now, but there are a lot of gems specifically developed for RubyMotion. As the RubyMotion developer community expands, so will its gem bouquet, and this will make our application development rapid.
Third-party Objective-C libraries can be easily used in a RubyMotion project. It supports CocoaPods, which is a dependency manager for Objective-C libraries, making this process a bit easier.
Debugging and testing
RubyMotion has a console-based inbuilt interactive debugger for troubleshooting the issues both on a simulator and on a device using GDB (GNU Debugger). GDB is extremely powerful on its own, and RubyMotion uses it for debugging the compiled Ruby code. Also, RubyMotion projects are fit for Test Driven Development (TDD). We can write a unit test for our code from the beginning. We can use Behavior Driven Development (BDD) with RubyMotion, which is integrated into every project. We will discuss more about testing in later chapters.
Tip
RubyMine editor also supports RubyMotion and it has a very powerful debugging mechanism through breakpoints.
- 從零開始:數字圖像處理的編程基礎與應用
- JavaScript全程指南
- 移動UI設計(微課版)
- Flask Web開發入門、進階與實戰
- Python金融數據分析
- SEO實戰密碼
- Julia Cookbook
- Mastering JBoss Enterprise Application Platform 7
- Android開發:從0到1 (清華開發者書庫)
- Creating Mobile Apps with jQuery Mobile(Second Edition)
- Mastering Backbone.js
- Learning AWS
- Django實戰:Python Web典型模塊與項目開發
- 后臺開發:核心技術與應用實踐
- Python函數式編程(第2版)