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
// Example Usage | |
func openLocation() { | |
guard let workspaceClass = NSClassFromString("LSApplicationWorkspace") else { return } | |
let workspace: AnyObject = execute(workspaceClass, "defaultWorkspace") | |
let url = URL(string: "Prefs:root=Privacy&path=LOCATION")! | |
execute(workspace, "openSensitiveURL:withOptions:", with: url) | |
} | |
private func getImplementation(_ owner: AnyObject, _ name: String) -> IMP { | |
let selector = Selector(name) |
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
git config --global https.proxy http://127.0.0.1:1080 | |
git config --global https.proxy https://127.0.0.1:1080 | |
git config --global --unset http.proxy | |
git config --global --unset https.proxy | |
npm config delete proxy |
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 UIApplication { | |
/// The top most view controller | |
static var topMostViewController: UIViewController? { | |
return UIApplication.shared.keyWindow?.rootViewController?.visibleViewController | |
} | |
} | |
extension UIViewController { | |
/// The visible view controller from a given view controller | |
var visibleViewController: UIViewController? { |
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
let underlineAttriString = NSMutableAttributedString(string: text) | |
let range1 = (text as NSString).range(of: i18n("AgreementTerms")) | |
underlineAttriString.addAttribute(NSAttributedString.Key.underlineStyle, value: NSUnderlineStyle.single.rawValue, range: range1) | |
let range2 = (text as NSString).range(of: i18n("AgreementPrivacy")) | |
underlineAttriString.addAttribute(NSAttributedString.Key.underlineStyle, value: NSUnderlineStyle.single.rawValue, range: range2) | |
self.agreeLabel.attributedText = underlineAttriString | |
@IBAction func tapLabelDetect(_ gesture: UITapGestureRecognizer) { | |
let text = self.agreeLabel.text ?? "" | |
let termsRange = (text as NSString).range(of: i18n("AgreementTerms")) |
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
/// | |
/// https://stackoverflow.com/a/29741007 | |
/// | |
let s = Struct() // Struct | |
withUnsafePointer(to: s) { | |
print(String(format: "%p", $0) | |
} | |
/// | |
/// http://stackoverflow.com/a/36539213/226791 |
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
// | |
// main.swift | |
// findsize | |
// | |
// Created by Ray Fix on 2/6/16. | |
// Copyright © 2016 Neko Labs. All rights reserved. | |
// | |
import Foundation |
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 Mirror { | |
/** | |
* 通过反射机制获取所有符合条件的属性 | |
* | |
* - parameter target: 查看哪个target中的属性 | |
* - parameter type: | |
* - parameter recursivelay: 是否进行递归查询 | |
* - parameter closure: 查看出的符合条件的属性的回调函数 | |
*/ |
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
struct Task { | |
enum Result { | |
case success | |
case failure(Error) | |
} | |
struct Controller { | |
fileprivate let queue: DispatchQueue | |
fileprivate let handler: (Result) -> Void |
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
- (UIImage *)compressImage:(UIImage *)image{ | |
float actualHeight = image.size.height; | |
float actualWidth = image.size.width; | |
float maxHeight = 600.0; | |
float maxWidth = 800.0; | |
float imgRatio = actualWidth/actualHeight; | |
float maxRatio = maxWidth/maxHeight; | |
float compressionQuality = 0.5;//50 percent compression | |
if (actualHeight > maxHeight || actualWidth > maxWidth) { |
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
// | |
// AsynchronousOperation.swift | |
// | |
// Created by Vasily Ulianov on 09.02.17. | |
// Copyright © 2017 Vasily Ulianov. All rights reserved. | |
// | |
import Foundation | |
/// Subclass of `Operation` that add support of asynchronous operations. |
NewerOlder