Converting Swift 2.3 to Swift 3.0 - Error, Cannot invoke 'dataTask' with an argument list of type'
The compiler wants URLRequest
and Error
...
var request = URLRequest(url: storeURL!)
request.httpMethod = "Post"
...
let task = session.dataTask(with: request,
completionHandler: { (responseData:Data?,
response:URLResponse?,
error:Error?) -> Void in
I recommend to omit all type annotations
let task = session.dataTask(with: request,
completionHandler: { (responseData, response, error) -> Void in
Swift 3: Cannot invoke dataTask with an argument list of type error
In Swift 3 the compiler wants native URLRequest
let urlRequest = URLRequest(url: url) // use a lowercase variable name, URL is a native struct in Swift 3
But with your particular syntax you don't even need the request
let task = session.dataTask(with: url) { (data: Data?, response: URLResponse?, error: Error?) in ...
nor the annotations
let task = session.dataTask(with: url) { (data, response, error) in ...
Error on dataTask - Cannot invoke 'dataTask' with an argument list of type...
Due to some comments, I have an answer! I changed the "request" from an NSURLRequest to a URLRequest and I also updated the code to this:
// Create a datatask and pass in the request
let dataTask = session.dataTask(with: request, completionHandler: { (data, response, error) in
// Get a reference to the image view element of the cell
let imageView = cell.viewWithTag(1) as! UIImageView
// Create an image onject from the data and assign it into the ImageView
imageView.image = UIImage(data: data!)
})
Cannot invoke 'dataTask' with an argument list of type (with: NSMutableRequest, ...)
Try this -
func performGetRequest(_ targetURL: URL!, completion: @escaping (_ data: Data?, _ HTTPStatusCode: Int, _ error: NSError?) -> Void) {
var request = URLRequest(url: targetURL)
request.httpMethod = "GET"
let sessionConfiguration = URLSessionConfiguration.default
let session = URLSession(configuration: sessionConfiguration)
let task = session.dataTask(with: request) { (data, response, error) in
DispatchQueue.main.async(execute: { () -> Void in
completion(data, (response as! HTTPURLResponse).statusCode, error)
})
}
task.resume()
}
Cannot invoke with an argument list of type Swift 3
Declaration of the functions:
func deviceShadowCallback(
_ name: String?,
operation: AWSIoTShadowOperationType,
operationStatus: AWSIoTShadowOperationStatusType,
clientToken: String?,
payload: Data? ) {
}
func register(
withShadow: String,
eventCallback: (
String?,
AWSIoTShadowOperationType,
AWSIoTShadowOperationStatusType,
String?,
Data? ) -> Void) {
}
Execution:
let statusThingName = "status"
register(withShadow: statusThingName, eventCallback: deviceShadowCallback)
I could compile and run it without any problems.
Swift 3 - Error - Cannot invoke 'data' with an argument list of type '(using: String.Encoding)'
You are using NSString , what you should do is use String
request.httpBody = "{}".data(using: String.Encoding.utf8)
I got a error when convert swift 3 from 2.3 Cannot invoke initializer for type 'CGFloat' with an argument list of type '((UIContentContainer, C ~~
Show us your definition of padding, it should be a number, but I think the compiler thinks it is a closure. If that's not it, let's see all the definitions. Or in Xcode move your cursor over each of these after stopping on the line using a breakpoint to confirm they are the type you expect. One of them isn't...
Edit 1: You have shown places where these variables have been correctly defined. But you've also shown code that doesn't make sense if you consider scope. Inside your first "if" statement you have the following:
var size: CGFloat = 25
But you never do anything with it while it is in scope. You never actually use the variable size while it is within scope (defined to be 25).
So where else do you define it?
Look at padding in the lines further down. You define it 3 times, but never use them after you define them, and the value you assign here goes away when each gets to the closing "}".
You define padding somewhere else as well, if you're not getting compiler errors.
Cannot invoke 'async' with an argument list of type '(execute: ())'
The syntax
DispatchQueue.main.async(execute: () -> Void)
expects a closure without parameter.
Use the syntax
DispatchQueue.main.async(execute: { someFunc(str: car) })
or with trailing closure syntax
DispatchQueue.main.async {
self.someFunc(str: car)
}
and don't forget the label parameter.
Cannot invoke 'dataTask' with an argument list of type
For some reason adding:
return ()
at the end of the closure, as suggested on the Apple forum, fixed the issue.
RxCocoa: Cannot invoke 'bind' with an argument list of type '(to: (UITapGestureRecognizer) - Void)'
I think bind(onNext: @escaping (E) -> Void)
is what you look for, rather than bind<O: ObserverType>(to observer: O)
.
Compare implementations:
public func bind<O: ObserverType>(to observer: O) -> Disposable where O.E == E {
return self.subscribe(observer)
}
public func bind(onNext: @escaping (E) -> Void) -> Disposable {
return subscribe(onNext: onNext, onError: { error in
rxFatalErrorInDebug("Binding error: \(error)")
})
}
Related Topics
Dynamic/Runtime Dispatch in Swift, or "The Strange Way Structs Behave in One Man's Opinion"
How to Open a Screen Directly in Xcuitest
Retrieve Multiple Photos Under a Node from Firebase Storage
How to Speed Up Updating Relationship Among Tables, After One or Both Tables Are Already Saved
How to Encode an Unmanaged<Seckey> to Base64 to Send to Another Server
For Loop for Dictionary Don't Follow It's Order in Swift
Swiftui Present Alert with Input Field
How to Print Call Stack in Swift
Modal View Closes When Selecting an Image in Uiwebview iOS
Nsimage Getting Resized When I Draw Text on It
Session.Datataskwithurl Completionhandler Never Called
Swift: Double Conversion Inconsistency. How to Correctly Compare Doubles
Adding Items to Array as a Dictionary Value
How to Subclass Nsoperation in Swift to Queue Skaction Objects for Serial Execution