Osman
Osman

Reputation: 1586

Want to create a custom class XY that inherits from a Class and a Protocol

I want to create the AVAudioInputNode in watchOS 3.

If I click on JumpToDefinition for AVAudioInputNode, I see that:

open class AVAudioInputNode : AVAudioIONode, AVAudioMixing {
}

Why I can't create a custom class with the same style ?

My class is:

open class xy : AVAudioIONode, AVAudioMixing {
}

The error is

Type xy does not conform to protocol "AvAudioMixing" and "AVAudioStereoMixing"

Upvotes: 0

Views: 118

Answers (2)

Rob
Rob

Reputation: 437552

Consider:

class XY : AVAudioIONode, AVAudioMixing { ... }

That means that that

  • you're subclassing AVAudioIONode, but also that

  • that you're going to conform to the AVAudioMixing protocol (i.e. that you'll implement the necessary AVAudioMixing methods/properties), as well as any protocols that AVAudioMixing inherits (e.g. AVAudioStereoMixing).

So, your error is telling you that while you've declared that your class will conform to AVAudioMixing (and therefore AVAudioStereoMixing, too), you haven't yet implemented the necessary methods and properties. The compiler is just warning you that you haven't finished implementing XY in order to successfully conform to those protocols.

Upvotes: 0

Mago Nicolas Palacios
Mago Nicolas Palacios

Reputation: 2591

That means you need to conform to those 2 protocols, that means you need to apply specific functions or properties that those protocols requiere.

For Example, for table views on a UIViewController Class you use 2 protocols: UITablewViewDelegate, UITableViewDataSource. And to conform those protocols you need to use this functions.

func tableView(_ tableView: UITableView, numberOfRowsInSection: Int) -> int {
return 1 
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  let cell = tablewView.dequehueReusableCell(withIdentifier: "weatherCell", for: indexPath)
  return cell
}

And also assign its delegate and Data source:

tableView.delegate = self
tableView.dataSource = self

In the specific case of those 2 protocols AVAudioIONode, AVAudioMixing you should search which are the required functions you need to conform.

Upvotes: 0

Related Questions