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

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.
主站蜘蛛池模板: 陕西省| 航空| 诏安县| 安图县| 惠东县| 德钦县| 黄大仙区| 岳阳市| 湛江市| 呼伦贝尔市| 屏东市| 北宁市| 锡林浩特市| 临澧县| 确山县| 孟津县| 济阳县| 遂川县| 莲花县| 桓台县| 万荣县| 华池县| 江安县| 洛浦县| 仁怀市| 罗田县| 永康市| 嘉义市| 盐边县| 锡林郭勒盟| 二手房| 南岸区| 铁力市| 枞阳县| 井研县| 阿鲁科尔沁旗| 舟曲县| 杨浦区| 和平区| 赣榆县| 大英县|