//
//  Foundation+Extend.swift
//  SwiftExtension
//
//  Created by 鍐垚鏋?on 15/6/10.
//  Copyright (c) 2015骞?鍐垚鏋? All rights reserved.
//

import Foundation
import UIKit

/** 瀹忓畾涔?*/

/** BOOL鍊?*/
let YES = true
let NO = false

/** 闆跺尯闂?*/
let RangeIntervalZero = 0..<0


/**  鏂瑰悜瀹氫箟  */
enum Direction {
    
    //涓?    case Top
    
    //宸?    case Left
    
    //涓?    case Bottom
    
    //鍙?    case Right
}

/**  瀵笽nt鎵╁睍  */
extension Int{
    
    var toCGFloat: CGFloat { return CGFloat(self) }
}

/**  瀵笴GFlout鎵╁睍  */
extension CGFloat {
    var toInt: Int { return Int(self) }
}


extension NSObject {
    
    var classNameAsString: String{
        return NSStringFromClass(self.classForCoder).componentsSeparatedByString(".").last!
    }
}


func stringFromClass(cls: AnyClass)->String?{
    
    let string = NSStringFromClass(cls.self).componentsSeparatedByString(".").last
    
    return string
}



/** OC涓嶴wift瀛楀吀涓庢暟缁勪簰杞?*/

/** id杞珼ictionary? */
func objectConvertToDictionay(obj: AnyObject!)->[NSObject: AnyObject]?{
    
    if obj == nil {print("娉ㄦ剰锛歄C鍘熷瓧鍏镐负绌?); return nil}
    
    return obj as? [NSObject: AnyObject]! as Dictionary?
}

/** id杞珹rray? */
func objectConvertToArray(obj: AnyObject!)->[AnyObject]?{
    
    if obj == nil {print("娉ㄦ剰锛歄C鍘熸暟缁勪负绌?); return nil}
    
    return obj as? [AnyObject]! as Array?
}



/** 鎵╁睍鍙绠楃被鍨嬬殑娣峰悎杩愮畻 */
protocol CanCalProtocol{}
extension Int: CanCalProtocol{}
extension Float: CanCalProtocol{}
extension CGFloat: CanCalProtocol{}
extension Double: CanCalProtocol{}

/** + */
func +(left:CanCalProtocol, right:CanCalProtocol) -> Double{
    return CanCalProtocol2Double(left) + CanCalProtocol2Double(right)
}

/** - */
func -(left:CanCalProtocol, right:CanCalProtocol) -> Double{
    return CanCalProtocol2Double(left) - CanCalProtocol2Double(right)
}

/** * */
func *(left:CanCalProtocol, right:CanCalProtocol) -> Double{
    return CanCalProtocol2Double(left) * CanCalProtocol2Double(right)
}

/** / */
func /(left:CanCalProtocol, right:CanCalProtocol) -> Double{
    return CanCalProtocol2Double(left) / CanCalProtocol2Double(right)
}


/** CanCalProtocol楂樼簿搴?*/
func CanCalProtocol2Double(num: CanCalProtocol) -> Double{
    
    if num is Int {return Double(num as! Int)}
    if num is NSInteger {return Double(num as! NSInteger)}
    if num is Float {return Double(num as! Float)}
    if num is CGFloat {return Double(num as! CGFloat)}
    if num is Double {return num as! Double}
    
    return 0
}
// 鐗堟潈灞炰簬鍘熶綔鑰?// 链接已屏蔽
// 鍙戝竷浠g爜浜庢渶涓撲笟鐨勬簮鐮佸垎浜綉绔? Code4App.com