All Projects → rebeloper → SwiftyPlistManager

rebeloper / SwiftyPlistManager

Licence: MIT license
Lightweight plist data management framework for iOS 10.3+

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to SwiftyPlistManager

Universaljavaapplicationstub
universalJavaApplicationStub - an alternative Application launcher script for Java based macOS Apps that works with both Apple's and Oracle's PList format and supports the old Apple Java 6 as well as all the latest Oracle/OpenJDK/Adopt/Corretto JRE's/JDK's. Plus it supports drag&drop to the Dock icon 🎉
Stars: ✭ 174 (+128.95%)
Mutual labels:  apple, plist
Cfpropertylist
PHP Implementation of Apple's PList (binary and xml)
Stars: ✭ 423 (+456.58%)
Mutual labels:  apple, plist
GoogleDriveBrowser
Goole Drive Download Library for iOS
Stars: ✭ 13 (-82.89%)
Mutual labels:  plist
AppleWifiNlpBackend
UnifiedNlp Backend that uses Apple's service to resolve wifi locations. Location calculation is done onboard and wifi locations are cached to minimize data usage.
Stars: ✭ 54 (-28.95%)
Mutual labels:  apple
itunes-api
Java client for iTunes APIs
Stars: ✭ 32 (-57.89%)
Mutual labels:  apple
Plist-Binary sublime
De/Encode .plist files between XML and binary format
Stars: ✭ 18 (-76.32%)
Mutual labels:  plist
xcode-tips.github.io
Community-run website for documenting Xcode Tips
Stars: ✭ 513 (+575%)
Mutual labels:  apple
csv2plist.py
Convert a .csv to .plist array for usage with iOS / OSX app development
Stars: ✭ 29 (-61.84%)
Mutual labels:  plist
ufolint
UFO source format linter
Stars: ✭ 23 (-69.74%)
Mutual labels:  plist
iOS-ARKit
Basic Concepts and Projects using ARKit on iOS.
Stars: ✭ 18 (-76.32%)
Mutual labels:  apple
PDFsuite
Python scripts, Automator Services and Quartz Filters for MacOS (OS X) that create, manipulate, and query PDF files
Stars: ✭ 131 (+72.37%)
Mutual labels:  apple
react-mapkit
React wrapper for Apple's mapkit.js.
Stars: ✭ 71 (-6.58%)
Mutual labels:  apple
apple dep client
Apple Device Enrollment Program Client
Stars: ✭ 22 (-71.05%)
Mutual labels:  apple
FAParser
JSON Parsing + Archiving & Unarchiving in User Defaults
Stars: ✭ 67 (-11.84%)
Mutual labels:  apple
GenericLocalPersistence
GenericLocalPersistence is a clean and easy-to-use code that is useful for integrating local storage like UserDefaults, PList, Keychain.
Stars: ✭ 17 (-77.63%)
Mutual labels:  plist
cook
macOS command line tool to automate common iOS development tasks
Stars: ✭ 50 (-34.21%)
Mutual labels:  apple
Giotto
Theme manager for your app: apply styles to anything you want through a plist file
Stars: ✭ 18 (-76.32%)
Mutual labels:  plist
pinpoint
🌎 A python script for finding your Mac.
Stars: ✭ 56 (-26.32%)
Mutual labels:  apple
OpenCore-EFI
No description or website provided.
Stars: ✭ 65 (-14.47%)
Mutual labels:  apple
Meme-Maker-iOS
Meme Maker open source iOS app made in Swift.
Stars: ✭ 59 (-22.37%)
Mutual labels:  apple

SwiftyPlistManager

License Platform Language Language Cocoapod Twitter

SwiftyPlistManager is a lightweight plist data management framework for iOS 10.3+

Step by step tutorial

I have written a blog post on rebeloper.com with even more info on the usage of SwiftyPlistManager and handy images.

YouTube series on how to use SwiftyPlistManager

Now you can watch my YouTube video series on how to use SwiftyPlistManager here.

Screenshots

Save data Get data Fetch data

Setup

SwiftyPlistManager needs template plist files to use them as the starting point of your data saving and loading. Basically on the first launch of the app it will copy it into it's Document directory and after that you'll be interacting with this copied version of the plist.

Just drag and drop (or create) your plist file(s) into your project. Optionaly you could edit the values to reflect your desired datastructure.

Starting SwiftyPlistManager

IMPORTANT: You always have to "start" SwiftyPlistManager on every launch of your app. Let's assume you have an empty Data.plist file added to your project and you want to log Add the next line of code to your application(_:didFinishLaunchingWithOptions:) function in Appdelegate.swift

SwiftyPlistManager.shared.start(plistNames: ["Data"], logging: true)

Set logging to true if you want to log what's going on under the hood. Optionally, set it to false before release or when you are fed up with too much text in the console.

The plistNames parameter takes in an array of Strings. You may start SwiftyPlistManager with as many plist file names as you'd like.

SwiftyPlistManager.shared.start(plistNames: ["Data", "OtherData"], logging: true)

Usage

Add new value

Before you can interact with any key-value pair you need to add it to your data structure. All types that are supported in plist files are suported. SwiftyPlistManager uses completion handlers so you can know when the operation has completed.

SwiftyPlistManager.shared.addNew("helloNewValue", key: "newKey", toPlistWithName: "Data") { (err) in
  if err == nil {
    print("Value successfully added into plist.")
  }
}

Save value

Next you want to edit your value. You just need to save a new value.

SwiftyPlistManager.shared.save("helloNewValue", forKey: "newKey", toPlistWithName: "Data") { (err) in
  if err == nil {
    print("Value successfully saved into plist.")
  }
}

Get value

If you want to get back the value in a completion handler you'll get back your result as an Any? object.

SwiftyPlistManager.shared.getValue(for: "newKey", fromPlistWithName: "Data") { (result, err) in
  if err == nil {
    print("The Value is: '\(result ?? "No Value Fetched")'")
  }
}

Fetch value

Most of the times you want to cast yor result into a constant right away and not wait for the completion handler to finish. You can use the following call to do just that. For this example we'll unwrap it with a guard-let statement.

guard let fetchedValue = SwiftyPlistManager.shared.fetchValue(for: "newKey", fromPlistWithName: "Data") else { return }

Remove key-value pair

Once in a while you might want to remove a key-value pair.

SwiftyPlistManager.shared.removeKeyValuePair(for: "newKey", fromPlistWithName: "Data") { (err) in
  if err == nil {
    print("Key-Value pair successfully removed from plist")
  }
}

Remove all key-value pairs

Or you might want to delete all the data from your plist file.

SwiftyPlistManager.shared.removeAllKeyValuePairs(fromPlistWithName: "Data") { (err) in
  if err == nil {
    print("Successfully removed all Key-Value pairs from plist")
  }
}

Note: this will not remove the plist from disk. It will just empty it from all the key-value pairs.

Error handling

Let's talk about error-handling. When performing calls with SwiftyPlistManager you get access to possible errors in the completion handlers.

public enum SwiftyPlistManagerError: Error {
  case fileNotWritten
  case fileDoesNotExist
  case fileUnavailable
  case fileAlreadyEmpty
  case keyValuePairAlreadyExists
  case keyValuePairDoesNotExist
}

Installation

CocoaPods

SwiftyPlistManager can be installed as a CocoaPod and builds as a Swift framework. To install, include this in your Podfile.

use_frameworks!

pod 'SwiftyPlistManager'

Once installed, just import SwiftyPlistManager in your classes and you're good to go.

Manualy

Clone or download the repo. Find the SwiftyPlistManager.swift file. Drag and drop it into your project and you're set up.

Swift 3.1

Language Branch Pod version Xcode version
Swift 3.1 master >= 1.0.1 Xcode 8.3 or greater
Swift 4 master >= 1.0.1 Xcode 9 or greater

Change Log

See the Releases Page

Known caveats

  • You can manipulate the plist file only on the root-keys. Nested key-value pairs (like elemnts in a dictionary) cannot be accessed directly. You'll need to get the whole dictionary from the plist, make your changes, than finally save your changed dictionary back into the plist.
  • The actual saving takes place under the hood in the Document directory. Because of this your changes will not be reflected in the plist file you added into your project.

Sample Code

The project includes a demo app for iOS with a sample ViewController.swift showing how to use SwiftyPlistManager.

License

MIT License

Copyright (c) 2017 Alex Nagy

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].