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

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.

主站蜘蛛池模板: 台前县| 钟山县| 乌审旗| 北海市| 景宁| 五大连池市| 峨山| 安平县| 绩溪县| 绥棱县| 富裕县| 盐城市| 宁波市| 忻城县| 桃江县| 吐鲁番市| 什邡市| 昌平区| 阆中市| 连山| 太原市| 甘谷县| 锦屏县| 车险| 泸州市| 贵港市| 罗甸县| 黄浦区| 巍山| 杨浦区| 高密市| 道孚县| 岐山县| 新干县| 华坪县| 湘阴县| 重庆市| 常熟市| 双江| 固始县| 秭归县|