我正在用WebRTC的委托方法打印几个枚举。比较它们或使用switch语句都可以正常工作,但是其中一个枚举只是打印其类型名称而不是关联的值:
func peerConnection(_ peerConnection: RTCPeerConnection, didChange newState: RTCPeerConnectionState) {
// I don't know why this only prints the type name and not the associated value
print ("peerConnectionState \(newState)")
}
func peerConnection(_ peerConnection: RTCPeerConnection, didChange newState: RTCIceConnectionState) {
print("ICEConnectionState: \(newState)")
}
此打印
peerConnectionState: RTCPeerConnectionState
ICEConnectionState: connected
RTCPeerConnectionState永远不会打印其关联值,即使我检查了它的rawValue,它也是枚举的有效成员。两者都在PeerConnectionState.h中定义,如下所示:
/** Represents the ice connection state of the peer connection. */
typedef NS_ENUM(NSInteger, RTCIceConnectionState) {
RTCIceConnectionStateNew,
RTCIceConnectionStateChecking,
RTCIceConnectionStateConnected,
RTCIceConnectionStateCompleted,
RTCIceConnectionStateFailed,
RTCIceConnectionStateDisconnected,
RTCIceConnectionStateClosed,
RTCIceConnectionStateCount,
};
/** Represents the combined ice+dtls connection state of the peer connection. */
typedef NS_ENUM(NSInteger, RTCPeerConnectionState) {
RTCPeerConnectionStateNew,
RTCPeerConnectionStateConnecting,
RTCPeerConnectionStateConnected,
RTCPeerConnectionStateDisconnected,
RTCPeerConnectionStateFailed,
RTCPeerConnectionStateClosed,
};
我对ObjC-Swift桥接不了解很多,这一切似乎都“奏效”。似乎只影响print()的两个枚举有什么区别?