 
 import UIKit
 
-public func plistGet(key:String, forPlistNamed:String) throws -> AnyObject{
+enum NRSimplePlistError: ErrorType {
+    case Fatal(String)
+}
+
+func plistGet(key:String, forPlistNamed:String) throws -> AnyObject? {
     let formats: UnsafeMutablePointer<NSPropertyListFormat> = UnsafeMutablePointer()
-    
-    var array:NSArray = NSArray()
-    var tipo:AnyObject = ""
-    
-    enum NRSimplePlistError: ErrorType {
-        case Fatal(String)
-    }
-    
-    
+
     if let path:String = NSBundle.mainBundle().pathForResource(forPlistNamed, ofType: "plist"){
         
         if let plistData = NSData(contentsOfFile: path) {
             
             //var plist = NSPropertyListSerialization.propertyListWithData(plistData, options: 0, format: formats, error: &error) as NSDictionary
-            
             do {
-                let plist = try NSPropertyListSerialization.propertyListWithData(plistData, options: NSPropertyListReadOptions.Immutable, format: formats) as! NSDictionary
-                
+                let plist = try NSPropertyListSerialization.propertyListWithData(plistData, options: .Immutable, format: formats) as! NSDictionary
+    
                 if (path=="") {
                     NSLog("NRSimplePlist - Errore LETTURA file plist '\(path)'")
                     NSLog("NRSimplePlist - Error READING plist file '\(path)'")
                     
                     throw NRSimplePlistError.Fatal("NRSimplePlist - Error READING plist file '\(path)'")
                 }
+            
+                if let tipo = plist.valueForKey(key) {
+                    return tipo
+                }
+            } catch let error1 as NSError {
+                NSLog("NRSimplePlist - Errore LETTURA file plist '\(path)', errore = '\(error1.localizedDescription)'")
+                NSLog("NRSimplePlist - Error READING plist file '\(path)', error = '\(error1.localizedDescription)'")
                 
-                tipo = plist.valueForKey(key)!
-                    
-                return tipo
+                throw error1
+            } catch {
+                NSLog("NRSimplePlist - Errore LETTURA file plist '\(path)'")
+                NSLog("NRSimplePlist - Error READING plist file '\(path)',")
                 
-            } catch let error1 as NSError {
-                NSLog("NRSimplePlist - Errore LETTURA file plist '\(path)'")
-                NSLog("NRSimplePlist - Error READING plist file '\(path)'")
-
-                throw error1
+                throw NRSimplePlistError.Fatal("NRSimplePlist - Error READING plist property")
             }
+            return nil
             
         }
         

            
            if let plistData = NSData(contentsOfFile: path as String) {
                
                
                do {
                    let plist = try NSPropertyListSerialization.propertyListWithData(plistData, options: NSPropertyListReadOptions.Immutable, format: formats) as! NSDictionary
                    
                    array = plist.mutableCopy() as! NSMutableDictionary
                    
                    array.setObject(newValue, forKey: forKey)
                    array.writeToFile(path as String, atomically: true)
                    
                } catch let error1 as NSError {
                    NSLog("NRSimplePlist - Errore LETTURA file plist '\(path)'")
                    NSLog("NRSimplePlist - Error READING plist file '\(path)'")
                    
                    throw error1
                }
  
            }
            
        } else {

        print("File '\(forPlistNamed)' not found")
    }
    
    return nil
}

func plistSet(newValue:AnyObject, forKey:String, inPlistNamed:String) throws {
    let formats: UnsafeMutablePointer<NSPropertyListFormat> = UnsafeMutablePointer()
    
    var array:NSMutableDictionary = NSMutableDictionary()
