1.使用valueForKeyPath求数组和、最大值、最小值及平均值
NSMutableArray* array = [NSMutableArray array];
for (int i = 0; i < 10; i++) {
CGFloat num = arc4random() % 100 + 1;
[array addObject:[NSNumber numberWithFloat:num]];
}
CGFloat sumValue = [[array valueForKeyPath:@"@sum.floatValue"] floatValue];
CGFloat maxValue = [[array valueForKeyPath:@"@max.floatValue"] floatValue];
CGFloat minValue = [[array valueForKeyPath:@"@min.floatValue"] floatValue];
CGFloat avgValue = [[array valueForKeyPath:@"@avg.floatValue"] floatValue];
2.获取汉字对应的拼音
+ (NSString *)getPinyinFormChinese:(NSString *)chinese {
// 将NSString装换成NSMutableString
NSMutableString *pinyin = [chinese mutableCopy];
// 将汉字转换为拼音(带音标)
CFStringTransform((__bridge CFMutableStringRef)pinyin, NULL, kCFStringTransformMandarinLatin, NO);
// 去掉拼音的音标(不带音标)
CFStringTransform((__bridge CFMutableStringRef)pinyin, NULL, kCFStringTransformStripCombiningMarks, NO);
return pinyin;
}
3.代码执行效率检测
CFAbsoluteTime start = CFAbsoluteTimeGetCurrent();
{测试代码}
CFAbsoluteTime end = CFAbsoluteTimeGetCurrent();
NSLog(@"代码执行时间: %0.3f", end - start);
4.生成随机字符串
NSInteger length = 10;
char data[length];
for (int i = 0; i < length; i++) {
data[i] = 'A' + (arc4random_uniform(26));
}
NSString *string = [[NSString alloc] initWithBytes:data length:length encoding:NSUTF8StringEncoding];
5.设置应用可以通过iTunes与电脑传输文件
在Info.plist中添加Application supports iTunes file sharing字段 Value设置为YES
6.Xcode文件路径
项目描述文件路径: ~/Library/MobileDevice/Provisioning Profiles
打包项目路径(Archive):~/Library/Developer/Xcode/Products
7.UIView转换为UIImage
// 将UIView转换为UIImage
- (UIImage *)convertViewToImage:(UIView *)view {
CGSize size = view.bounds.size;
// 下面方法,第一个参数表示区域大小。第二个参数表示是否是非透明的。如果需要显示半透明效果,需要传NO,否则传YES。第三个参数就是屏幕密度了
UIGraphicsBeginImageContextWithOptions(size, NO, [UIScreen mainScreen].scale);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}