swift swift中的“NSURL == String url”扩展名

swift中的“NSURL == String url”扩展名

isEquivalent.swift
extension NSURL {
	
	/**
	Check if the url:String is equivalent to NSURL
	:param: url to compare me
	:returns: true if is the same false otherwise
	*/
	func isEquivalent(url: String) -> Bool {
		
		if let myUrl = absoluteString {
			let urlComponents = url.componentsSeparatedByString("?")
			let myUrlComponents = myUrl.componentsSeparatedByString("?")
				return urlComponents.first == myUrlComponents.first
		}
		
		return true
	}
	
}

swift swift中的“NSURL == String url”扩展名

swift中的“NSURL == String url”扩展名

isEquivalent.swift
extension NSURL {
	
	/**
	Check if the url:String is equivalent to NSURL
	:param: url to compare me
	:returns: true if is the same false otherwise
	*/
	func isEquivalent(url: String) -> Bool {
		
		if let myUrl = absoluteString {
			let urlComponents = url.componentsSeparatedByString("?")
			let myUrlComponents = myUrl.componentsSeparatedByString("?")
				return urlComponents.first == myUrlComponents.first
		}
		
		return true
	}
	
}

swift swift中的“NSURL == String url”扩展名

swift中的“NSURL == String url”扩展名

isEquivalent.swift
extension NSURL {
	
	/**
	Check if the url:String is equivalent to NSURL
	:param: url to compare me
	:returns: true if is the same false otherwise
	*/
	func isEquivalent(url: String) -> Bool {
		
		if let myUrl = absoluteString {
			let urlComponents = url.componentsSeparatedByString("?")
			let myUrlComponents = myUrl.componentsSeparatedByString("?")
				return urlComponents.first == myUrlComponents.first
		}
		
		return true
	}
	
}

swift swift中的“NSURL == String url”扩展名

swift中的“NSURL == String url”扩展名

isEquivalent.swift
extension NSURL {
	
	/**
	Check if the url:String is equivalent to NSURL
	:param: url to compare me
	:returns: true if is the same false otherwise
	*/
	func isEquivalent(url: String) -> Bool {
		
		if let myUrl = absoluteString {
			let urlComponents = url.componentsSeparatedByString("?")
			let myUrlComponents = myUrl.componentsSeparatedByString("?")
				return urlComponents.first == myUrlComponents.first
		}
		
		return true
	}
	
}

swift swift中的“NSURL == String url”扩展名

swift中的“NSURL == String url”扩展名

isEquivalent.swift
extension NSURL {
	
	/**
	Check if the url:String is equivalent to NSURL
	:param: url to compare me
	:returns: true if is the same false otherwise
	*/
	func isEquivalent(url: String) -> Bool {
		
		if let myUrl = absoluteString {
			let urlComponents = url.componentsSeparatedByString("?")
			let myUrlComponents = myUrl.componentsSeparatedByString("?")
				return urlComponents.first == myUrlComponents.first
		}
		
		return true
	}
	
}

swift swift中的“NSURL == String url”扩展名

swift中的“NSURL == String url”扩展名

isEquivalent.swift
extension NSURL {
	
	/**
	Check if the url:String is equivalent to NSURL
	:param: url to compare me
	:returns: true if is the same false otherwise
	*/
	func isEquivalent(url: String) -> Bool {
		
		if let myUrl = absoluteString {
			let urlComponents = url.componentsSeparatedByString("?")
			let myUrlComponents = myUrl.componentsSeparatedByString("?")
				return urlComponents.first == myUrlComponents.first
		}
		
		return true
	}
	
}

swift swift中的“NSURL == String url”扩展名

swift中的“NSURL == String url”扩展名

isEquivalent.swift
extension NSURL {
	
	/**
	Check if the url:String is equivalent to NSURL
	:param: url to compare me
	:returns: true if is the same false otherwise
	*/
	func isEquivalent(url: String) -> Bool {
		
		if let myUrl = absoluteString {
			let urlComponents = url.componentsSeparatedByString("?")
			let myUrlComponents = myUrl.componentsSeparatedByString("?")
				return urlComponents.first == myUrlComponents.first
		}
		
		return true
	}
	
}

swift swift中的“NSURL == String url”扩展名

swift中的“NSURL == String url”扩展名

isEquivalent.swift
extension NSURL {
	
	/**
	Check if the url:String is equivalent to NSURL
	:param: url to compare me
	:returns: true if is the same false otherwise
	*/
	func isEquivalent(url: String) -> Bool {
		
		if let myUrl = absoluteString {
			let urlComponents = url.componentsSeparatedByString("?")
			let myUrlComponents = myUrl.componentsSeparatedByString("?")
				return urlComponents.first == myUrlComponents.first
		}
		
		return true
	}
	
}

swift swift中的“NSURL == String url”扩展名

swift中的“NSURL == String url”扩展名

isEquivalent.swift
extension NSURL {
	
	/**
	Check if the url:String is equivalent to NSURL
	:param: url to compare me
	:returns: true if is the same false otherwise
	*/
	func isEquivalent(url: String) -> Bool {
		
		if let myUrl = absoluteString {
			let urlComponents = url.componentsSeparatedByString("?")
			let myUrlComponents = myUrl.componentsSeparatedByString("?")
				return urlComponents.first == myUrlComponents.first
		}
		
		return true
	}
	
}

swift 弱化函数可帮助您将实例弱绑定到静态方法引用

弱化函数可帮助您将实例弱绑定到静态方法引用

weakify.swift
// these functions take a swift class's statically referenced method and the instance those methods
// should apply to, and returns a function that weakly captures the instance so that you don't have
// to worry about memory retain cycles if you want to directly use an instance method as a handler
// for some object, like NSNotificationCenter.
//
// For more information, see this post:
// http://www.klundberg.com/blog/capturing-objects-weakly-in-instance-method-references-in-swift/

func weakify <T: AnyObject, U>(owner: T, f: T->U->()) -> U -> () {
    return { [weak owner] obj in
        if let this = owner {
            f(this)(obj)
        }
    }
}

func weakify <T: AnyObject>(owner: T, f: T->()->()) -> () -> () {
    return { [weak owner] in
        if let this = owner {
            f(this)()
        }
    }
}

func weakify <T: AnyObject, U>(owner: T, f: T->()->U) -> () -> U? {
    return { [weak owner] in
        if let this = owner {
            return f(this)()
        } else {
            return nil
        }
    }
}

func weakify <T: AnyObject, U, V>(owner: T, f: T->U?->()) -> V -> () {
    return { [weak owner] obj in
        if let this = owner {
            f(this)(obj as? U)
        }
    }
}

func weakify <T: AnyObject, U, V>(owner: T, f: T->U->V) -> U -> V? {
    return { [weak owner] obj in
        if let this = owner {
            return f(this)(obj)
        } else {
            return nil
        }
    }
}

func weakify <T: AnyObject, U>(owner: T, f: T->()->()) -> U -> () {
    return { [weak owner] _ in
        if let this = owner {
            f(this)()
        }
    }
}