{"id":1034,"url":"https://github.com/naru-jpn/pencil","last_synced_at":"2026-03-06T17:03:53.882Z","repository":{"id":56932957,"uuid":"70461738","full_name":"naru-jpn/pencil","owner":"naru-jpn","description":"Super lightweight DB written in Swift.","archived":false,"fork":false,"pushed_at":"2018-02-25T14:04:24.000Z","size":895,"stargazers_count":90,"open_issues_count":0,"forks_count":7,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-12-09T14:39:59.185Z","etag":null,"topics":["carthage","coccoapods","complex-values","enum","pencil","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/naru-jpn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-10T07:13:49.000Z","updated_at":"2024-01-10T07:38:03.000Z","dependencies_parsed_at":"2022-08-21T05:20:44.231Z","dependency_job_id":null,"html_url":"https://github.com/naru-jpn/pencil","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/naru-jpn/pencil","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naru-jpn%2Fpencil","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naru-jpn%2Fpencil/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naru-jpn%2Fpencil/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naru-jpn%2Fpencil/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/naru-jpn","download_url":"https://codeload.github.com/naru-jpn/pencil/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naru-jpn%2Fpencil/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30186780,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-06T14:42:24.748Z","status":"ssl_error","status_checked_at":"2026-03-06T14:42:14.925Z","response_time":250,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["carthage","coccoapods","complex-values","enum","pencil","swift"],"created_at":"2024-01-05T20:15:37.514Z","updated_at":"2026-03-06T17:03:53.857Z","avatar_url":"https://github.com/naru-jpn.png","language":"Swift","funding_links":[],"categories":["Data Structures / Algorithms","Libs","Data Management [🔝](#readme)"],"sub_categories":["Getting Started","Data Management","Other free courses","Linter"],"readme":"\u003c!--# Pencil--\u003e\n\n\u003cp align=\"center\"\u003e\u003cimg src=\"./pencil.png\" width=\"170\" alt=\"pencil_logo\" /\u003e\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\u003cimg src=\"https://img.shields.io/badge/Platform-iOS-blue.svg\" alt=\"platform-ios\" /\u003e \u003cimg src=\"https://img.shields.io/badge/Carthage-compatible-brightgreen.svg\" alt=\"carthage-compatible\" /\u003e \u003cimg src=\"https://img.shields.io/badge/Pod-0.0.7-blue.svg\" alt=\"cocoapods-compatible\" /\u003e \u003cimg src=\"https://img.shields.io/badge/Swift-3.0-orange.svg\" alt=\"swift-3.0\" /\u003e \u003cimg src=\"https://img.shields.io/badge/License-MIT-lightgrey.svg\" alt=\"MIT\" /\u003e\u003c/p\u003e\n\n\u003c!--\n\u003cp align=\"center\"\u003eWrite any value to file.\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\u003cimg src=\"./pencil.png\" width=\"150\" alt=\"pencil_logo\" /\u003e\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\u003cimg src=\"https://img.shields.io/badge/Platform-iOS-blue.svg\" alt=\"platform-ios\" /\u003e \u003cimg src=\"https://img.shields.io/badge/Carthage-compatible-brightgreen.svg\" alt=\"carthage-compatible\" /\u003e \u003cimg src=\"https://img.shields.io/badge/Pod-0.0.7-blue.svg\" alt=\"cocoapods-compatible\" /\u003e \u003cimg src=\"https://img.shields.io/badge/Swift-3.0-orange.svg\" alt=\"swift-3.0\" /\u003e \u003cimg src=\"https://img.shields.io/badge/License-MIT-lightgrey.svg\" alt=\"MIT\" /\u003e\u003c/p\u003e\n--\u003e\n\nUse of value types is recommended and we define standard values, simple structured data, application state and etc. as struct or enum. \nPencil makes us store these values more easily.\n\n## Installation\n\n__Carthage__\n\n```\ngithub \"naru-jpn/Pencil\"\n```\n\n__CocoaPods__\n\n```\npod 'pencil'\n```\n\n__Swift Package Manager__\n\nCompatible.\n\n__Manually__\n\nCopy all `*.swift` files contained in `Sources` directory into your project. \n\n## Recommeded / Example\n- __Application state such as tab index application selected at last time.__\n  - You can write `Int` value into file on device and read it.\n- __Recently user inserted textfield value.__\n  - You can write `String` value into file named for each textfield and read it.\n- __Structured data without any DB system.__\n  - You can write struct values into file on device and read it.\n\n## Usage\n\n### Standard values\n\n#### Int\n\n```swift\n// (create stored url)\nguard let storedURL = Directory.Documents?.append(path: \"int.data\") else {\n  return\n}\n\nlet num: Int = 2016\n\n// write\nnum.write(to: storedURL)\n\n// ...\n\n// read\nlet stored: Int? = Int.value(from: storedURL)\n```\n\n#### String\n\n```swift\nlet text: String = \"Pencil store value easily.\"\ntext.write(to: storedURL)\n\n// ...\n\nlet stored: String? = String.value(from: storedURL)\n```\n\n#### Array (containing writable values)\n\n```swift\nlet nums: [Int] = [2016, 11, 28]\nnums.write(to: storedURL)\n\n// ...\n\nlet stored: [Int]? = [Int].value(from: storedURL)\n```\n\n#### Dictionary (contaning writable values with string key)\n\n```swift\nlet dictionary: [String: Int] = [\"year\": 2016, \"month\": 11, \"day\": 28]\ndictionary.write(to: storedURL)\n\n// ...\n\nlet stored: [String: Int]? = [String: Int].value(from: url)\n```\n\nOther standard writable and readable values are `Set`, `Bool`, `Float`, `Double`, `Date`, `Int8`, `Int16`, `Int32`, `Int64`, `UInt`, `UInt8`, `UInt16`, `UInt32` and `UInt64`.\n\n### Enum\n\n#### Define writable and readable enum\n\nType of raw value should conform `ReadWriteElement` and add `ReadWriteElement` for enum.\n\n```\nenum Sample: Int, ReadWriteElement {\n  case one = 1\n  case two = 2\n}\n```\n\n#### write to file / read from file path\n\nRead and write values by the same way with standard values.\n\n```swift\nlet sample: Sample = .two\nsample.write(to: storedURL)\n\n// ...\n\nlet stored: Sample? = Sample.value(from: url)\n```\n\n### Custom struct\n\n#### Define writable and readable custom struct\n\n1. Define custom struct (named `Sample` in this case).\n1. Conform protocol `CustomReadWriteElement`.\n1. Implement function `static func read` and return `Sample` or `nil`.\n  - Apply each parameters with parameter name.\n\n```swift\nstruct Sample: CustomReadWriteElement {\n    \n  let dictionary: [String: Int]\n  let array: [Int]?\n  let identifier: String\n    \n  static func read(components: Components) -\u003e Sample? {\n    do {\n      return try Sample(\n        dictionary: components.component(for: \"dictionary\"),\n        array:      components.component(for: \"array\"),\n        identifier: components.component(for: \"identifier\")\n      )\n    } catch {\n      return nil\n    }\n  }\n}\n```\n\n#### write to file / read from file path\n\nRead and write values by the same way with standard values.\n\n```swift\nlet sample: Sample = Sample(dictionary: [\"one\": 2, \"two\": 5], array: [2, 3], identifier: \"abc123\")\nsample.write(to: storedURL)\n\n// ...\n\nlet stored: Sample? = Sample.value(from: url)\n```\n\n#### Complex values containing custom struct\n\nYou can now write and read complex values containing custom struct.\n\n```swift\nlet sample: Sample = Sample(dictionary: [\"one\": 2, \"two\": 5], array: [2, 3], identifier: \"abc123\")\nlet samples: [Samples] = [sample, sample, sample]\nsamples.write(to: storedURL)\n\n// ...\n\nlet stored: [Sample]? = [Sample].value(from: url)\n```\n\n#### Read struct with default parameters\n\nDefine custom struct with default parameters. You need not to `try` if all properties have default values or optional.\n\n```swift\nstruct Sample: CustomReadWriteElement {\n    \n    let dictionary: [String: Int]\n    let array: [Int]?\n    let identifier: String\n    \n    static func read(components: Components) -\u003e Sample? {      \n        return Sample(\n            dictionary: components.component(for: \"dictionary\", defaultValue: [\"default\": 100]),\n            array:      components.component(for: \"array\"),\n            identifier: components.component(for: \"identifier\", defaultValue: \"default\")\n        )\n    }\n}\n```\n\n### Create stored file path\n\nPencil support to create file path using class `Directory`.\n\n```swift\n// Create path ~/Documents/pencil.data\nlet url: URL? = Directory.Documents?.append(path: \"pencil.data\")\n```\n\nOther directories are `Applications`, `Demos`, `Documentation`, `Documents`, `AutosavedInformation`, `Caches` and `Downloads`.\n\n## Example\n\n[PencilExample](https://github.com/naru-jpn/pencil/tree/master/Example)\n\n## License\n\nPencil is released under the MIT license. See LICENSE for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnaru-jpn%2Fpencil","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnaru-jpn%2Fpencil","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnaru-jpn%2Fpencil/lists"}