swift - why can't I use as. it offers me to use as! but still the app doesn't run -


i using swift 1.2 in xcode 6.4
casting types using "as" in code below:

let playsoundvc:playsoundviewcontroller = segue.destenationviewcontroller playsoundviewcontroller   let data = sender = recordaudio   

but giving me error. says have use "as!" instead of "as" in both lines "force downcast" it. however, when fix , using "as!" app doesn't run. have read made update "as" "as!" now. why app still doesn't run ?

if want downcast (sender has superclass of recordaudio):

let data = sender as! recordaudio // make explicit 

if want upcast (sender has subclass of recordaudio):

let data = sender recordaudio 

if want cast type:

let data = recordaudio(sender) 

but have have correct initializer recordaudio class.


in swift syntax has changed as swift 1.2

as! failable casts — casts can fail @ runtime expressed new as! operator make potential runtime failure clear readers , maintainers of code. (link)

since as downcast , destinationviewcontroller not only superclass of playsoundviewcontroller. there can more 1 subclass of destinationviewcontroller.

so can crash. therefore have add ! make explicit know doing.


if not run, maybe destinationviewcontroller not superclass of playsoundviewcontroller.

does playsoundviewcontroller inherit type destinationviewcontroller has?


Comments

Popular posts from this blog

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -