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.
- You can write
- Recently user inserted textfield value.
- You can write
String
value into file named for each textfield and read it.
- You can write
- Structured data without any DB system.
- You can write struct values into file on device and read it.
Usage
Standard values
Int
String
Array (containing writable values)
Dictionary (contaning writable values with string key)
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.
Custom struct
Define writable and readable custom struct
- Define custom struct (named
Sample
in this case). - Conform protocol
CustomReadWriteElement
. - Implement function
static func read
and returnSample
ornil
.
- Apply each parameters with parameter name.
write to file / read from file path
Read and write values by the same way with standard values.
Complex values containing custom struct
You can now write and read complex values containing custom struct.
Read struct with default parameters
Define custom struct with default parameters. You need not to try
if all properties have default values or optional.
Create stored file path
Pencil support to create file path using class Directory
.
Other directories are Applications
, Demos
, Documentation
, Documents
, AutosavedInformation
, Caches
and Downloads
.
Example
License
Pencil is released under the MIT license. See LICENSE for details.