PASynchronizedDictionary

public final class PASynchronizedDictionary<Element>

A class to create a synchronized dictionary

  • Initialize the dictionary with an option of passing a custom queue and/or an existing dictionary

    Declaration

    Swift

    public init(queue: DispatchQueue? = nil, dict: [String: Element] = [String: Element]())

    Parameters

    queue

    A custom queue to be used for the synchronization

    dict

    A dictionary to be used as the starting state

  • Returns the number of elements in the dictionary

    Declaration

    Swift

    public func count() -> Int
  • Reurns a boolean indicating if the dictionary is empty or not

    Declaration

    Swift

    public func isEmpty() -> Bool
  • Returns a boolean indicating if the dictionary contains the requested Key

    Declaration

    Swift

    public func containsKey(key: String) -> Bool

    Parameters

    key

    The key of the object to check

  • Reurns the Keyset of the dictionary

    Declaration

    Swift

    public func keys() -> Dictionary<String, Element>.Keys
  • Reurns a boolean indicating if the dictionary contains the requested Value

    Declaration

    Swift

    public func containsValue(value: Element) -> Bool

    Parameters

    value

    The value of the object to check

  • Returns the Valueset of the dictionary

    Declaration

    Swift

    public func values() -> Dictionary<String, Element>.Values
  • Returns an optional element for the requested Key

    Declaration

    Swift

    public func get(key: String) -> Element?

    Parameters

    key

    The key of the object to retrieve

  • Returns the complete dictionary

    Declaration

    Swift

    public func getAll() -> [String : Element]
  • Returns the object for the requested Key if found Returns the Default Value if no object was found for the requested Key

    Declaration

    Swift

    public func getOrDefault(key: String, defaultValue: Element) -> Element

    Parameters

    key

    The key of the object to retrieve

    defaultValue

    Default value to return if no object was found for the requested Key

  • Reurns the label of the queue being used for synchronization

    Declaration

    Swift

    public func getQueueLabel() -> String
  • Put the element if its not already in the dictionary or update its value if its present

    Declaration

    Swift

    public func putOrUpdate(key: String, value: Element)

    Parameters

    key

    The key of the object to insert/update

    value

    The value of the object to insert/update

  • Puts the element in the fictionary only if its missing

    Declaration

    Swift

    public func putIfAbsent(key: String, value: Element)

    Parameters

    key

    The key of the object to insert

    value

    The value of the object to insert

  • Removes the element associated with the provided key

    Declaration

    Swift

    public func remove(key: String) -> Element?

    Parameters

    key

    The key of the object to remove

  • It merges the current dictionary with the one provided

    Declaration

    Swift

    public func merge(dict: [String : Element])

    Parameters

    dict

    The dictionary to be merged with the current one

  • Removes all the objects in the dictionary

    Declaration

    Swift

    public func removeAll()