ViewController example

  • open AppConsole/Demo/ViewController/ViewController.xcworkspace

    // part of ViewController.swift
    class ViewController: UIViewController {
      @IBOutlet var label: UILabel!
    
      override func viewDidLoad() {
          super.viewDidLoad()
          // Do any additional setup after loading the view, typically from a nib.
    
          label.text = AppConsole(initial: self).run()
      }
    
      ...
    
  • Run

In [1]:
using Swifter

In [2]:
vc = initial("http://localhost:8080")


Out[2]:
<ViewController.ViewController: 0x7f99cbead550>

In [3]:
@query vc.view


Out[3]:
<UIView: 0x7f99cbd15260; frame = (0 0; 320 568); autoresize = W+H; layer = <CALayer: 0x7f99cbd155e0>>


In [4]:
@query vc.view.backgroundColor = UIColor.yellowColor()


Out[4]:
UIDeviceRGBColorSpace 1 1 0 1

In [5]:
@query vc.view


Out[5]:
<UIView: 0x7f99cbd15260; frame = (0 0; 320 568); autoresize = W+H; layer = <CALayer: 0x7f99cbd155e0>>


In [6]:
@query vc.label.text = "Hello Swift"


Out[6]:
Hello Swift

In [7]:
@query vc.label.numberOfLines


Out[7]:
2

In [8]:
@query vc.label.text = "Hello Swift\nHello Julia"


Out[8]:
Hello Swift
Hello Julia

In [9]:
@query vc.label.font = UIFont(name: "Helvetica", size: 35)


Out[9]:
<UICTFont: 0x7f99cbc09240> font-family: "Helvetica"; font-weight: normal; font-style: normal; font-size: 35.00pt

In [10]:
@query vc.label


Out[10]:
<UILabel: 0x7f99cbc0cd40; frame = (20 100; 500 200); text = 'Hello Swift
Hello Julia'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7f99cbd0cb90>>


In [11]:
@query vc.label.backgroundColor = UIColor.cyanColor()


Out[11]:
UIDeviceRGBColorSpace 0 1 1 1

In [12]:
@query vc.label


Out[12]:
<UILabel: 0x7f99cbc0cd40; frame = (20 100; 500 200); text = 'Hello Swift
Hello Julia'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7f99cbd0cb90>>


In [13]:
@query vc.view.subviews


Out[13]:
  • <UILabel: 0x7f99cbc0cd40; frame = (20 100; 500 200); text = 'Hello Swift Hello Julia'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7f99cbd0cb90>>
  • <_UILayoutGuide: 0x7f99cbd15650; frame = (0 0; 0 20); hidden = YES; layer = <CALayer: 0x7f99cbd15a60>>
  • <_UILayoutGuide: 0x7f99cbd16420; frame = (0 568; 0 0); hidden = YES; layer = <CALayer: 0x7f99cbd165b0>>

In [14]:
@query vc.view.subviews[0].backgroundColor = UIColor.orangeColor()


Out[14]:
UIDeviceRGBColorSpace 1 0.5 0 1

In [15]:
@query vc.view


Out[15]:
<UIView: 0x7f99cbd15260; frame = (0 0; 320 568); autoresize = W+H; layer = <CALayer: 0x7f99cbd155e0>>


In [16]:
(Left, Center, Right) = (0, 1, 2)


Out[16]:
(0,1,2)

In [17]:
@query vc.label.textAlignment


Out[17]:
0

In [18]:
@query vc.label.textAlignment = Center


Out[18]:

In [19]:
@query vc.label.frame


Out[19]:
{{20, 100}, {500, 200}}

In [20]:
@query vc.label.frame = "{{20, 300}, {280, 200}}"


Out[20]:
{{20, 300}, {280, 200}}

In [21]:
@query UIScreen.mainScreen()


Out[21]:
<UIScreen: 0x7f99cbe08360; bounds = {{0, 0}, {320, 568}}; mode = <UIScreenMode: 0x7f99cbe08820; size = 640.000000 x 1136.000000>>


In [22]:
ENV["SWIFTER_SAVE_IMAGE"] = false


Out[22]:
false