Expression Resolves to an Unused Function

Expression resolves to an unused function

Swooping in here after Martin R's comment ...

if audioPlayer.playing { audioPlayer.stop} else {  audioPlayer.play}

On this line, you are not calling the stop and play functions, but simply accessing them. Resolving to an unused function is trying to tell you that you have an expression that is returning a function type, but you are never calling it (audioPlayer.stop and audioPlayer.play are the expressions in question here).

To rid yourself of this error, and probably produce the correct behavior, try calling the functions.

if audioPlayer.playing { 
audioPlayer.stop()
} else {
audioPlayer.play()
}

Expression resolves to an unused function, in Swift UI. can't figure out what the problem is

To call the function as the button action, you need to use a function call -- include the parentheses with any parameters -- not just the function name (without the parentheses).

The convention for variable and function names in Swift is lower camel case, so you should consider beginning the function name with a lowercase character.

struct ContentView: View {

@State private var Option = ["1-10","1-100","L or D","Custom"]
@State private var Random = Int.random(in: 0...4)
@State private var num = 0

var body: some View {
NavigationView {
Form {
Section {
Text("Za Warudo")
}
.padding(150)

Section {
ForEach(0 ..< Option.count) { number in
Button(action: {
self.myButtonAction()
}) {
Text("welpo")

}
}
}
}
.navigationBarTitle("We Need Help")
}
}

func myButtonAction() {
num += 1
}
}

Expression resolves to an unused function (Swift)

Remove the { } phase after the in will solve the problem.
It should look like this:

RequestManager.sharedInstance.postRequest(Constants.BASE_URL + Constants.LOGIN, body: requestBody, onCompletion:  {(json: JSON) in
let result = json["response"]
print(result)
}
)

For the closure param, you should not type it by yourself to prevent typo. Use tab key to select that param, then press enter, xCode will auto generate the code for you.

If use the way I just said, the trailing closure will look like this:

RequestManager.sharedInstance.postRequest(Constants.BASE_URL + Constants.LOGIN, body: requestBody) { (json) in
let result = json["response"]
print(result)
}

Expression resolves to an unused function when trying to call removeFirst()

As per Removing Elements in Array - Swift Standard Library

func remove(at: Int) -> Element

Removes and returns the element at the specified position.
Thus

operations.remove(at: 0) 

is returning a function from operations which is then not used. To solve just ignore the result:-

_ = operations.remove(at: 0)

Error: Expression resolves to an unused function (array with closure)

tasks.remove(at: 0) returns the element at position 0 in addition to mutating the tasks array. Assign the result to _ to ignore the result and appease the Swift compiler:

_ = tasks.remove(at: 0)

Expression resolves to an unused function and use of unresolved identifier 'dispatch' errors

I guess you aren't calling the fetchImage function properly. Try this :

if view.window != nil {
self.fetchImage()
}

Don't forget the () after the function name.

Expression resolves to unused I Value

AFAIK, this isn't possible the way you are trying to do it.

One option is to loop through all of your buttons and change the background color in the loop.

for button in [button1, button2]{
button.backgroundColor = UIColor.blueColor()
}

The reason you are getting this error is because this line

let chicken1 = button1; button2

is the same as

let chicken1 = button1
button2 //this value isn't used

Swift doesn't actually need ; at the end of a line like in other languages. By adding ;, you tell Swift that you want to have multiple expressions on a single line.

The second line doesn't do anything because there are no function calls and no assignment, so it's like you want to get the value of button2 but you don't use it.



Related Topics



Leave a reply



Submit