ios - Button On/Off sound in settings -


i have 2 viewcontroller (viewcontroller , settings). how can when switch turned off sound of buttons (or in application) turned off , turned on ??

code sound of buttons:

@ibaction func soundbutton(_ sender: uibutton) {     let filename = "button-16"     let ext = "mp3"      if let soundurl = bundle.main.url(forresource: filename, withextension: ext) {         var soundid: systemsoundid = 0          audioservicescreatesystemsoundid(soundurl cfurl, &soundid)          audioservicesaddsystemsoundcompletion(soundid, nil, nil, { (soundid, clientdata) -> void in             audioservicesdisposesystemsoundid(soundid)         }, nil)          audioservicesplaysystemsound(soundid)     } } 

enter image description here

take global boolean variable issound uiswitch. when uiswitch on means true, make variable issound on. now, make condition based on variable.

you can make global variable appdelegate file or header file. (.h file)

if issound == true || issound == on { // make sound on } else { // make sound off } 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -