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

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.
主站蜘蛛池模板: 资中县| 中方县| 肥城市| 集贤县| 永清县| 塔城市| 旬阳县| 丹巴县| 鹰潭市| 南涧| 逊克县| 涞源县| 儋州市| 黄骅市| 东兰县| 宣武区| 剑河县| 汾西县| 都安| 成武县| 中卫市| 梁山县| 兴仁县| 和龙市| 松潘县| 茶陵县| 谢通门县| 长葛市| 津市市| 井研县| 北流市| 慈溪市| 芜湖市| 五台县| 二连浩特市| 甘洛县| 申扎县| 富源县| 盐边县| 陆良县| 汽车|