insta catering
insta catering

Reputation: 160

unrecognized selector sent to instance 0x7fe098c09830

So I've seen and tried various countless changes to my code based on what i've seen on stackoverflow but literally nothing seems to work. The error is occuring when I press my volume button which will write to user default data so I can check that whenever audio is about to play during actual game play.

I think this is only my problem because i've tried everything. Anyway my code is below:

//if user presses volume button
@IBAction func DaVol(_ sender: Any)
{
    //if User default for audio is nil, initialize it, otherwise change it where needed
    if audioDefaultIsMuted.value(forKey: "Volume") != nil
    {
        //if the audio has been on turn it off
        let tempAudioDefaultIsMuted = audioDefaultIsMuted.value(forKey: "Volume") as! Bool
        if  tempAudioDefaultIsMuted == false
        {
            //if label is the on music one, set value to true (meaning ismuted will be true)
            //then change label to off label
            audioDefaultIsMuted.set(true, forKey: "Volume")
            audioDefaultIsMuted.synchronize()

            //change to new image
            volumectrl.setImage(#imageLiteral(resourceName: "nowaves"), for: UIControlState.normal)
        }
        else
        {
            //otherwise set value to false
            //then change label to on one
            audioDefaultIsMuted.set(true, forKey: "Volume")
            audioDefaultIsMuted.synchronize()

            //change to new image
            volumectrl.setImage(#imageLiteral(resourceName: "audio"), for: UIControlState.normal)
        }
    }
    let currVolImage = volumectrl.image(for: UIControlState.normal)
    //check curr image and do same shit as before accordingly
    if  currVolImage == #imageLiteral(resourceName: "audio")
    {
        //if label is the on music one, set value to true (meaning ismuted will be true)
        //then change label to off label
        audioDefaultIsMuted.set(true, forKey: "Volume")
        audioDefaultIsMuted.synchronize()

        volumectrl.setImage(#imageLiteral(resourceName: "nowaves"), for: UIControlState.normal)
    }
    else if currVolImage == #imageLiteral(resourceName: "nowaves")
    {
        //otherwise set value to false
        //then change label to on one
        audioDefaultIsMuted.set(false, forKey: "Volume")
        audioDefaultIsMuted.synchronize()

        volumectrl.setImage(#imageLiteral(resourceName: "audio"), for: UIControlState.normal)
    }
}

Upvotes: 0

Views: 163

Answers (2)

Vishwas Singh
Vishwas Singh

Reputation: 1657

It may be that you have connected button action to a method and after that you changed the method name or deleted the method and written and connected a new method.

Do this-

  1. Right click on button in storyboard(if using) and delete all actions on it
  2. Connect button action again by dragging from button to corresponding action method

Upvotes: 0

menq
menq

Reputation: 391

Where did you get the audioDefaultIsMuted, and check its value.

You can use swift let if to simplify your code like this

if let value = audioDefaultIsMuted.value(forKey: "Volume") {
  print(value)
}

Upvotes: 1

Related Questions