Swift 3.0 Result of Call Is Unused

Result of call is unused

You are confusing the results variable, which is, indeed, used inside the closure, and the result of the taskForDELETEMethod call itself, which is NSURLSessionDataTask object.

From the examples of using taskForDELETEMethod that I was able to find online it looks like it is perfectly OK to ignore the return value, so you can avoid this warning by assigning the result to _ variable, i.e.

let _ = taskForDELETEMethod {
... // The rest of your code goes here
}

Swift result of call to is unused

Assign the return value of the function to _ to explicitly discard it, like this:

_ = somethingThatReturnsAValueYouDontCareAbout()

Swift 3 warns about unused function return values, so you need to show it that you know what you're doing.

Swift 3 : Warning Unused result of call when overriding BecomeFirstResponder

The bug has been solved in the lastest Swift version.

Swift Compiler Warning : Result of call to 'save(defaults:)' is unused

The DataHandling instance's save(defaults:) function technically returns a value, even if you don't use it. To silence this warning, assign it to _ to signify that you don't intend to use the result value, e.g.:

_ = ordering.save(defaults: indexPath.defaultsKey)

or

let _ = ordering.save(defaults: indexPath.defaultsKey)

Just to be clear, this is almost definitely not why your tableview is not loading data. It should be pretty insignificant. The indexPath.defaultsKey is being saved (assuming the API works).

Swift 3 Result of call to (_:parameters:completionHandler:)' is unused warning and Braced block of statements is an unused closure error

You can annotate the method it is warning you about with @discardableResult.

For example:

@discardableResult
func foobar() -> Bool {
return true
}

Result of call to 'sorted(by:)' is unused

.sorted(by: ) 

returns the sorted array, if you need the sorted array and leave the original array untouched.

.sort(by:)

it doesn't returns anything, it sorts the original array.
If you don't care about original array being modified, then use .sort(by:)

Result of call to [myFunction] is unused

This is behaviour that has been introduced in Swift 3. Instead of having to explicitly annotate functions with @warn_unused_result in order to tell the compiler that the result should be used by the caller, this is now the default behaviour.

You can use the @discardableResult attribute on your function in order to inform the compiler that the return value doesn't have to be 'consumed' by the caller.

@discardableResult
func makeConstraint(withAnotherView : UIView) -> NSLayoutConstraint {

... // do things that have side effects

return NSLayoutConstraint()
}

view1.makeConstraint(view2) // No warning

let constraint = view1.makeConstraint(view2) // Works as expected

You can read about this change in more detail on the evolution proposal.



Related Topics



Leave a reply



Submit