新特性:
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编码,相应的函数有:
01.
- (id)initWithBase64EncodedString:(NSString *)base64String
02.
options:(NSDataBase64DecodingOptions)options;
03.
04.
- (NSString *)base64EncodedStringWithOptions:
05.
(NSDataBase64EncodingOptions)options;
06.
07.
- (id)initWithBase64EncodedData:(NSData *)base64Data
08.
options:(NSDataBase64DecodingOptions)options;
09.
10.
- (NSData *)base64EncodedDataWithOptions:
11.
(NSDataBase64EncodingOptions)options;
NSTimer:新增函数:
1.
- (NSTimeInterval)tolerance;
2.
- (
void
)setTolerance:(NSTimeInterval)tolerance;
设置tolerance对于启动若干个fireDate相近的NSTimer有用,节省CPU唤醒时间
NSCharacterSet新增函数:
1.
+ (id)URLUserAllowedCharacterSet
2.
+ (id)URLPass<a href=
"http://www.it165.net/edu/ebg/"
target=
"_blank"
class
=
"keylink"
>word</a>AllowedCharacterSet
3.
+ (id)URLHostAllowedCharacterSet
4.
+ (id)URLPathAllowedCharacterSet
5.
+ (id)URLQueryAllowedCharacterSet
6.
+ (id)URLFragmentAllowedCharacterSet
新增类:
NSProgress:进度通知类
NSURLComponents:可把其视作NSMutableURL,例子:
1.
NSURLComponents *components = [NSURLComponents componentsWithString:@
"http://nshipster.com"
];
2.
components.path = @
"/iOS7"
;
3.
components.query = @
"foo=bar"
;
4.
5.
NSLog(@
"%@"
, components.scheme);
// @"http"
6.
NSLog(@
"%@"
, [components URL]);
// @http://nshipster.com/iOS7?foo=bar
CIDetectorSmile & CIDetectorEyeBlink:图像微笑和眨眼识别,例子:
01.
CIDetector *smileDetector = [CIDetector detectorOfType:CIDetectorTypeFace
02.
context:context
03.
options:@{CIDetectorTracking: @YES,
04.
CIDetectorAccuracy: CIDetectorAccuracyLow}];
05.
NSArray *features = [smileDetector featuresInImage:image options:@{CIDetectorSmile:@YES}];
06.
if
(([features count] > 0) && (((CIFaceFeature *)features[0]).hasSmile)) {
07.
UIImageWriteToSavedPhotosAlbum(image, self, @selector(didFinishWritingImage), features);
08.
}
else
{
09.
self.label.text = @
"Say Cheese!"
10.
}
AVCaptureMetaDataOutput:支持二维码及其他类型码识别,例子:
01.
AVCaptureSession *session = [[AVCaptureSession alloc] init];
02.
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
03.
NSError *error = nil;
04.
05.
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device
06.
error:&error];
07.
if
(input) {
08.
[session addInput:input];
09.
}
else
{
10.
NSLog(@
"Error: %@"
, error);
11.
}
12.
13.
AVCaptureMetadataOutput *output = [[AVCaptureMetadataOutput alloc] init];
14.
[output setMetadataObjectTypes:@[AVMetadataObjectTypeQRCode]];
15.
[output setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];
16.
[session addOutput:output];
17.
18.
[session startRunning];
01.
#pragma mark - AVCaptureMetadataOutputObjectsDelegate
02.
03.
- (
void
)captureOutput:(AVCaptureOutput *)captureOutput
04.
didOutputMetadataObjects:(NSArray *)metadataObjects
05.
fromConnection:(AVCaptureConnection *)connection
06.
{
07.
NSString *QRCode = nil;
08.
for
(AVMetadataObject *metadata in metadataObjects) {
09.
if
([metadata.type isEqualToString:AVMetadataObjectTypeQRCode]) {
10.
// This will never happen; nobody has ever scanned a QR code... ever
11.
QRCode = [(AVMetadataMachineReadableCodeObject *)metadata stringValue];
12.
break
;
13.
}
14.
}
15.
16.
NSLog(@
"QR Code: %@"
, QRCode);
17.
}
SSReadingList:添加URL到safari阅读列表中,例子:
1.
NSURL *URL = [NSURL URLWithString:@
"http://nshipster.com/ios7"
];
2.
[[SSReadingList defaultReadingList] addReadingListItemWithURL:URL
3.
title:@
"NSHipster"
4.
previewText:@
"..."
5.
error:nil];
AVSpeechSynthesizer:文本转语音,例子:
1.
AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc] init];
2.
AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:@
"Just what do you think you're doing, Dave?"
];
3.
utterance.rate = AVSpeechUtteranceMinimumSpeechRate;
// Tell it to me slowly
4.
[synthesizer speakUtterance:utterance];
MKDistanceFormatter:距离格式化为本地文本,例子:
1.
CLLocation *sanFrancisco = [[CLLocation alloc] initWithLatitude:37.775 longitude:-122.4183333];
2.
CLLocation *portland = [[CLLocation alloc] initWithLatitude:45.5236111 longitude:-122.675];
3.
CLLocationDistance distance = [portland distanceFromLocation:sanFrancisco];
4.
5.
MKDistanceFormatter *formatter = [[MKDistanceFormatter alloc] init];
6.
formatter.units = MKDistanceFormatterUnitsImperial;
7.
NSLog(@
"%@"
, [formatter stringFromDistance:distance]);
// 535 miles