Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ViewController.swift
- // CommonEditor
- //
- // Created by 莫非 on 2018/2/11.
- // Copyright © 2018年 Mofei. All rights reserved.
- //
- import Cocoa
- class ViewController: NSViewController {
- override func viewDidLoad() {
- super.viewDidLoad()
- var map = Map()
- map.id = "swift123"
- print(map)
- let location = NSString(string:"/Users/xxx/unlimitecode/Swift/MapEditor/CommonEditor/lv1.bytes").expandingTildeInPath
- let fileContent = try? NSString(contentsOfFile: location, encoding: String.Encoding.utf8.rawValue)
- // let binaryData: Data = try! map.serializedData()
- print(map)
- let docsPath = Bundle.main.resourcePath!
- let fileManager = FileManager.default
- do {
- let docsArray = try fileManager.contentsOfDirectory(atPath: docsPath)
- print(docsArray)
- for item in docsArray{
- if item.hasSuffix(".bytes"){
- print(item.split(separator: ".")[0])
- }
- }
- } catch {
- print(error)
- }
- if let path = Bundle.main.path(forResource: "lv2", ofType: "bytes") {
- do {
- let data = try Data(contentsOf: URL(fileURLWithPath: path), options: .mappedIfSafe)
- var decodedInfo = try! Map(serializedData: data)
- print(decodedInfo)
- let mapMirror = Mirror(reflecting: decodedInfo)
- for(name,value) in mapMirror.children{
- guard let name = name else { continue }
- // print("\(name): \(type(of: value)) = '\(value)'")
- }
- decodedInfo.exclude.append(MapCell())
- print(decodedInfo)
- } catch{
- }
- }
- // Do any additional setup after loading the view.
- }
- override var representedObject: Any? {
- didSet {
- // Update the view, if already loaded.
- }
- }
- }
Add Comment
Please, Sign In to add comment