Type 'Class' does not conform to protocol 'MCSessionDelegate'

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Type 'Class' does not conform to protocol 'MCSessionDelegate'



I'm working on migrating my code from Swift 2.X to 3.X and have already resolved majority of my runtime error except one that keeps on bugging out.
I have all the required functions and have cleaned and deleted the derived data but it still saying that my class does not conform to 'MCSessionDelegate'.
`


import MultipeerConnectivity
import Foundation

class Cashier: Advertiser

var waiterBecomesConnectedHandler: ((MCPeerID) -> Void)?
var waiterBecomesDisconnectedHandler: ((MCPeerID) -> Void)?


extension Cashier: MCSessionDelegate


@available(iOS 7.0, *)
func session(_ session: MCSession, didStartReceivingResourceWithName resourceName: String, fromPeer peerID: MCPeerID, with progress: Progress)



@available(iOS 7.0, *)
func session(_ session: MCSession, peer peerID: MCPeerID, didChange state: MCSessionState)
switch state
case .notConnected:
waiterBecomesDisconnectedHandler?(peerID)
connectedPeerSessions.removeValue(forKey: peerID)
break

case .connected:
waiterBecomesConnectedHandler?(peerID)
break

case .connecting:
break




@available(iOS 7.0, *)
func session(_ session: MCSession, didReceive data: Data, fromPeer peerID: MCPeerID)



@available(iOS 7.0, *)
func session(_ session: MCSession, didReceive stream: InputStream, withName streamName: String, fromPeer peerID: MCPeerID)




@available(iOS 7.0, *)
func session(_ session: MCSession, didFinishReceivingResourceWithName resourceName: String, fromPeer peerID: MCPeerID, at localURL: URL, withError error: Error?)


`



Here is the code for the protocol
`


// Delegate methods for MCSession.
public protocol MCSessionDelegate : NSObjectProtocol


// Remote peer changed state.
@available(iOS 7.0, *)
public func session(_ session: MCSession, peer peerID: MCPeerID, didChange state: MCSessionState)


// Received data from remote peer.
@available(iOS 7.0, *)
public func session(_ session: MCSession, didReceive data: Data, fromPeer peerID: MCPeerID)


// Received a byte stream from remote peer.
@available(iOS 7.0, *)
public func session(_ session: MCSession, didReceive stream: InputStream, withName streamName: String, fromPeer peerID: MCPeerID)


// Start receiving a resource from remote peer.
@available(iOS 7.0, *)
public func session(_ session: MCSession, didStartReceivingResourceWithName resourceName: String, fromPeer peerID: MCPeerID, with progress: Progress)


// Finished receiving a resource from remote peer and saved the content
// in a temporary location - the app is responsible for moving the file
// to a permanent location within its sandbox.
@available(iOS 7.0, *)
public func session(_ session: MCSession, didFinishReceivingResourceWithName resourceName: String, fromPeer peerID: MCPeerID, at localURL: URL, withError error: Error?)


// Made first contact with peer and have identity information about the
// remote peer (certificate may be nil).
@available(iOS 7.0, *)
optional public func session(_ session: MCSession, didReceiveCertificate certificate: [Any]?, fromPeer peerID: MCPeerID, certificateHandler: @escaping (Bool) -> Swift.Void)
`





Are you really building apps to be backward compatible to iOS < 7.0 ? If not, try removing the @available(...) and just set your iOS target to >= 7.0. In most cases you should no longer be targeting such old versions of iOS.
– ekscrypto
Aug 13 at 2:06





@ekscrypto thank you for the advice*. I removed the @available(...) and changed my iOS target to 8.0 now it's telling me to add a didStartReceivingResourceWithName stub which I already have on my code.
– Martin Jaycy Halum
Aug 13 at 2:12



didStartReceivingResourceWithName





It should have a “fix” button in the warning bubble. If you click on it check the stub it created, most likely you have one of the type wrong or a parameter name changed
– ekscrypto
Aug 13 at 2:14





I clicked on the fix button and it's showing the exact same functions. Am I missing something?
– Martin Jaycy Halum
Aug 13 at 2:39




2 Answers
2



Remove all the functions from the extension


extension Cashier: MCSessionDelegate.





Thanks for the answer and I did the steps above and it's still showing me that my class still does not conform to the protocol.
– Martin Jaycy Halum
Aug 13 at 6:57






Please share the protocol code for MCSessionDelegate or maybe link for repo
– Tushar Katyal
Aug 13 at 7:47





I updated my question to add the MCSessionDelegate
– Martin Jaycy Halum
Aug 13 at 8:17





Try the answer posted by Ashley Mills below. Seems like that's the issue
– Tushar Katyal
Aug 13 at 9:13



One of your delegate methods is wrong. at localURL: URL should be at localURL: URL?


at localURL: URL


at localURL: URL?


func session(_ session: MCSession,
didFinishReceivingResourceWithName resourceName: String,
fromPeer peerID: MCPeerID,
at localURL: URL?,
withError error: Error?)



https://developer.apple.com/documentation/multipeerconnectivity/mcsessiondelegate/1406984-session






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard