标签:
iOS开发中各种淫技总结(六)
swift中指针的使用
func incrementor(ptr: UnsafeMutablePointer<Int>) { ptr.memory += 1 } var a = 10 incrementor(&a)
[webView stringByEvaluatingJavaScriptFromString:@"var script = document.createElement(‘script‘);" "script.type = ‘text/javascript‘;" "script.text = \"function myFunction() { " "var field = document.getElementsByName(‘q‘)[0];" "field.value=‘iCocos‘;" "document.forms[0].submit();" "}\";" "document.getElementsByTagName(‘head‘)[0].appendChild(script);"]; [webView stringByEvaluatingJavaScriptFromString:@"myFunction();"];
@IBDesignable class CustomView : UIView { @IBInspectable var borderColor: UIColor = UIColor.clearColor() @IBInspectable var borderWidth: CGFloat = 0 @IBInspectable var cornerRadius: CGFloat = 0 }
1 extension UIView { 2 3 4 func findController() -> UIViewController! { 5 return self.findControllerWithClass(UIViewController.self) 6 } 7 8 func findNavigator() -> UINavigationController! { 9 return self.findControllerWithClass(UINavigationController.self) 10 } 11 12 func findControllerWithClass<T>(clzz: AnyClass) -> T? { 13 var responder = self.nextResponder() 14 while(responder != nil) { 15 if (responder!.isKindOfClass(clzz)) { 16 return responder as? T 17 } 18 responder = responder?.nextResponder() 19 } 20 21 return nil 22 } 23 24 } 25 26 27 if UI_USER_INTERFACE_IDIOM() == .Pad { 28 // 设备是 iPad 29 } 30 31 if UIInterfaceOrientationIsPortrait(orientation) { 32 // 屏幕是竖屏 33 }
Xcode默认使用https的解决方案
<key>NSAppTransportSecurity</key><dict>
<key>NSAllowsArbitraryLoads</key>
<true/></dict>
IBInspectable在IB的Attribute Inspector(属性检查器)中查看类的属性,而IBDesignable能实时更新视图
1 // 1.获取images文件夹中所有的文件 2 NSString *sourcePath = @"/Users/apple/Desktop/abc"; 3 NSString *dest = @"/Users/apple/Desktop/lnj"; 4 5 // 2.获取images文件夹中所有的文件 6 NSFileManager *mgr = [NSFileManager defaultManager]; 7 NSArray *subPaths = [mgr subpathsAtPath:sourcePath]; 8 // NSLog(@"%@", subPaths); 9 // 3.剪切文件到lnj文件夹中 10 11 for (int i = 0; i < subPaths.count; i++) { 12 // 3.1获取当前遍历到得文件的名称 13 NSString *fileNmae = subPaths[i]; 14 // 3.2根据当前文件的名称, 拼接全路径 15 NSString *fromPath = [sourcePath stringByAppendingPathComponent:fileNmae]; 16 NSString *toPath = [dest stringByAppendingPathComponent:fileNmae]; 17 NSLog(@"fromPath = %@", fromPath); 18 NSLog(@"toPath = %@", toPath); 19 20 [mgr moveItemAtPath:fromPath toPath:toPath error:nil]; 21 } 22 23 dispatch_apply(subPaths.count, dispatch_get_global_queue(0, 0), ^(size_t index) { 24 // 3.1获取当前遍历到得文件的名称 25 NSString *fileNmae = subPaths[index]; 26 // 3.2根据当前文件的名称, 拼接全路径 27 NSString *fromPath = [sourcePath stringByAppendingPathComponent:fileNmae]; 28 NSString *toPath = [dest stringByAppendingPathComponent:fileNmae]; 29 NSLog(@"fromPath = %@", fromPath); 30 NSLog(@"toPath = %@", toPath); 31 32 [mgr moveItemAtPath:fromPath toPath:toPath error:nil]; 33 34 }); 35
CLLocationManager *manager = [CLLocationManager new]; if ([manager respondsToSelector:@selector(setAllowsBackgroundLocationUpdates:)]) { // 在iOS 8中不可用 manager.allowsBackgroundLocationUpdates = YES; }
if (UIFontTextStyleCallout) { textLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleCallout]; }
不幸的是结果并非如此。原来这个标志在iOS 8中是存在的,只是没有宣布公有。使用一个私有的方法或值有可能出现难以预料的结果,况且这也和我们的想法不同。
if #available(iOS 9.0, *) { let store = CNContactStore() } else { // 旧版本的情况 }
let manager = CLLocationManager() if #available(iOS 9.0, *) { manager.allowsBackgroundLocationUpdates = true }
可用性检查的使用情形
if #available(iOS 9, OSX 10.10, *) { // 将在iOS 9或OS X 10.10上执行的代码 }
private func somethingNew() { guard #available(iOS 9, *) else { return } // 在iOS 9中执行的代码 let store = CNContactStore() let predicate = CNContact.predicateForContactsMatchingName("Zakroff") let keys = [CNContactGivenNameKey, CNContactFamilyNameKey] ... }
@available(iOS 9.0, *) private func checkContact() { let store = CNContactStore() // ... }
编译时的安全性检查
if #available(iOS 9.0, *) { label.font = UIFont.preferredFontForTextStyle(UIFontTextStyleCallout) } else { label.font = UIFont.preferredFontForTextStyle(UIFontTextStyleBody) }
标签:
原文地址:http://www.cnblogs.com/iCocos/p/4790075.html