 
 public func NonEmptyString(optionalValue: String?, trimWhitespace: Bool = true) -> String? {
     if let value = optionalValue {
-        let trimmedValue: String = (trimWhitespace ? value.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()) : value);
+        let trimmedValue: String = (trimWhitespace ? value.trimmingCharacters(in: NSCharacterSet.whitespaceAndNewline()) : value);
         if trimmedValue.isEmpty {
             return nil
         } else {

        } else if let v = value as? Int {
            return v != 0
        } else if let v = value as? String {
            let u = v.uppercaseString
            if (u == "YES" || u == "TRUE" || u == "ON" || u == "Y" || u == "1") {
                return true
            } else if (u == "NO" || u == "FALSE" || u == "OFF" || u == "N" || u == "0") {

        } else if let v = value as? String {
            let scanner = NSScanner(string: v)
            var num: Double = 0.0
            if scanner.scanDouble(&num) && scanner.isAtEnd {
                return num
            } else {
                return nil
