All Projects → naru-jpn → Pencil

naru-jpn / Pencil

Licence: mit
Super lightweight DB written in Swift.

Programming Languages

swift
15916 projects
enum
40 projects

Labels

Projects that are alternatives of or similar to Pencil

Css3colorsswift
A UIColor extension with CSS3 Color names.
Stars: ✭ 62 (-24.39%)
Mutual labels:  carthage
Sheeeeeeeeet
Sheeeeeeeeet is a Swift library for creating menus, custom action sheets, context menus etc.
Stars: ✭ 1,177 (+1335.37%)
Mutual labels:  carthage
Swiftlinkpreview
It makes a preview from an URL, grabbing all the information such as title, relevant texts and images.
Stars: ✭ 1,216 (+1382.93%)
Mutual labels:  carthage
Cameramanager
Simple Swift class to provide all the configurations you need to create custom camera view in your app
Stars: ✭ 1,130 (+1278.05%)
Mutual labels:  carthage
Popmenu
A fully customizable popup style menu for iOS 😎
Stars: ✭ 1,155 (+1308.54%)
Mutual labels:  carthage
Ctshowcase
A simple to use Showcase library that can highlight arbitrary views in an iOS app
Stars: ✭ 73 (-10.98%)
Mutual labels:  carthage
Peep
Easy Sound Generator 🐥
Stars: ✭ 59 (-28.05%)
Mutual labels:  carthage
Hover
🎈 The smartest floating button
Stars: ✭ 81 (-1.22%)
Mutual labels:  carthage
Corenavigation
📱📲 Navigate between view controllers with ease. 💫 🔜 More stable version (written in Swift 5) coming soon.
Stars: ✭ 69 (-15.85%)
Mutual labels:  carthage
Spasibo
🙏 Support your favourite open source projects
Stars: ✭ 78 (-4.88%)
Mutual labels:  carthage
Cluster
Easy Map Annotation Clustering 📍
Stars: ✭ 1,132 (+1280.49%)
Mutual labels:  carthage
Memorycache
LRU, type-safe, thread-safe memory cache class in Swift
Stars: ✭ 66 (-19.51%)
Mutual labels:  carthage
Notificationz
📡 Helping you own NotificationCenter in Swift!
Stars: ✭ 74 (-9.76%)
Mutual labels:  carthage
Transitionbutton
UIButton sublass for loading and transition animation.
Stars: ✭ 1,124 (+1270.73%)
Mutual labels:  carthage
Soundable
Soundable allows you to play sounds, single and in sequence, in a very easy way
Stars: ✭ 78 (-4.88%)
Mutual labels:  carthage
Pinpointkit
Send better feedback
Stars: ✭ 1,115 (+1259.76%)
Mutual labels:  carthage
Loadingshimmer
An easy way to add a shimmering effect to any view with just one line of code. It is useful as an unobtrusive loading indicator.
Stars: ✭ 1,180 (+1339.02%)
Mutual labels:  carthage
Hdwallet
Simple Swift library for creating HD cryptocurrencies wallets and working with crypto Coins/ERC20 tokens.
Stars: ✭ 80 (-2.44%)
Mutual labels:  carthage
Silentscrolly
Scroll to hide navigationBar, tabBar and toolBar.
Stars: ✭ 79 (-3.66%)
Mutual labels:  carthage
Dikit
Dependency Injection Framework for Swift, inspired by KOIN.
Stars: ✭ 77 (-6.1%)
Mutual labels:  carthage

pencil_logo

platform-ios carthage-compatible cocoapods-compatible swift-3.0 MIT

Use of value types is recommended and we define standard values, simple structured data, application state and etc. as struct or enum. Pencil makes us store these values more easily.

Installation

Carthage

github "naru-jpn/Pencil"

CocoaPods

pod 'pencil'

Swift Package Manager

Compatible.

Manually

Copy all *.swift files contained in Sources directory into your project.

Recommeded / Example

  • Application state such as tab index application selected at last time.
    • You can write Int value into file on device and read it.
  • Recently user inserted textfield value.
    • You can write String value into file named for each textfield and read it.
  • Structured data without any DB system.
    • You can write struct values into file on device and read it.

Usage

Standard values

Int

// (create stored url)
guard let storedURL = Directory.Documents?.append(path: "int.data") else {
  return
}

let num: Int = 2016

// write
num.write(to: storedURL)

// ...

// read
let stored: Int? = Int.value(from: storedURL)

String

let text: String = "Pencil store value easily."
text.write(to: storedURL)

// ...

let stored: String? = String.value(from: storedURL)

Array (containing writable values)

let nums: [Int] = [2016, 11, 28]
nums.write(to: storedURL)

// ...

let stored: [Int]? = [Int].value(from: storedURL)

Dictionary (contaning writable values with string key)

let dictionary: [String: Int] = ["year": 2016, "month": 11, "day": 28]
dictionary.write(to: storedURL)

// ...

let stored: [String: Int]? = [String: Int].value(from: url)

Other standard writable and readable values are Set, Bool, Float, Double, Date, Int8, Int16, Int32, Int64, UInt, UInt8, UInt16, UInt32 and UInt64.

Enum

Define writable and readable enum

Type of raw value should conform ReadWriteElement and add ReadWriteElement for enum.

enum Sample: Int, ReadWriteElement {
  case one = 1
  case two = 2
}

write to file / read from file path

Read and write values by the same way with standard values.

let sample: Sample = .two
sample.write(to: storedURL)

// ...

let stored: Sample? = Sample.value(from: url)

Custom struct

Define writable and readable custom struct

  1. Define custom struct (named Sample in this case).
  2. Conform protocol CustomReadWriteElement.
  3. Implement function static func read and return Sample or nil.
  • Apply each parameters with parameter name.
struct Sample: CustomReadWriteElement {
    
  let dictionary: [String: Int]
  let array: [Int]?
  let identifier: String
    
  static func read(components: Components) -> Sample? {
    do {
      return try Sample(
        dictionary: components.component(for: "dictionary"),
        array:      components.component(for: "array"),
        identifier: components.component(for: "identifier")
      )
    } catch {
      return nil
    }
  }
}

write to file / read from file path

Read and write values by the same way with standard values.

let sample: Sample = Sample(dictionary: ["one": 2, "two": 5], array: [2, 3], identifier: "abc123")
sample.write(to: storedURL)

// ...

let stored: Sample? = Sample.value(from: url)

Complex values containing custom struct

You can now write and read complex values containing custom struct.

let sample: Sample = Sample(dictionary: ["one": 2, "two": 5], array: [2, 3], identifier: "abc123")
let samples: [Samples] = [sample, sample, sample]
samples.write(to: storedURL)

// ...

let stored: [Sample]? = [Sample].value(from: url)

Read struct with default parameters

Define custom struct with default parameters. You need not to try if all properties have default values or optional.

struct Sample: CustomReadWriteElement {
    
    let dictionary: [String: Int]
    let array: [Int]?
    let identifier: String
    
    static func read(components: Components) -> Sample? {      
        return Sample(
            dictionary: components.component(for: "dictionary", defaultValue: ["default": 100]),
            array:      components.component(for: "array"),
            identifier: components.component(for: "identifier", defaultValue: "default")
        )
    }
}

Create stored file path

Pencil support to create file path using class Directory.

// Create path ~/Documents/pencil.data
let url: URL? = Directory.Documents?.append(path: "pencil.data")

Other directories are Applications, Demos, Documentation, Documents, AutosavedInformation, Caches and Downloads.

Example

PencilExample

License

Pencil is released under the MIT license. See LICENSE for details.

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].