官术网_书友最值得收藏!

Folder structure

In this section, we will understand the folder structure of our application as we know from the previous section that motion create <project name> sets up the directory structure with all the essential files to run a simple RubyMotion application. Let's walk through each one of them to have a precise understanding of their function:

  • The app folder: This is the core of your application code; you will write most of your code in this folder. RubyMotion iterates in this folder and loads any .rb file that it catches.
    Tip

    If you want to keep your code somewhere else other than the app directory, add the folder path to the Rakefile.

  • The app_delegate.rb file in the app folder: This file is at the heart of the RubyMotion application. If you are a little familiar with iOS development, this is the delegate file. A delegate is an object that usually reacts to some event in another object and/or can affect how another object behaves. There are various methods that can be implemented in UIApplicationDelegate. These methods are called during the different phases of an application, such as during the finish of its launch, during termination, when the application is low on memory, and during the occurrence of important changes. While the application is running, tracking its state transitions is one of the main jobs of the application delegate.

    App delegates use the method application:didFinishLaunchingWithOptions as the first entry point. This method is called after your application has been launched. When this method is called, your application is in the inactive state. A few other methods available are:

    • applicationWillEnterForeground
    • applicationWillTerminate
    • application:shouldSaveApplicationState
    • application:shouldRestoreApplicationState

    A full list of available methods can be obtained from the iOS developer library (http://developer.apple.com/library/ios). The good part here is that most of the methods are self-explanatory by their name. For example, applicationWillEnterForeground will be called when your application is relaunched.

    Tip

    We see that in some iOS 6 applications, the app is restored to the previous state; we can handle this in an application delegate.

  • The resources folder: As the name suggests, the resources folder contains static content, such as images, sounds, UI layouts, and icons that we use in our applications.
  • The Spec folder: This folder contains automated test cases. RubyMotion supports a Ruby testing framework, Bacon; it is a small RSpec clone that is used for writing unit, functional, and UI tests. By default, it creates main_spec.rb as an example.
  • Rakefile: With Rakefile we can configure our application name, resources, gems to be included, and the code location. We will discuss more about Rakefile later in this chapter.
主站蜘蛛池模板: 改则县| 寿阳县| 兰西县| 江门市| 安溪县| 桐城市| 霍林郭勒市| 泗洪县| 浦东新区| 铜陵市| 阿图什市| 区。| 瓮安县| 灯塔市| 新闻| 大方县| 永新县| 夹江县| 历史| 巢湖市| 九江县| 屏山县| 汤原县| 大竹县| 乳源| 高州市| 和田市| 宣城市| 衡山县| 合川市| 韩城市| 普洱| 墨玉县| 正宁县| 太湖县| 勃利县| 新沂市| 兴安盟| 中宁县| 百色市| 玉环县|