博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ios7新增基础类库以及OC新特性
阅读量:6072 次
发布时间:2019-06-20

本文共 4612 字,大约阅读时间需要 15 分钟。

新特性:

Modules:用XCode5新建工程默认支持modules编译,老项目需在Build Settings里查找modules,找到的Enable Modules选项设置为YES。

对应新增语法:@import,导入系统头文件,例如:@import MapKit;  或者库的部分头文件:@import UIKit.UIView;

优点:不需要再在Build Phases里的Link Binary With Libraries添加系统framework文件;缺点:不支持自定义或第三方库

新返回类型:instancetype,用在构造函数返回类型上,建议以前用id作为返回类型的都改成instancetype。

好处:有更严格的编译类型检查,便于编译时即可发现潜在的问题;

NSArray:新增函数: -(id)firstObject; 但只要ios4以上都可以用

NSData:新增Base64编码,相应的函数有:

 

- (id)initWithBase64EncodedString:( *)base64String       options:(NSDataBase64DecodingOptions)options; - ( *)base64EncodedStringWithOptions:      (NSDataBase64EncodingOptions)options; - (id)initWithBase64EncodedData:( *)base64Data       options:(NSDataBase64DecodingOptions)options; - ( *)base64EncodedDataWithOptions:      (NSDataBase64EncodingOptions)options;

 

 

NSTimer:新增函数:

 

- (NSTimeInterval)tolerance;- (void)setTolerance:(NSTimeInterval)tolerance;

设置tolerance对于启动若干个fireDate相近的NSTimer有用,节省CPU唤醒时间

 

NSCharacterSet新增函数:

 

  • + (id)URLUserAllowedCharacterSet
  • + (id)URLPasswordAllowedCharacterSet
  • + (id)URLHostAllowedCharacterSet
  • + (id)URLPathAllowedCharacterSet
  • + (id)URLQueryAllowedCharacterSet
  • + (id)URLFragmentAllowedCharacterSet

 

新增类:

NSProgress:进度通知类

NSURLComponents:可把其视作NSMutableURL,例子:

 

NSURLComponents *components = [NSURLComponents componentsWithString:@"http://nshipster.com"];components.path = @"/iOS7";components.query = @"foo=bar";NSLog(@"%@", components.scheme); // @"http"NSLog(@"%@", [components URL]); // @"http://nshipster.com/iOS7?foo=bar"

CIDetectorSmile & CIDetectorEyeBlink:图像微笑和眨眼识别,例子:

 

 

CIDetector *smileDetector = [CIDetector detectorOfType:CIDetectorTypeFace                                context:context                                 options:@{CIDetectorTracking: @YES,                                           CIDetectorAccuracy: CIDetectorAccuracyLow}];NSArray *features = [smileDetector featuresInImage:image options:@{CIDetectorSmile:@YES}];if (([features count] > 0) && (((CIFaceFeature *)features[0]).hasSmile)) {    UIImageWriteToSavedPhotosAlbum(image, self, @selector(didFinishWritingImage), features);} else {    self.label.text = @"Say Cheese!"}

 

 

 

AVCaptureMetaDataOutput:支持二维码及其他类型码识别,例子:

AVCaptureSession *session = [[AVCaptureSession alloc] init];AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];NSError *error = nil;AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device                                                                    error:&error];if (input) {    [session addInput:input];} else {    NSLog(@"Error: %@", error);}AVCaptureMetadataOutput *output = [[AVCaptureMetadataOutput alloc] init];[output setMetadataObjectTypes:@[AVMetadataObjectTypeQRCode]];[output setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];[session addOutput:output];[session startRunning];
#pragma mark - AVCaptureMetadataOutputObjectsDelegate- (void)captureOutput:(AVCaptureOutput *)captureOutputdidOutputMetadataObjects:(NSArray *)metadataObjects       fromConnection:(AVCaptureConnection *)connection{    NSString *QRCode = nil;    for (AVMetadataObject *metadata in metadataObjects) {        if ([metadata.type isEqualToString:AVMetadataObjectTypeQRCode]) {            // This will never happen; nobody has ever scanned a QR code... ever            QRCode = [(AVMetadataMachineReadableCodeObject *)metadata stringValue];            break;        }    }    NSLog(@"QR Code: %@", QRCode);}

SSReadingList:添加URL到safari阅读列表中,例子:

NSURL *URL = [NSURL URLWithString:@"http://nshipster.com/ios7"];[[SSReadingList defaultReadingList] addReadingListItemWithURL:URL                                                        title:@"NSHipster"                                                  previewText:@"..."                                                         error:nil];

AVSpeechSynthesizer:文本转语音,例子:

AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc] init];AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:@"Just what do you think you're doing, Dave?"];utterance.rate = AVSpeechUtteranceMinimumSpeechRate; // Tell it to me slowly[synthesizer speakUtterance:utterance];

MKDistanceFormatter:距离格式化为本地文本,例子:

CLLocation *sanFrancisco = [[CLLocation alloc] initWithLatitude:37.775 longitude:-122.4183333];CLLocation *portland = [[CLLocation alloc] initWithLatitude:45.5236111 longitude:-122.675];CLLocationDistance distance = [portland distanceFromLocation:sanFrancisco];MKDistanceFormatter *formatter = [[MKDistanceFormatter alloc] init];formatter.units = MKDistanceFormatterUnitsImperial;NSLog(@"%@", [formatter stringFromDistance:distance]); // 535 miles
参考网址:

 

 

转载地址:http://zqngx.baihongyu.com/

你可能感兴趣的文章
深入浅出Netty
查看>>
3.使用maven创建java web项目
查看>>
笔记本搜索不到某一AP广播的SSID,信道的原因
查看>>
基于Spring MVC的异常处理及日志管理
查看>>
MediaBrowserService 音乐播放项目《IT蓝豹》
查看>>
MySQL入门12-数据类型
查看>>
Windows Azure 保留已存在的虚拟网络外网IP(云服务)
查看>>
修改字符集
查看>>
HackTheGame 攻略 - 第四关
查看>>
js删除数组元素
查看>>
带空格文件名的处理(find xargs grep ..etc)
查看>>
华为Access、Hybrid和Trunk的区别和设置
查看>>
centos使用docker下安装mysql并配置、nginx
查看>>
关于HTML5的理解
查看>>
需要学的东西
查看>>
Internet Message Access Protocol --- IMAP协议
查看>>
Linux 获取文件夹下的所有文件
查看>>
对 Sea.js 进行配置(一) seajs.config
查看>>
dom4j解析xml文件
查看>>
第六周
查看>>