Swift将Plist(在NSString内)转换为NSDictionary

时间:2015-06-07 03:19:55

标签: swift nsstring nsdictionary

你好我有一个包含Plist数据的NSString。我需要将其转换为NSDictionary。我已经找到了用文件做的方法,但我想直接在内存中进行。我怎么能用swift做到这一点?谢谢你的帮助。

2 个答案:

答案 0 :(得分:0)

var plist : NSMutableDictionary
let nsDocumentDirectory = NSSearchPathDirectory.DocumentDirectory
let nsUserDomainMask = NSSearchPathDomainMask.UserDomainMask
if let paths = NSSearchPathForDirectoriesInDomains(nsDocumentDirectory, nsUserDomainMask, true) {
    if paths.count > 0 {
        if let dirPath = paths[0] as? String {
            let readPath = dirPath.stringByAppendingPathComponent("info.plist")
            plist = NSMutableDictionary(contentsOfFile: readPath)!
            println(plist)
        }
    }
}

答案 1 :(得分:0)

经过大量的咕噜声和玩耍后,我遇到了

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.webtemplum.hq60" >

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".LoginActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

以防万一其他人碰巧遇到我的情况。