ios - Getting to grip with the high level ways of Xcode + Swift -


recently, have started study swift story board, xcode, etc. struggling understand principals of viewcontroller code, seems miss lot of essentials - presumably try , make things more simple - isn't programmers have come else where.

import uikit  class viewcontroller: uiviewcontroller {      //properties      @iboutlet weak var textfieldname: uitextfield!     @iboutlet weak var submit: uibutton!     @iboutlet weak var submit1: uibutton!      override func viewdidload() {         super.viewdidload()         // additional setup after loading view, typically nib.     }      //actions      @ibaction func onsubmit(sender: uibutton) {         switch(sender){             case submit:                 print("only 1");             case submit1:                 print("222");             default:                 print("nothing");         }      } } 

after following basic tutorial, have tried playing around on own test out understanding. iboutlets, define elements of storyboard requires me drag , drop code in order correctly correspond element. when type

@iboutlet weak var submit1: uibutton! 

without having dragged storyboard - not work / correspond. there more backend not have control over?

also, actions. how come prints without method being called?! must missing obvious - attributes?

i want able code things myself, , identify elements/buttons/etc myself without dragging , dropping, , not seeing associations - submit1 , submit, @ moment, set exact same thing: uibutton!

i aware , accept confusion , interpretation flawed , wrong. shed light on lower level activities of viewcontroller?

thanks.

if don't want drag , drop can write, don't see problem

let button = uibutton(frame: cgrect(x: 100, y: 100, width: 100, height: 50)) button.backgroundcolor = .greencolor() button.settitle("test button", forstate: .normal) button.addtarget(self, action: #selector(buttonaction), forcontrolevents: .touchupinside)  self.view.addsubview(button) 

Comments