<commit_before>//
//  KeychainWrapperSubscript.swift
//  SwiftKeychainWrapper
//
//  Created by <NAME> on 5/10/20.
//  Copyright © 2020 <NAME>. All rights reserved.
//

import Foundation

public extension KeychainWrapper {
        
    func remove(forKey key: Key) {
        removeObject(forKey: key.rawValue)
    }
    
}

public extension KeychainWrapper {
    
    subscript(key: Key) -> String? {
        get { return string(forKey: key) }
        set {
            guard let value = newValue else { return }
            set(value, forKey: key.rawValue)
        }
    }

    subscript(key: Key) -> Bool? {
        get { return bool(forKey: key) }
        set {
            guard let value = newValue else { return }
            set(value, forKey: key.rawValue)
        }
    }

    subscript(key: Key) -> Int? {
        get { return integer(forKey: key) }
        set {
            guard let value = newValue else { return }
            set(value, forKey: key.rawValue)
        }
    }

    subscript(key: Key) -> Double? {
        get { return double(forKey: key) }
        set {
            guard let value = newValue else { return }
            set(value, forKey: key.rawValue)
        }
    }

    subscript(key: Key) -> Float? {
        get { return float(forKey: key) }
        set {
            guard let value = newValue else { return }
            set(value, forKey: key.rawValue)
        }
    }

    subscript(key: Key) -> CGFloat? {
        get { return cgFloat(forKey: key) }
        set {
            guard let cgValue = newValue else { return }
            let value = Float(cgValue)
            set(value, forKey: key.rawValue)
        }
    }
    
    subscript(key: Key) -> Data? {
        get { return data(forKey: key) }
        set {
            guard let value = newValue else { return }
            set(value, forKey: key.rawValue)
        }
    }

}


public extension KeychainWrapper {
    
    func data(forKey key: Key) -> Data? {
        if let value = data(forKey: key.rawValue) {
            return value
        }
        return nil
    }

    func bool(forKey key: Key) -> Bool? {
        if let value = bool(forKey: key.rawValue) {
            return value
        }
        
        return nil
    }

    func integer(forKey key: Key) -> Int? {
        if let value = integer(forKey: key.rawValue) {
            return value
        }
        
        return nil
    }

    func float(forKey key: Key) -> Float? {
        if let value = float(forKey: key.rawValue) {
            return value
        }
        
        return nil
    }

    func cgFloat(forKey key: Key) -> CGFloat? {
        if let value = float(forKey: key) {
            return CGFloat(value)
        }
        
        return nil
    }

    func double(forKey key: Key) -> Double? {
        if let value = double(forKey: key.rawValue) {
            return value
        }
        
        return nil
    }

    func string(forKey key: Key) -> String? {
        if let value = string(forKey: key.rawValue) {
            return value
        }
        
        return nil
    }

}


public extension KeychainWrapper {
    
    struct Key: Hashable, RawRepresentable, ExpressibleByStringLiteral {

        public var rawValue: String

        public init(rawValue: String) {
            self.rawValue = rawValue<commit_msg>Add conditional logic for `CGFloat` accessories<commit_after>//
//  KeychainWrapperSubscript.swift
//  SwiftKeychainWrapper
//
//  Created by <NAME> on 5/10/20.
//  Copyright © 2020 <NAME>. All rights reserved.
//

import Foundation

#if canImport(CoreGraphics)
import CoreGraphics
#endif

public extension KeychainWrapper {
        
    func remove(forKey key: Key) {
        removeObject(forKey: key.rawValue)
    }
    
}

public extension KeychainWrapper {
    
    subscript(key: Key) -> String? {
        get { return string(forKey: key) }
        set {
            guard let value = newValue else { return }
            set(value, forKey: key.rawValue)
        }
    }

    subscript(key: Key) -> Bool? {
        get { return bool(forKey: key) }
        set {
            guard let value = newValue else { return }
            set(value, forKey: key.rawValue)
        }
    }

    subscript(key: Key) -> Int? {
        get { return integer(forKey: key) }
        set {
            guard let value = newValue else { return }
            set(value, forKey: key.rawValue)
        }
    }

    subscript(key: Key) -> Double? {
        get { return double(forKey: key) }
        set {
            guard let value = newValue else { return }
            set(value, forKey: key.rawValue)
        }
    }

    subscript(key: Key) -> Float? {
        get { return float(forKey: key) }
        set {
            guard let value = newValue else { return }
            set(value, forKey: key.rawValue)
        }
    }

    #if canImport(CoreGraphics)
    subscript(key: Key) -> CGFloat? {
        get { return cgFloat(forKey: key) }
        set {
            guard let cgValue = newValue else { return }
            let value = Float(cgValue)
            set(value, forKey: key.rawValue)
        }
    }
    #endif
    
    subscript(key: Key) -> Data? {
        get { return data(forKey: key) }
        set {
            guard let value = newValue else { return }
            set(value, forKey: key.rawValue)
        }
    }

}


public extension KeychainWrapper {
    
    func data(forKey key: Key) -> Data? {
        if let value = data(forKey: key.rawValue) {
            return value
        }
        return nil
    }

    func bool(forKey key: Key) -> Bool? {
        if let value = bool(forKey: key.rawValue) {
            return value
        }
        
        return nil
    }

    func integer(forKey key: Key) -> Int? {
        if let value = integer(forKey: key.rawValue) {
            return value
        }
        
        return nil
    }

    func float(forKey key: Key) -> Float? {
        if let value = float(forKey: key.rawValue) {
            return value
        }
        
        return nil
    }

    #if canImport(CoreGraphics)
    func cgFloat(forKey key: Key) -> CGFloat? {
        if let value = float(forKey: key) {
            return CGFloat(value)
        }
        
        return nil
    }
    #endif

    func double(forKey key: Key) -> Double? {
        if let value = double(forKey: key.rawValue) {
            return value
        }
        
        return nil
    }

    func string(forKey key: Key) -> String? {
        if let value = string(forKey: key.rawValue) {
            return value
        }
        
        return nil
    }

}


public extension KeychainWrapper {
    
    struct Key: Hashable, RawRepresentable, ExpressibleByStringLiteral {

        public var rawValue: String

        public init(rawValue: String) {
            self.rawValue = rawValue
{'fraction_non_alphanumeric': 0.09716125256072579, 'fraction_numerical': 0.0026338893766461808, 'mean_word_length': 1.5522778192681106, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 35, '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': '3102064', 'n_tokens_mistral': 2065, 'n_tokens_neox': 2010, 'n_words': 553}