How to read from a plist with Swift 3 iOS app

前端 未结 7 1850
無奈伤痛
無奈伤痛 2020-12-24 06:49

-Disclaimer-
I\'m extremely new to iOS and Swift development, but I\'m not particularly new to programming.

I have a basic iOS applicati

相关标签:
7条回答
  • 2020-12-24 07:21

    Here is a Swift 3 implementation, based on Nirav D's answer:

        /// Read Plist File.
        ///
        /// - Parameter fileURL: file URL.
        /// - Returns: return plist content.
        func ReadPlist(_ fileURL: URL) -> [String: Any]? {
            guard fileURL.pathExtension == FileExtension.plist, let data = try? Data(contentsOf: fileURL) else {
                return nil
            }
            guard let result = try? PropertyListSerialization.propertyList(from: data, options: [], format: nil) as? [String: Any] else {
                return nil
            }
            print(result)
            return result
        }
    
    0 讨论(0)
提交回复
热议问题