Plist

public class Plist

Property list, A file with the default settings.

In the macOS, iOS, NeXTSTEP, and GNUstep programming frameworks, property list files are files that store serialized objects.

Property list files use the filename extension .plist, and thus are often referred to as p-list files.

Wikipedia

let plist = Plist(withNameAtDocumentDirectory: "Plister")
plist.set(2020,for: "new.year")
plist.get("new.year")
// Output: 2020
  • Default folder name which stores plist. you can change it

    Declaration

    Swift

    public static let folderName: String
  • url

    Url of plist wether inside a bundle or document directory

    Declaration

    Swift

    public let url: URL
  • Return result of encryption object, if encryption was nil result will be false

    Declaration

    Swift

    public var encrypted: Bool { get }
  • An AES object that used to encrypt and decrypt properties value

    Declaration

    Swift

    public private(set) var encryption: AES?
  • Original dictionary Get-only to plist.

    Modification occurs on cache property first, then at the end or on your command cache writes to plist and dictionary will updated.

    Declaration

    Swift

    public var dictionary: NSMutableDictionary? { get }
  • Lazy initialized copy of dicitonary property which can be used to read and write at last on willTerminateNotification and didEnterBackgroundNotification cache will write to document directory and dictionary property will updated.

    Declaration

    Swift

    public lazy var cache: NSMutableDictionary? { get set }
  • Property list size with byte described

    Declaration

    Swift

    public var volume: Int64 { get }
  • Property list size including Binary prefix

    Declaration

    Swift

    public var size: String { get }
  • Property list file name

    Declaration

    Swift

    public var fileName: String { get }
  • Property list name

    Declaration

    Swift

    public var name: String { get }
  • Write dictionary to document directory, no need to call this method Plist will do it when needed.

    Declaration

    Swift

    @objc
    public func save()
  • Initialize a plist object with given url inside main bundle.

    every file inside a bundle is read-only so you can only read object attributes.

    let url = Bundle.main.url(forResource: "Info", withExtension: "plist")
    let plist = Plist(mainBundleUrl: url!)
    

    Declaration

    Swift

    public init(insideBundleUrl url: URL)

    Parameters

    url

    Url to plist inside a bundle.

  • Initialize a plist object with given name and store plist file inside document directory then you can read and write.

    If there is a plist which has same name this method only retrive that plist without any change to that file.

    let name = "Client"
    let plist = Plist(withNameAtDocumentDirectory: name)
    

    Declaration

    Swift

    public init(withNameAtDocumentDirectory name: String, folderName folder: String = Plist.folderName)

    Parameters

    name

    Name of given plist file.

    folder

    Folder inside document directory, if there was not a folder, Plister created a folder with given name

  • Initialize a encrypted value plist object with given name and store plist file inside document directory then you can read and write. If there is a plist which has same name this method only retrive that plist without any change to that file.

    let name = "Wallet"
    let plist = Plist(withNameAtDocumentDirectory: name)
    

    Declaration

    Swift

    public convenience init(withNameAtDocumentDirectory name: String, folderName folder: String = Plist.folderName, encryption: AES)

    Parameters

    name

    Name of given plist file.

    folder

    Folder inside document directory, if there was not a folder, Plister created a folder with given name

    encryption

    an AES object to encrypt and decrypt data.

  • Delete given plist from DocumentDirectory and Deinitialize the object at same time.

    let settings = Plist(withNameAtDocumentDirectory: "Settings")
    Plist.delete(&settings)
    print("Settings: \(settings)")
    // Settings: nil
    

    Declaration

    Swift

    public static func delete(_ plist: inout Plist?)

    Parameters

    plist

    Plist object as a refrence of plist object to remove from memory and document directory

  • Encrypt given value and returns encrypted data

    Takes any argument and convert to String then create a Data object from string, encoding in utf8 and encrypt encoded utf8 to plist encryption algorithm

    Declaration

    Swift

    func encrypt(_ rawValue: Any?) -> Data?

    Parameters

    rawValue

    Takes any argument

  • Decrypt given encrypted data and returns decrypted data

    Declaration

    Swift

    func decrypt(_ data: Data?) -> Data?

    Parameters

    data

    Takes an encrypted data

  • Translate given decrypted data in most accurate performance and returns a Dictionary

    Declaration

    Swift

    func decryptedDictionary(decryptedData rawValue: Any?) -> [String : Any]?

    Parameters

    decryptedData

    Takes a decrypted data

  • Translate given decrypted data in most accurate performance and returns a Collection

    Declaration

    Swift

    func decryptedCollection(decryptedData rawValue: Any?) -> [Any]?

    Parameters

    decryptedData

    Takes a decrypted data

  • Translate given decrypted data in most accurate performance and returns a String

    Declaration

    Swift

    func decryptedString(decryptedData rawValue: Any?) -> String?

    Parameters

    decryptedData

    Takes a decrypted data

  • Translate given decrypted data in most accurate performance and returns a Bool

    Declaration

    Swift

    func decryptedBool(decryptedData rawValue: Any?) -> Bool?

    Parameters

    decryptedData

    Takes a decrypted data

  • Translate given decrypted data in most accurate performance and returns a Int

    Declaration

    Swift

    func decryptedInt(decryptedData rawValue: Any?) -> Int?

    Parameters

    decryptedData

    Takes a decrypted data

  • Translate given decrypted data in most accurate performance and returns a Float

    Declaration

    Swift

    func decryptedFloat(decryptedData rawValue: Any?) -> Float?

    Parameters

    decryptedData

    Takes a decrypted data

  • Translate given decrypted data in most accurate performance and returns a Double

    Declaration

    Swift

    func decryptedDouble(decryptedData rawValue: Any?) -> Double?

    Parameters

    decryptedData

    Takes a decrypted data

  • Translate given decrypted data in most accurate performance and returns a Date

    Declaration

    Swift

    func decryptedDate(decryptedData rawValue: Any?) -> Date?

    Parameters

    decryptedData

    Takes a decrypted data

  • A type representing an error value that wont thrown but raise in debugger

    See more

    Declaration

    Swift

    enum Error
  • Return cached plist as a collection of key value pairs

    Declaration

    Swift

    func asCollection() -> [NSDictionary.Element]

    Return Value

    A Collection of (key,value)

  • Sets the value of the specified key to the specified value.

    If plist encryption enabled, rawValue will encrypted with AES algorithm. and save to plist for given key.

    let plist = Plist(withNameAtDocumentDirectory: "Information")
    let key = "didUserSignedIn"
    plist.set(true, for: key)
    // Sets true value for didUserSignedIn key
    plist.get(key)
    // result will be true
    

    Declaration

    Swift

    func set(_ rawValue: Any?, for key: String)

    Parameters

    rawValue

    The value for the property identified by key.

    key

    The name of one of the receiver’s properties.

  • Returns the value for the property identified by a given key.

    If plist encryption enabled, value for given key is represented as decrypted Data that contains String, for better get use default methods to get value as bool,int,string,float,double,json,collection.

    Declaration

    Swift

    func get(_ key: String) -> Any?

    Parameters

    key

    The name of one of the receiver’s properties.

  • Overwrite a clean dictionary at plist url

    Declaration

    Swift

    func clean()
  • Remove given tuple keys from plist

    Declaration

    Swift

    func remove(_ keys: String...)
  • Remove given collection keys from plist

    Declaration

    Swift

    func remove(keys collection: [String])
  • Returns Bool value for the property identified by a given key.

    Encryption

    If plist encryption enabled, the result will decrypted and translate to Bool type with most accurate performance.

    Declaration

    Swift

    func bool(_ key: String) -> Bool?

    Parameters

    key

    The name of one of the receiver’s properties.

  • Returns Int value for the property identified by a given key.

    Encryption

    If plist encryption enabled, the result will decrypted and translate to Int type with most accurate performance.

    Declaration

    Swift

    func int(_ key: String) -> Int?

    Parameters

    key

    The name of one of the receiver’s properties.

  • Returns Double value for the property identified by a given key.

    Encryption

    If plist encryption enabled, the result will decrypted and translate to Double type with most accurate performance.

    Declaration

    Swift

    func double(_ key: String) -> Double?

    Parameters

    key

    The name of one of the receiver’s properties.

  • Returns Float value for the property identified by a given key.

    Encryption

    If plist encryption enabled, the result will decrypted and translate to Float type with most accurate performance.

    Declaration

    Swift

    func float(_ key: String) -> Float?

    Parameters

    key

    The name of one of the receiver’s properties.

  • Returns String value for the property identified by a given key.

    Encryption

    If plist encryption enabled, the result will decrypted and translate to String type with most accurate performance.

    Declaration

    Swift

    func string(_ key: String) -> String?

    Parameters

    key

    The name of one of the receiver’s properties.

  • Returns Dictionary value for the property identified by a given key.

    Encryption

    If plist encryption enabled, the result will decrypted and translate to Dictionary type with most accurate performance.

    Declaration

    Swift

    func dictionary(_ key: String) -> [String : Any]?

    Parameters

    key

    The name of one of the receiver’s properties.

  • Returns Collection value for the property identified by a given key.

    Encryption

    If plist encryption enabled, the result will decrypted and translate to Collection type with most accurate performance.

    Declaration

    Swift

    func collection(_ key: String) -> [Any]?

    Parameters

    key

    The name of one of the receiver’s properties.

  • Returns Date value for the property identified by a given key.

    Encryption

    If plist encryption enabled, the result will decrypted in TimeInterval format and translate to Date type with most accurate performance.

    Declaration

    Swift

    func date(_ key: String) -> Date?

    Parameters

    key

    The name of one of the receiver’s properties.

  • Returns Data value for the property identified by a given key.

    Encryption

    If plist encryption enabled, the result will decrypted in TimeInterval format and translate to Date type with most accurate performance.

    Declaration

    Swift

    func data(_ key: String) -> Data?

    Parameters

    key

    The name of one of the receiver’s properties.

  • Remove value for given key.

    Declaration

    Swift

    func null(_ key: String)

    Parameters

    key

    The name of one of the receiver’s properties.