segue - SWIFT: Passing Data from one class to another -
so have been using prepareforsegue pass data 1 variable class. works fine when variable passing data destinationviewcontroller. happens when it's not?
example: taking moving viewcontroller1 viewcontroller2 want data viewcontroller1 go "non viewcontroller" class though still want segue vc2 happen.
any ideas? thank you!
override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject?) { if (segue.identifier == "stoprecording") { //let playsoundsvc:playsoundsviewcontroller = segue.destinationviewcontroller as! playsoundsviewcontroller let audioeffectsclass = audioeffect() let data = sender as! recordedaudio audioeffectsclass.receivedaudio = data } }
import foundation import avfoundation
class audioeffect {
let session = avaudiosession.sharedinstance() var audioengine: avaudioengine! var audioplayernode: avaudioplayernode! var audiofile: avaudiofile! var receivedaudio: recordedaudio! var changeeffect = avaudiounittimepitch() func create(){ //output through speakers do{ try session.overrideoutputaudioport(avaudiosessionportoverride.speaker) } catch {print("failed output audio through speakers.")} audioengine = avaudioengine() audioplayernode = avaudioplayernode() audioengine.attachnode(audioplayernode) } func playaudio(){ audioengine.stop() audioengine.reset() { audiofile = try avaudiofile(forreading: receivedaudio.filepathurl) } catch {print("failed create file.")} audioplayernode.schedulefile(audiofile, attime: nil, completionhandler: nil) { try audioengine.start() } catch {} audioplayernode.play() audioengine.attachnode(changeeffect) audioengine.connect(audioplayernode, to: changeeffect, format: nil) audioengine.connect(changeeffect, to: audioengine.outputnode, format: nil) } func playaudiowithvariablepitch(pitch:float) { changeeffect.pitch = pitch create() playaudio() } func playaudiowithvariablerate(rate: float){ changeeffect.rate = rate create() playaudio() } func stopaudio(){ audioengine.stop() }
}
if have variable referencing class, make method receive data in class , call method , pass data in prepareforsegue
.
Comments
Post a Comment