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

REPL – the interactive console

RubyMotion comes with an interactive console that lets us traverse and scan the code that we are using in our application. The good thing is that the console is connected to the application running on the simulator. This means that if we make any changes from the console, it will be reflected on the simulator in real time. Let's try this with our HelloWorld application.

Run the application as follows:

$rake

As expected, it will open a simulator and the terminal screen will show:

(main)>

Now hold the Command key and hover the mouse over the simulator. You will see a red-bordered box. As we move the mouse pointer over an element, we can see its corresponding class object appearing in the terminal window (UIView:0xc5710c0)? as seen in the following screenshot. Now click the mouse to select the object that you want to work on dynamically.

Try the following command on the terminal and observe the changes in the simulator:

self returns the current object selected by the mouse.

(#<UIView:0x7652680>)> self
=> #<UIView:0x7652680>

Create an object blue for the UIColor class and assign the color blue to the variable as follows:

(#<UIView:0x7652680>)> blue = UIColor.blueColor

To change the background color of the view, use the backgroundColor property of the selected view as follows:

=> #<UICachedDeviceRGBColor:0xb05a800>
 (#<UIView:0x7652680>)> self.backgroundColor = blue
=> #<UICachedDeviceRGBColor:0xb05a800>

Make sure that the background color on the simulator has been changed to blue as shown in the following screenshot:

Let's dismiss the alert box by clicking on any button and put a new alert box with the following code:

a = UIAlertView.new
a.title = "My Title"
a.message = "Hello World!"
a.show

The simulator shows a new alert box on screen without compiling the code as shown in the following screenshot:

You can dismiss the alert box as follows:

(main) > a.dismiss

We can see how REPL is a great tool for developing applications for iOS and how it helps us make changes dynamically. To make these changes permanent we need to add the same code to our source code.

主站蜘蛛池模板: 轮台县| 日土县| 四子王旗| 饶阳县| 镇江市| 南城县| 高州市| 鹤峰县| 修武县| 诸城市| 泸溪县| 宁明县| 宿迁市| 鸡泽县| 博白县| 海阳市| 阳高县| 长沙市| 丹巴县| 达拉特旗| 福海县| 灯塔市| 鞍山市| 修文县| 交城县| 永川市| 武强县| 巴林右旗| 贵港市| 绵阳市| 陕西省| 神池县| 元阳县| 双江| 濉溪县| 枣阳市| 古蔺县| 宁城县| 集贤县| 建阳市| 临朐县|