- 數(shù)組取值
1.使用 valueForKeyPath
valueForKeyPath
取到所有當(dāng)前key
的 value
值 返回?cái)?shù)組
2.使用 謂詞提取數(shù)據(jù), 可以返回滿足條件的model數(shù)據(jù)
NSNumber *testNumber = @123;
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF = 123"];
if ([predicate evaluateWithObject:testNumber]) {
NSLog(@"testString:%@", testNumber);
}
2.1. 姓名過(guò)濾
NSArray * nameFilter = [_model.addressList filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"name CONTAINS %@",searchText]];
終端下執(zhí)行下面命令
顯示全部文件
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];
}];