Result of call to 'functionName()' is unused

result of call to sink receivevalue:' is unused
result of call to constraint equaltoconstant is unused
result of call to signout is unused
result of call to replacingoccurrences(of with options:range is unused)
discardableresult
result of call to wait timeout is unused
result of 'alert' initializer is unused swiftui
result of call to frame width height alignment is unused

I have an odd issue and I’m not sure what I am doing wrong.

I have the following function that I want called in viewDidLoad to load all documents in a collection that will be used in a tableview.

func functionName() -> [String] {

    var NameArray = [String]()

    db.collection("Names").getDocuments() { (querySnapshot, err) in
        if let err = err {
            print("Error getting documents: \(err)")
        } else {
            for document in querySnapshot!.documents {
                NameArray.append("\(document.documentID)")
            }
        }
    }
    print(NameArray)
    print(NameArray.count)

    return (NameArray)
}

The function has the warning result is being ignored. I don’t want to silence it as I need the value, it should be return an array with values and a non zero count.

I run the below code connected to a button and it returns the array and count as expected. I also would like the keep the variable NameArray as local.

@IBAction func fetchUsersButton(_ sender: UIButton) {
    var NameArray = [String]()

    db.collection("Names").getDocuments() { (querySnapshot, err) in
        if let err = err {
            print("Error getting documents: \(err)")
        } else {
            for document in querySnapshot!.documents {
                NameArray.append("\(document.documentID)")
            }
        }
        print(NameArray)
        print(NameArray.count)
    }
}

Instead of returning an array you need to place it in a completion handler.

func functionName(_ completion: @escaping ([String]) -> Void) {

    var NameArray = [String]()

    db.collection("Names").getDocuments() { (querySnapshot, err) in
        if let err = err {
            print("Error getting documents: \(err)")
        } else {
            for document in querySnapshot!.documents {
                NameArray.append("\(document.documentID)")
            }
        }

        completion(NameArray)
    }        
}

Xcode 7 warning: Result of call to 'map' is unused, Result of call to 'map' is unused. This warning doesn't make sense. How can I suppress it? UPDATE: I got this to work by doing the following,  Navigating to Call Results. When viewing a Lead Profile, Call Results (1) may already be displayed on the upper left corner above the Dashboard. If not, click the Log Call button (2) to bring up the Call Results. Selecting a Call Result. Call Results can be selected manually by clicking on them, or by using Hotkeys (if these have been configured).

You can try something like this:

func functionName() -> [String] {

    var nameArray = [String]()

    db.collection("Names").getDocuments() { (querySnapshot, err) in
        if let err = err {
            print("Error getting documents: \(err)")
        } else {
            for document in querySnapshot!.documents {
                NameArray.append("\(document.documentID)")
            }
            print(nameArray)
            return nameArray
        }
    }
    print(nameArray)
    print(nameArray.count)

    return (nameArray)
}

If your code gets to the else statement its because there were no problems and you were able to fetch data; thats when you need to return the array after you loop through every document. Because that firebase function uses a completion handler, thats why if you put the print statements outside the completion, it gets executed automatically. Also you shouldn't be starting variables with a capital letter. In swift it's a good practice to use camelCase. Hope this helps.

Result of call to subscribe(onNext: onError: onCompleted , RxSwift: Result of call to subscribe(onNext: onError: onCompleted: onDisposed:) is unused - warning. The solution is simply to add the subscription to a  Is there any proper example for explaining call-by-result ? (not pseudocode) I have learned that ALGOL 68, Ada could use this way, but I cannot find any clear example of Call-by-Result.

The reason that you aren't returning anything is because db.collection().getDocuments is an asynchronous function. What this means is that the function gets to "return" before the db.collection().getDocuments code is done executing.

"Return" assumes that the code will execute synchronously which means it will execute line by line in a predictable order. An asynchronous function is one in which we don't know when it will finish executing (which is always true of network code).

What if the network is down? What if it takes a long time to download? Since we can't know, we use a completion handler to "return" what we need once the function has completed. The other suggestions are great, below is another solution. As a note, it assumes that this function is part of class, and you want to assign the result to an outside variable.

class MyClass {

      var myNameArray = [String]()

      func functionName() {

          db.collection("Names").getDocuments() { (querySnapshot, err) in
              if let err = err {
                  print("Error getting documents: \(err)")
              } else {
                  for document in querySnapshot!.documents {
                      myNameArray.append("\(document.documentID)")
                  }
              }
          }
      }

}

Another small thing about naming conventions, variables should utilize camelCase, so nameArray is preferable to NameArray.

Swift 3 Warning of Unused Result, This has been giving me a lot of warnings of the form “Result of call to someFunction is unused”. By default in Swift 3 ignoring the return value  Clifton Park restaurant crowd results in call to police. La Fiesta in Clifton Park, NY Thursday May 5, 2011. ( Michael P. Farrell/Times Union ) Michael P. Farrell. CLIFTON PARK – The parade of

Result unused warnings, Let's have I have code: audienceController?.hide().done { _ -> Void in #code } This throws warning Result of call to 'done(on:flags:_:)' is  If the expected phone call time comes and goes, and you don’t hear by the time they tell you that you will hear, then place that call to the right person and get your test results. If they take a message and you don't hear back within a few hours, then call again. Continue to pursue those results until someone calls you with them.

Swift: Discardable Result - Patrick, In Swift 2.2, if you called a function and didn't use its returned result you would receive no warning. To generate a warning the method definition  It’s time to build a few JavaScript applications to see what jQuery can do for you when you’re retrieving results from AJAX calls. Although your real-world situations will be more complex, the process is going to be the same. How to work with standard output This example uses the DoMath.php script to perform math and …

How to ignore return values using @discardableResult, Without that attribute in place you'd need to assign the result to underscore to silence the warning, like this: _ = scores.updateValue(3, forKey:  The result of a function can be assigned to a variable, but it cannot be used as a variable. If you want to assign a new value to the function itself, omit the parentheses (the function call operator).