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

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.
主站蜘蛛池模板: 兰溪市| 噶尔县| 根河市| 黄陵县| 乐业县| 阿图什市| 巢湖市| 云梦县| 静安区| 庆元县| 兴安县| 苍溪县| 韶山市| 静海县| 九龙坡区| 长乐市| 昂仁县| 三都| 宿州市| 家居| 安庆市| 子洲县| 镇江市| 获嘉县| 交城县| 平江县| 沧源| 罗山县| 蕲春县| 商城县| 云阳县| 百色市| 玉林市| 沾化县| 安阳市| 海林市| 霸州市| 青铜峡市| 天祝| 娄烦县| 琼海市|