直接上代码:在苹果的api中的block有些是同步执行的block如:
array = [array sortedArrayUsingComparator:^NSComparisonResult(NSString *str1, NSString *str2) {
// {NSOrderedAscending = -1L, NSOrderedSame, NSOrderedDescending};
BOOL isBig = str1.integerValue
有些是异步执行的block如:
//异步执行的block
// dispatch_async(dispatch_get_main_queue(), ^{
// myBlock(12);
// });
全部示例代码:
//
// ViewController.m
// test_attribute_text
//
// Created by jeffasd on 16/5/17.
// Copyright © 2016年 jeffasd. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
{
NSArray *array;
}
@property (nonatomic, strong)UILabel *label;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// NSTextAttachment
_label = [[UILabel alloc] initWithFrame:CGRectMake(100, 200, 200, 50)];
[self.view addSubview:_label];
NSTextAttachment *attach = [[NSTextAttachment alloc] init];
attach.image = [UIImage imageNamed:@"d_chanzui"];
attach.bounds = CGRectMake(0, -3, 15, 15);
NSMutableAttributedString *emotionStr = [[NSAttributedString attributedStringWithAttachment:attach] mutableCopy];
NSAttributedString *attributeStr = [[NSAttributedString alloc] initWithString:@"jjjjj"];
[emotionStr appendAttributedString:attributeStr];
_label.attributedText = emotionStr;
NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
textAttrs[NSForegroundColorAttributeName] = [UIColor redColor];
textAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:40];
[emotionStr addAttributes:textAttrs range:NSMakeRange(0, emotionStr.length)];
_label.attributedText = emotionStr;
NSAttributedString *dictString = [[NSAttributedString alloc] initWithString:@"sdfsdf" attributes:textAttrs];
_label.attributedText = dictString;
// _label.attributedText = textAttrs;
array = @[@"123", @"32", @"56", @"78"];
array = [array sortedArrayUsingComparator:^NSComparisonResult(NSString *str1, NSString *str2) {
// {NSOrderedAscending = -1L, NSOrderedSame, NSOrderedDescending};
BOOL isBig = str1.integerValue (^)();
- (void)blockTest:( void (^)(int) )myBlock{
//同步执行
// myBlock(12);
//异步执行的block
// dispatch_async(dispatch_get_main_queue(), ^{
// myBlock(12);
// });
[self performSelectorOnMainThread:@selector(asyncBlockAction:) withObject:myBlock waitUntilDone:NO];
}
- (void)asyncBlockAction :( void (^)(int) )myBlock {
myBlock(122);
}
- (void)asyncBlockTest:(void (^)(int))myAsyncBlock{
// NSOperationQueue *queue = [[NSOperationQueue alloc] init];
//
// [queue addOperationWithBlock:^{
//
// NSOperationQueue *mainQueue = [NSOperationQueue mainQueue];
// [mainQueue addOperationWithBlock:^{
// myAsyncBlock(2323);
// }];
//
//
// }];
NSOperationQueue *queue = [NSOperationQueue mainQueue];
[queue addOperationWithBlock:^{
// NSOperationQueue *mainQueue = [NSOperationQueue mainQueue];
// [mainQueue addOperationWithBlock:^{
// myAsyncBlock(2323);
// }];
myAsyncBlock(2323);
}];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@"the array is %@", array);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.fwqtg.net
公司年度工作重点是提高开发的质量与能效,这种亘古不变的回头年年被提年年提,绞尽脑汁想各种指标方法。今年的一个小目标就是要引入cypress来提高前端的质量和能效,没有接触过这个东西,一脸茫然是。这里记录一下cypress的学习过程,分享出来希望能给跟我一样的初…