<commit_before>//
//  DataModel.swift
//  Checklists
//
//  Created by <NAME> on 28.12.15.
//  Copyright © 2015 Closure One. All rights reserved.
//

import Foundation

class DataModel {
  var checklists = [Checklist]()
  
  var indexOfSelectedChecklist: Int {
    
    get {
      return NSUserDefaults.standardUserDefaults().integerForKey("ChecklistIndex")
    }
    
    set {
      NSUserDefaults.standardUserDefaults().setInteger(newValue, forKey: "ChecklistIndex")
    }
    
    
  }
  
  init() {
    print("Data file path is \(dataFilePath())")
    loadChecklists()
    registerDefaults()
  }
  
  // MARK: File related
  func documentsDirectory() -> String {
    let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
    return paths[0]
  }
  
  func dataFilePath() -> String {
    return (documentsDirectory() as NSString).stringByAppendingPathComponent("Checklists.plist")
  }
  
  func saveChecklists() {
    let data = NSMutableData()
    let archiver = NSKeyedArchiver(forWritingWithMutableData: data)
    archiver.encodeObject(checklists, forKey: "Checklists")
    archiver.finishEncoding()
    data.writeToFile(dataFilePath(), atomically: true)
  }
  
  func loadChecklists() {
    let path = dataFilePath()<commit_msg>Putting handle first time to init.<commit_after>//
//  DataModel.swift
//  Checklists
//
//  Created by <NAME> on 28.12.15.
//  Copyright © 2015 Closure One. All rights reserved.
//

import Foundation

class DataModel {
  var checklists = [Checklist]()
  
  var indexOfSelectedChecklist: Int {
    
    get {
      return NSUserDefaults.standardUserDefaults().integerForKey("ChecklistIndex")
    }
    
    set {
      NSUserDefaults.standardUserDefaults().setInteger(newValue, forKey: "ChecklistIndex")
    }
    
    
  }
  
  init() {
    print("Data file path is \(dataFilePath())")
    loadChecklists()
    registerDefaults()
    handleFirstTimeAppStart()
  }
  
  // MARK: File related
  func documentsDirectory() -> String {
    let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
    return paths[0]
  }
  
  func dataFilePath() -> String {
    return (documentsDirectory() as NSString).stringByAppendingPathComponent("Checklists.plist")
  }
  
  func saveChecklists() {
    let data = NSMutableData()
    let archiver = NSKeyedArchiver(forWritingWithMutableData: data)
    archiver.encodeObject(checklists, forKey: "Checklists")
    archiver.finishEncoding()
    data.writeToFile(dataFilePath(), atomically: true)
  }
  
  func loadChecklists() {
    let path = dataFilePath()
{'fraction_non_alphanumeric': 0.1105121293800539, 'fraction_numerical': 0.008471313053523296, 'mean_word_length': 3.3444816053511706, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '363740', 'n_tokens_mistral': 827, 'n_tokens_neox': 778, 'n_words': 169}