- 数组取值
1.使用 valueForKeyPath
valueForKeyPath 取到所有当前key的 value值 返回数组
2.使用 谓词提取数据, 可以返回满足条件的model数据
NSNumber *testNumber = @123;
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF = 123"];
if ([predicate evaluateWithObject:testNumber]) {
NSLog(@"testString:%@", testNumber);
}
2.1. 姓名过滤
NSArray * nameFilter = [_model.addressList filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"name CONTAINS %@",searchText]];
终端下执行下面命令
显示全部文件
defaults write com.apple.finder AppleShowAllFiles -bool true
osascript -e 'tell application "Finder" to quit'
不显示全部文件
defaults write com.apple.finder AppleShowAllFiles -bool false
osascript -e 'tell application "Finder" to quit'
3.获取微信用户信息
[[AFHTTPSessionManager manager]
GET:@"https://api.weixin.qq.com/sns/oauth2/access_token"
parameters:@{@"appid":KWechatAPPID,
@"secret":KWechatAPPSecret,
@"code":strOrEmpty(code),
@"grant_type":@"authorization_code"}
progress:^(NSProgress * _Nonnull downloadProgress) {
}
success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
//解析access_token
NSLog(@"获取access_token: %@\n openid: %@",[responseObject objectForKey:@"access_token"],[responseObject objectForKey:@"openid"]);
//微信登录
NSString * openId = [responseObject objectForKey:@"openid"];
NSString * access_token = [responseObject objectForKey:@"access_token"];
//unionid
NSString *url =[NSString stringWithFormat:@"https://api.weixin.qq.com/sns/userinfo?access_token=%@&openid=%@",access_token,openId];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSURL *zoneUrl = [NSURL URLWithString:url];
NSString *zoneStr = [NSString stringWithContentsOfURL:zoneUrl encoding:NSUTF8StringEncoding error:nil];
NSData *data = [zoneStr dataUsingEncoding:NSUTF8StringEncoding];
dispatch_async(dispatch_get_main_queue(), ^{
if (data) {
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:WXLoginSuccessNotification object:dic];
}
});
});
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"走到这里面了-===========");
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"获取用户信息失败" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
[alertView show];
}];