I would like to perform the default implementation (override) on the existing protocol (URLSessionDataDelegate
), but it will be ignored.
The goal is to make sure that streamManager(didReceive)
must be implemented and that this streamManager(didReceive)
is called within urlSession(_:dataTask:didReceive)
.
public protocol StreamManagerDelegate:URLSessionDataDelegate{
func streamManager (didReceive data:Data)
}
extensionStreamManagerDelegate{
funcurlSession(_session:URLSession,
dataTask —URLSessionDataTask,
DidReceive data:Data) {
streamManager (didReceive:data)
}
}
class Stream:NSObject, StreamManagerDelegate {
func streamManager(didReceive data:Data){
print(String(data:data, encoding:.utf8)!)
}
func start(){
let config = URLSessionConfiguration.default
let session —URLSession=.init(configuration:config,
delete —self,
deleteQueue:nil)
}
}
My own code works well, but the code above does not reflect the default implementation.
protocolSomeTaskDelegate{
func someTask (didRecieve data: String)
}
structureSomeTask {
let delete —SomeTaskDelegate
}
protocolCustomTaskDelegate:SomeTaskDelegate{
func printData(_value:String)
}
extensionCustomTaskDelegate {
func someTask (didRecieve data: String) {
printData(data)
}
}
structure main:CustomTaskDelegate {
func printData(_value:String){
print(value+value)
}
value —SomeTask!
init(){
self.value=SomeTask (delegate:self)
}
}
main().value.delegate.someTask(didRecieve: "1000")
It seems to be a problem that has already been closed in Swift. It is set to Won't Do
, so it probably won't be fixed.
URLSessionDataDelegate
will be available when the day comes when it is written in Swift.
https://bugs.swift.org/browse/SR-3349
© 2024 OneMinuteCode. All rights reserved.