title: How do I set up a success/failure block so that I can pass a string into it using Swift?
body: <p>I have an API method that returns teams for particular leagues. All I need to do is pass in some parameters.</p>
  
  <p>For example, the API URL looks like this: <a href="http://api.website.com/api/teams?season=last&amp;league=0Xc334xUK4" rel="nofollow noreferrer">http://api.website.com/api/teams?season=last&amp;league=0Xc334xUK4</a></p>
  
  <p>Here is my code:</p>
  
  <pre><code>@objc class APITeam: NSObject {
  
      var leagueObjectID: NSString!
  
      let baseUrl = "http://api.website.com/api"
  
      static let sharedInstance = APITeam()
  
      static let getTeamsEndpoint = "/teams"
  
      static let params = "?season=last&amp;league="
  
      private override init() {}
  
      func getTeams (_ onSuccess: @escaping(Any) -&gt; Void, onFailure: @escaping(Error) -&gt; Void) {
  
          var request = URLRequest(url: URL(string: baseUrl + APITeam.getTeamsEndpoint + APITeam.params)!)
  
          let session = URLSession.shared
  
          request.httpMethod = "GET"
  
          let task = session.dataTask(with: request) { (data : Data?, response : URLResponse?, error : Error?) in
  
              if(error != nil){
                  onFailure(error!)
              } else{
  
                  do {
  
                      let result  = try JSONSerialization.jsonObject(with: data!)
                      onSuccess(result)
  
                  } catch {
  
                      print(error)
  
                  }
  
              }
  
          }
          task.resume()
  
      }
  
  }
  </code></pre>
  
  <p>In order for this API method to return data, I need to pass in the objectID of the league I want teams for when making a request.</p>
  
  <p>I've tried to add parameter to:</p>
  
  <pre><code>func getTeams (_ onSuccess: @escaping(Any) -&gt; Void, onFailure: @escaping(Error) -&gt; Void, leagueObjectID: String) {
  
   var request = URLRequest(url: URL(string: baseUrl + APITeam.getTeamsEndpoint + APITeam.params + leagueObjectID)!)
  </code></pre>
  
  <p>This doesn't work as expected. When I use the method in another class, "leagueObjectID" acts as an additional part of the success, error block if that makes sense. I need to be able to pass the leagueObjectID into the method so it's used at the end of the URL the request is made to.</p>
  
  <p>This is how I call APITeam in an objective-c class:</p>
  
  <pre><code>[[APITeam sharedInstance] getTeams:^(id result) {
  
  } onFailure:^(NSError * error) {
  
  }];
  </code></pre>
  
  <p>As you can see, the extra parameter I added to the getTeams function doesn't show up, and when I try to manually add it, I get an error.</p>
  
  <p>How would you handle this?
  An example would be much appreciated.</p>
  
  <p>Thanks for your time</p>