トップ 最新 追記

Cocoa練習帳

iOS/iPhone/iPad/watchOS/tvOS/MacOSX/Android プログラミング, Objective-C, Cocoa, Swiftなど

2012|01|02|03|04|05|06|07|08|09|10|11|12|
2013|01|02|03|04|05|06|07|08|09|10|11|12|
2014|01|02|03|04|05|06|07|08|09|10|11|12|
2015|01|02|03|04|05|06|07|08|09|10|11|12|
2016|01|02|03|04|05|06|07|08|09|10|11|12|
2017|01|02|03|04|05|06|07|08|09|10|11|12|
2018|01|02|03|04|05|06|07|08|09|10|11|12|
2019|01|02|03|04|05|06|07|08|09|10|11|12|
2020|01|02|03|04|05|06|07|08|09|10|11|12|
2021|01|02|03|04|05|06|07|08|09|10|11|12|
2022|01|02|03|04|05|06|07|08|09|10|11|12|
2023|01|02|03|04|05|06|07|08|09|10|11|12|
2024|01|02|

2017-09-03 [macOS]Day One Classic 書類

Day One Classicという日記アプリを使っているが、今後のことを考えて、自家製アプリに移行することを考えている。

Day Oneの同期データの種類は、以下のとおり。

  • Day One
    独自サーバ。
  • iCloud
    
 探せばデータを見つけることは出来るが、見えないと考えるべきか。
    
 ~/Library/Mobile Documents/*~com~dayoneapp~dayone/Documents/Journal_dayone
  • Dropbox
    
 データは見える場所。
    
 ~/Dropbox/アプリ/Day\ One/Journal.dayone

Dropboxでのディレクトリ構成は以下のとおり

Day One
 +- Journal.dayone
    +- entries
    |    1A573C0B559248A991C4AC0F0EA8B1E7.doentry
    |    1FB23D983DF341079532B0F9381BCFCC.doentry
    |    :
    +- photos
         1A573C0B559248A991C4AC0F0EA8B1E7.jpg
         2D37E853754E43EFBA0FFBAEEB6A8B40.jpg
         :

entries配下のファイルは、plistのよう。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Activity</key>
	<string>Automotive</string>
	<key>Creation Date</key>
	<date>2016-07-18T08:51:34Z</date>
	<key>Creator</key>
	<dict>
		<key>Device Agent</key>
		<string>iPhone/iPhone7,2</string>
		<key>Generation Date</key>
		<date>2016-07-18T08:51:34Z</date>
		<key>Host Name</key>
		<string>iPhone6GB128Gold</string>
		<key>OS Agent</key>
		<string>iOS/9.3.2</string>
		<key>Software Agent</key>
		<string>Day One iOS/1.17.9</string>
	</dict>
	<key>Entry Text</key>
	<string>AT教習のゼッケン
下で待つ。準備なし</string>
:

この内容を読み取るコードを書いてみた。保存先を選択する。

    @IBAction func buttonPushed(sender: AnyObject) {
        let openPanel = NSOpenPanel()
        openPanel.allowsMultipleSelection = false
        openPanel.canChooseDirectories = true
        openPanel.canCreateDirectories = false
        openPanel.canChooseFiles = false
        openPanel.begin { (result) -> Void in
            if result == NSFileHandlingPanelOKButton {
                let inst = KeepADiary()
                inst.dump(url: openPanel.urls[0])
            }
        }
    }

内容をダンプ。

class KeepADiary {
    public func dump(url: URL) -> Void {
        print(url)
        var entriesUrl = url
        entriesUrl.appendPathComponent("entries", isDirectory: true)
        print(entriesUrl)
        var fileList: [String] {
            do {
                return try FileManager.default.contentsOfDirectory(atPath: entriesUrl.path)
            } catch {
                return []
            }
        }
        for fileName in fileList {
            var fileUrl = entriesUrl
            fileUrl.appendPathComponent(fileName)
            let plistXML: NSData = FileManager.default.contents(atPath: fileUrl.path)! as NSData
            let temp = try! PropertyListSerialization.propertyList(from:plistXML as Data, options: [], format: nil) as! [String:Any]
            print(temp)
        }
    }
}

_ ソースコード

GitHubからどうぞ。
https://github.com/murakami/KeepADiary - GitHub

_ 【Cocoa練習帳】

http://www.bitz.co.jp/weblog/
http://ameblo.jp/bitz/(ミラー・サイト)

トップ 最新 追記