- RubyMotion iOS Develoment Essentials
- Abhishek Nalwaya Akshat Paul
- 346字
- 2021-08-13 16:43:55
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.
- Python概率統(tǒng)計(jì)
- Reactive Programming with Swift
- 我的第一本算法書
- 從程序員到架構(gòu)師:大數(shù)據(jù)量、緩存、高并發(fā)、微服務(wù)、多團(tuán)隊(duì)協(xié)同等核心場(chǎng)景實(shí)戰(zhàn)
- Python Network Programming Cookbook(Second Edition)
- Salesforce Reporting and Dashboards
- HTML5從入門到精通(第4版)
- 編寫高質(zhì)量代碼:改善Objective-C程序的61個(gè)建議
- 機(jī)器學(xué)習(xí)微積分一本通(Python版)
- Android Studio Cookbook
- Android Sensor Programming By Example
- C#面向?qū)ο蟪绦蛟O(shè)計(jì)(第2版)
- HTML5 Canvas核心技術(shù):圖形、動(dòng)畫與游戲開發(fā)
- C# 7 and .NET Core 2.0 Blueprints
- Java Script從入門到精通(第5版)