Guest User

Untitled

a guest
Feb 24th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. //
  2. // ViewController.swift
  3. // CommonEditor
  4. //
  5. // Created by 莫非 on 2018/2/11.
  6. // Copyright © 2018年 Mofei. All rights reserved.
  7. //
  8.  
  9. import Cocoa
  10.  
  11. class ViewController: NSViewController {
  12.  
  13. override func viewDidLoad() {
  14. super.viewDidLoad()
  15. var map = Map()
  16. map.id = "swift123"
  17. print(map)
  18. let location = NSString(string:"/Users/xxx/unlimitecode/Swift/MapEditor/CommonEditor/lv1.bytes").expandingTildeInPath
  19. let fileContent = try? NSString(contentsOfFile: location, encoding: String.Encoding.utf8.rawValue)
  20. // let binaryData: Data = try! map.serializedData()
  21. print(map)
  22. let docsPath = Bundle.main.resourcePath!
  23. let fileManager = FileManager.default
  24.  
  25. do {
  26. let docsArray = try fileManager.contentsOfDirectory(atPath: docsPath)
  27. print(docsArray)
  28. for item in docsArray{
  29. if item.hasSuffix(".bytes"){
  30. print(item.split(separator: ".")[0])
  31. }
  32. }
  33. } catch {
  34. print(error)
  35. }
  36. if let path = Bundle.main.path(forResource: "lv2", ofType: "bytes") {
  37. do {
  38. let data = try Data(contentsOf: URL(fileURLWithPath: path), options: .mappedIfSafe)
  39. var decodedInfo = try! Map(serializedData: data)
  40. print(decodedInfo)
  41. let mapMirror = Mirror(reflecting: decodedInfo)
  42. for(name,value) in mapMirror.children{
  43. guard let name = name else { continue }
  44. // print("\(name): \(type(of: value)) = '\(value)'")
  45. }
  46. decodedInfo.exclude.append(MapCell())
  47. print(decodedInfo)
  48.  
  49. } catch{
  50.  
  51. }
  52. }
  53.  
  54. // Do any additional setup after loading the view.
  55. }
  56.  
  57. override var representedObject: Any? {
  58. didSet {
  59. // Update the view, if already loaded.
  60. }
  61. }
  62.  
  63.  
  64. }
Add Comment
Please, Sign In to add comment