Giter Site home page Giter Site logo

inifile-swift's Introduction

IniFile-swift

讀寫 INI File 的 Swift 版本

INI 範例檔案

inifile.ini

; 分號開頭是註解
# 這行是無法處理的資料,儲存時依然會保留
; 底下這一組是最上層資料,section 指定為空字串即可處理

key=value

[Section]
key1=value1
key2=value2

[Section2]
key3=value3

CIniFile 使用方法

預設 encoding 為 utf8

let myIni = try CIniFile(fileName = "inifile.ini", encoding = .utf8)

讀取資料

若 section 為空字串,表示讀取最上層無 section 的資料
若讀取失敗,則傳回 defaultVal

let str = myIni.readString(section, key, defaultVal)
let int = myIni.readInt(section, key, defaultVal)
let bool = myIni.readBool(section, key, defaultVal)

設定資料

myIni.writeString(section, key, str)
myIni.writeInt(section, key, int)
myIni.writeBool(section, key, bool)

儲存至原來的檔案

儲存時會儘量依原始資料的順序與保存註解和無法處理的內容

myIni.writeFile()

儲存至指定檔案

myIni.writeFile("newinifile.ini")

注意:

布林值以下為真
1, yes, on, true
以下為假
0, no, off, false
其他則視為無法判斷。
以上不區別大小寫,不過寫入時,請以這二個變數為主
defaultBoolTrue, defaultBoolFalse
但這只用在執行時有修改的布林值,不影響原始資料。
也就是若原本是寫
key=yes
若 key 沒有修改,則不會變成 0 或 1 (依變數設定),依然是 yes

inifile-swift's People

Contributors

heavenchou avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.