title: How to get a user attribute from an AWS Cognito user pool in Swift?
body: <p>I'm using AWS Cognito user pools with <a href="https://github.com/awslabs/aws-sdk-ios-samples/tree/master/CognitoYourUserPools-Sample/Swift" rel="nofollow noreferrer">Amazon's Swift sample app</a>.  I'm able to create users with a <code>given_name</code> attribute, but it's not obvious how to later retrieve the <code>given_name</code>. </p>
  
  <p>The Amazon sample retrieves attributes as a <code>AWSCognitoIdentityUserGetDetailsResponse</code> and then dumps them to the screen.  However, I can't find documentation for <code>AWSCognitoIdentityUserGetDetailsResponse</code>.  It appears to be something of an array, but it's not obvious to me how to just pull out a <code>given_name</code> from the returned attributes.  One would think that returning attributes as a dictionary would be a good idea, but it doesn't appear that Amazon did things that way.  </p>
  
  <p>Any pointers?</p>
  
  <p><strong>EDIT:</strong> To clarify, what's returned is an array of <code>AttributeType</code> objects.  Here's code in the Cognito sample which displays all returned attributes:</p>
  
  <pre><code>override func tableView(_ tableView: UITableView, cellForRowAt 
          indexPath: IndexPath) -&gt; UITableViewCell {
      let cell = tableView.dequeueReusableCell(withIdentifier: "attribute", for: indexPath)
      let userAttribute = self.response?.userAttributes![indexPath.row]
      cell.textLabel!.text = userAttribute?.name
      cell.detailTextLabel!.text = userAttribute?.value
      return cell
  }
  </code></pre>
  
  <p>Here's the raw response:</p>
  
  <pre><code>Response body:
  {"UserAttributes":[{"Name":"sub","Value":"XXXXXXXX-XXXX-XXXX-XXXX-
  XXXXXXXXXXXX"},{"Name":"email_verified","Value":"true"},
  {"Name":"given_name","Value":"Bob"},
  {"Name":"email","Value":"bob@example.com"}],"Username":"AAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE"}
  </code></pre>
  
  <p>It's just not obvious to me how to pull out <code>given_name</code> without iterating through the whole array.</p>