const getNearestDateIndex = (targetDate, dates) => {
if (!targetDate || !dates) {
throw new Error('Argument(s) is illegal !')
}
if (!dates.length) {
return -1
}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##dispatch_benchmark-Monkey | |
GCD 之 dispatch_benchmark 测量指定代码块执行时间 | |
#import <Foundation/Foundation.h> | |
// 声明GCD中dispatch_benchmark函数原型 | |
extern uint64_t dispatch_benchmark(size_t count, void (^block)(void)); | |
int main(int argc, const char * argv[]) { | |
@autoreleasepool { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private let defaultTopType: String = "application" | |
private let defaultSubType: String = "octet-stream" | |
/// Represents a media type, consisting of a top-level type and a subtype. | |
/// May also possess parameters which adjust or qualify the media type. | |
/// MimeType parameters are not parsed or processed but are provided as-is as a String | |
public struct MimeType: ExpressibleByStringLiteral, CustomStringConvertible, Comparable { | |
/// Required for StringLiteralConvertible | |
public typealias StringLiteralType = String |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIImage { | |
/// 图片压缩 | |
/// | |
/// - Parameters: | |
/// - maxFileSize: 压缩后的最大容量,单位 MB | |
/// - compression: 初始压缩值,默认为 1 | |
/// - Returns: | |
func mcCompress(maxFileSize: Int, compression: CGFloat = 1.0) -> Data? { | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func requestWith(endUrl: String, imageData: Data?, parameters: [String : Any], onCompletion: ((JSON?) -> Void)? = nil, onError: ((Error?) -> Void)? = nil){ | |
let url = "http://google.com" /* your API url */ | |
let headers: HTTPHeaders = [ | |
/* "Authorization": "your_access_token", in case you need authorization header */ | |
"Content-type": "multipart/form-data" | |
] | |
Alamofire.upload(multipartFormData: { (multipartFormData) in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
extension UIColor { | |
convenience init(red: Int, green: Int, blue: Int) { | |
assert(red >= 0 && red <= 255, "Invalid red component") | |
assert(green >= 0 && green <= 255, "Invalid green component") | |
assert(blue >= 0 && blue <= 255, "Invalid blue component") | |
self.init(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: 1.0) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import Photos | |
import AVFoundation | |
import MediaCenterSDK | |
import Kingfisher | |
import NVActivityIndicatorView | |
import ObjectMapper | |
class ViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate, NVActivityIndicatorViewable { | |