vendredi 22 mars 2019

Swift: Override AVAudioSession recordPermission

I am trying to test following code

switch AVAudioSession.sharedInstance().recordPermission {
     case AVAudioSession.RecordPermission.granted:
        if !self.recording {
          fallthrough
        }
        label = device.localizedName
     case AVAudioSession.RecordPermission.denied:
        fallthrough
     case AVAudioSession.RecordPermission.undetermined:
        label = ""
}

To test this code i need to be able to mock recordPermission. The Swift API for recordPermission is described like the following:

/* Returns an enum indicating whether the user has granted or denied permission to record, or has not been asked */
@available(iOS 8.0, *)
open var recordPermission: AVAudioSession.RecordPermission { get }

I created a Mock class called AVAudioSessionMock. I am trying to override the recordPermission property as follows

import AVFoundation

public class AVAudioSessionMock: AVAudioSession {
  private let permission: AVAudioSession.RecordPermission
  public override var recordPermission: AVAudioSession.RecordPermission {
    get {
      return self.permission
    }
  }

  init(permission: AVAudioSession.RecordPermission){
    self.permission = permission
  }
}


However the compiler is showing me an error of Property does not override any property from its superclass.
Any idea what I am doing wrong?

Aucun commentaire:

Enregistrer un commentaire