   
   */
   public func clear() -> Bool {
-    let query = [ kSecClass as String : kSecClassGenericPassword ]
+    var query: [String: NSObject] = [ kSecClass as String : kSecClassGenericPassword ]
+    query = addAccessGroupWhenPresent(query)
+    lastQueryParameters = query
     
     let status: OSStatus = SecItemDelete(query as CFDictionaryRef)
     

  var lastQueryParameters: [String: NSObject]? // Used by the unit tests

  var keyPrefix = "" // Can be useful in test.
  
  public init() { }
  

  /// Returns the key with currently set prefix.
  func keyWithPrefix(key: String) -> String {
    return "\(keyPrefix)\(key)"
  }
  
  func addAccessGroupWhenPresent(items: [String: NSObject]) -> [String: NSObject] {
    guard let accessGroup = accessGroup else { return items }
    
    var result: [String: NSObject] = items
    result[KeychainSwiftConstants.accessGroup] = accessGroup
    return result
  }
}

