“This is the 23rd day of my participation in the First Challenge 2022. For details: First Challenge 2022.”
The introduction
Use NSPredicate to search for elements of a particular condition from an array:
- Filter the selected specification data
- Regroups an array of objects with date attributes by date
- Urban search
- Concatenation of multiple filter criteria: filtering of bank lists
- Filtering of string arrays (array elements are of system type)
- Data query for Core Data
- Grouping data using predicates (array elements are of custom type)
Use regular expressions to match lookup data:
- Use regular expressions to monitor keywords in chat logs
- Application of NSPredicate in regular expressions: regular expressions that limit UITextField to input only amount (0.. 00)
Use system-specific apis for data lookups to avoid looping through sets of numbers:
- Use NSPredicate to filter the electronic signature data of type=8 from the array to avoid traversing the set of certificateInfoList
- Use makeObjectsPerformSelector to avoid loop array
- Use the method starting with enumerate
I searches an array for elements of a particular condition
- Search for conditional elements from arrays (Filter e-signature data from arrays with Type =8, avoid traversing sets of certificateInfoList)
- Kunnan.blog.csdn.net/article/det…
II Application of regular expressions
- IOS data search skills [regular expression application]
Kunnan.blog.csdn.net/article/det…
III. Avoid looping over a number set
3.1 use NSPredicate to filter the e-signature data of type=8 from the array and avoid going through the set of certificateInfoList
- Find e-signature data [avoid traversing sets of certificateInfoList, determine type=8]
Blog.csdn.net/z929118967/…
- (CRMcertificateInfoListDto *)getSignimgURLCRMcertificateInfoListDto{
NSPredicate* predicate = [NSPredicate predicateWithFormat:@"type == %@"The [[NSNumber numberWithInteger:CRMcertificateInfoListDtotype4Sign] description]];
NSArray *arFiltered = [ self.certificateInfoList filteredArrayUsingPredicate:predicate];// Filter the maTemp array with a certain criteria (specific date), i.e., do a big data search.
CRMcertificateInfoListDto *dto = nil;
if(arFiltered.count>0){
dto = arFiltered.firstObject;
}
return dto;
}
Copy the code
3.2 use makeObjectsPerformSelector to avoid loop array
- Using makeObjectsPerformSelector set self. StorePayFeeRateListDto. The attribute of internal elements settlementCycle payFeeRateList array (settlement cycle: 0-T0 1-T1 default 0) to avoid looping convenience arrays
[self.StorePayFeeRateListDto.payFeeRateList makeObjectsPerformSelector:@selector(setSettlementCycle:) withObject:swichStr];
Copy the code
- Loop through the code of the array
for (int i = 0; i < self.StorePayFeeRateListDto.payFeeRateList.count; i++) {//settlementCycle
NSMutableDictionary * mutDic = [[NSMutableDictionary alloc]initWithDictionary:_sectionArr[i]];
[mutDic setObject:swichStr forKey:@"settlementCycle"];
[_sectionArr setObject:mutDic atIndexedSubscript:i];
}
Copy the code
3.3 Using the method starting with Enumerate
[objc] view plain copy
/* In the enumerate methods, the blocks will be invoked inside an autorelease pool, so any values assigned inside the block should be retained. */
- (void)enumerateSubstringsInRange:(NSRange)range options:(NSStringEnumerationOptions)opts usingBlock:(void(^) (NSString * __nullable substring, NSRange substringRange, NSRange enclosingRange, BOOLBOOL *stop))block NS_AVAILABLE(10_6, 4_0);
- (void)enumerateLinesUsingBlock:(void(^) (NSString *line, BOOLBOOL *stop))block NS_AVAILABLE(10_6, 4_0);
Copy the code
- Used to read the contents of a TXT document line by line
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"girl" ofType:@"txt"];
NSData *fileData = [NSData dataWithContentsOfFile:filePath];
NSString *fileStr = [[NSString alloc]initWithData:fileData encoding:NSUTF8StringEncoding];
// Read line by line
[fileStr enumerateLinesUsingBlock:^(NSString * _Nonnull line, BOOLBOOL * _Nonnull stop) {
NSLog(@"%@\n",line);
}];
// read character by character
[fileStr enumerateSubstringsInRange:NSMakeRange(0, fileStr.length) options:NSStringEnumerationByWords usingBlock:^(NSString * _Nullable substring, NSRange substringRange, NSRange enclosingRange, BOOLBOOL * _Nonnull stop) {
NSLog(@"tmp111===%@",substring);
}];
Copy the code
- An example of traversing a payment password
// read character by character
[fileStr enumerateSubstringsInRange:NSMakeRange(0, fileStr.length) options:NSStringEnumerationByComposedCharacterSequences
usingBlock:^(NSString * _Nullable substring, NSRange substringRange, NSRange enclosingRange, BOOL * _Nonnull stop) {
NSLog(@"tmp111===%@",substring);
[m_textField appendPsw:substring];
[_pswView SetInputNum:_inputEncData.count];
[m_textField onChange];
}];
Copy the code
- NSStringEnumerationByWords
[fileStr enumerateSubstringsInRange:NSMakeRange(0, fileStr.length) options:NSStringEnumerationByWords
usingBlock:^(NSString * _Nullable substring, NSRange substringRange, NSRange enclosingRange, BOOL * _Nonnull stop) {
NSLog(@"tmp111===%@",substring);
[m_textField appendPsw:substring];
[_pswView SetInputNum:_inputEncData.count];
[m_textField onChange];
}];
Copy the code
see also
1. Please input the correct settlement card number [Luhn algorithm of bank Card Number validity verification] – Bank card number verification algorithm 2. Id card verification: [Verification age and whether verification meets the rules of ID card number generation]
Blog.csdn.net/z929118967/…
BOOL in OC is not as good as BOOL
BOOL means 1 is YES, so non-1 is NO. BOOL means 0 is false, so non-0 is true;
Contact author: iOS Reverse (public number: iosrev)
Author profile: CSDN blog expert certification
international Top 50, Huawei Cloud enjoy expert certification
, iOS reverse public number master
Resume template, technical assistance. Pay attention to me, all for you.