像strong, retain, copy,block引用循环这些常见的这里不再赘述。
- 下面代码输出结果
- (void)viewDidLoad {
[super viewDidLoad];
dispatch_sync(dispatch_get_global_queue(0, 0), ^{
| import UIKit | |
| class CustomURLProtocol: URLProtocol { | |
| struct Constants { | |
| static let RequestHandledKey = "URLProtocolRequestHandled" | |
| } | |
| var session: URLSession? | |
| var sessionTask: URLSessionDataTask? |
| /** | |
| Returns an accurate version of the system uptime even while the device is asleep. | |
| http://stackoverflow.com/questions/12488481/getting-ios-system-uptime-that-doesnt-pause-when-asleep | |
| - returns: Time interval since last reboot. | |
| */ | |
| public static func systemUptime() -> TimeInterval { | |
| var boottime = timeval() | |
| var mib = [CTL_KERN, KERN_BOOTTIME] | |
| var size = MemoryLayout<timeval>.stride |
像strong, retain, copy,block引用循环这些常见的这里不再赘述。
- (void)viewDidLoad {
[super viewDidLoad];
dispatch_sync(dispatch_get_global_queue(0, 0), ^{
| // Make sure viewDidAppear has happened before sending this action to ensure that all links | |
| // in the responder chain are connected. | |
| // http://stackoverflow.com/a/11768282/1306872 | |
| [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) | |
| to:nil | |
| from:nil | |
| forEvent:nil]; | |
| ////////////////////////////////////////////////// | |
| @implementation UIView (FirstResponder) | |
| - (UIView *)findFirstResponder { | |
| if (self.isFirstResponder) { | |
| return self; | |
| } | |
| for (UIView *subView in self.subviews) { | |
| UIView *firstResponder = [subView findFirstResponder]; | |
| if (firstResponder != nil) { |
| if [ $CONFIGURATION == Release ]; then | |
| echo "Bumping build number..." | |
| plist=${PROJECT_DIR}/${INFOPLIST_FILE} | |
| # increment the build number (ie 115 to 116) | |
| buildnum=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${plist}") | |
| if [[ "${buildnum}" == "" ]]; then | |
| echo "No build number in $plist" | |
| exit 2 | |
| fi |
| func sumRecursively(numbers: [Int], _ acc:Int = 0) -> Int { | |
| if let head = numbers.first { | |
| let tail = Array(dropFirst(numbers)) | |
| return sumRecursively(tail, head + acc) | |
| } else { | |
| return acc | |
| } | |
| } | |
| let myNumbers = [1,2,3,4,5] |
| // | |
| // NSDictionary+Unicode.m | |
| // | |
| // Created by lihang on 2017/2/5. | |
| // Copyright © 2017年 HL. All rights reserved. | |
| // | |
| @implementation NSDictionary (HLUnicode) | |
| + (void)load { |
| import Foundation | |
| import AVFoundation | |
| import UIKit | |
| class LHPersistentRunTask : NSObject, AVAudioPlayerDelegate { | |
| var player : AVAudioPlayer? | |
| var backgroundTask = UIBackgroundTaskInvalid | |
| var expirationHandler : (()->Void)? |
| let label = UILabel() | |
| label.frame = CGRect(x: 0.0, y: 0.0, width: 400.0, height: 75.0) | |
| label.backgroundColor = UIColor.whiteColor() | |
| label.font = UIFont.preferredFontForTextStyle(UIFontTextStyleTitle1) | |
| label.textAlignment = .Center | |
| label.text = "Hello, world!" | |
| let fadeTransition = CATransition() | |
| fadeTransition.duration = 0.2 |