SoFunction
Updated on 2024-11-14

Sorting Dictionaries by Multiple Rules in Python

First, let's talk about determining whether the cell phone number is correct or not. My idea is to add a category to the string and write code like this:
+ (BOOL)valiMobile:(NSString *)mobile{
        if ( != 11){
//Determine whether the cell phone number is 11-digit
            return NO;
            }else{
// Use the regular expression method to determine the cell phone number
/**
* :: Mobile segment regular expressions
  */
                NSString *CM_NUM = @"^((13[4-9])|(147)|(15[0-2,7-9])|(178)|(18[2-4,7-8]))\\d{8}|(1705)\\d{7}$";
/**
* :: Unicode regular expressions
*/
                 NSString *CU_NUM = @"^((13[0-2])|(145)|(15[5-6])|(176)|(18[5,6]))\\d{8}|(1709)\\d{7}$";
/**
* :: Regular expressions for electrical signal segments
*/
                NSString *CT_NUM = @"^((133)|(153)|(177)|(18[0,1,9]))\\d{8}$";
//Initialize the NSPredicate object
                NSPredicate *pred1 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM_NUM];
//Filter judgment with specific object, return BOOL value.
                BOOL isMatch1 = [pred1 evaluateWithObject:mobile];
                NSPredicate *pred2 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CU_NUM];
                BOOL isMatch2 = [pred2 evaluateWithObject:mobile];
                NSPredicate *pred3 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CT_NUM];
            BOOL isMatch3 = [pred3 evaluateWithObject:mobile];
                if (isMatch1 || isMatch2 || isMatch3) {
                    return YES;
                    }else{
                return NO;
            }
        }
}
If you have some questions about the use of NSPredicate, you can look at this article:/p/d4098bc9488d the following and then say a CAPTCHA countdown, 1, I created a classification for the button 2, set the text on the button, and record the total length of the countdown, and then open a timer, and close the button's Click event 3, the total time will be reduced in the timer, and set the text on the button, and then do a judgment to determine whether the time is returned to 0, if it is 0, then release the timer, and then set the text on the button, and then open the user interaction. Code is as follows: .h file
#import@interface UIButton (BtnTime)
/**
Problems with button countdown
@param countDownTime The countdown time in minutes.
*/
- (void)buttonWithTime:(CGFloat)countDownTime;
@end
In the .m file
#import "UIButton+"
/** Display time for countdown */
static NSInteger secondsCountDown;
/** Recording of total time */
static NSInteger allTime;
@implementation UIButton (BtnTime)
- (void)buttonWithTime:(CGFloat)countDownTime {
= NO;
secondsCountDown = 60 * countDownTime;
allTime = 60 * countDownTime;
[self setTitle:[NSString stringWithFormat:@"%ldsRetrieve after",secondsCountDown] forState:UIControlStateNormal];
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeFireMethod:) userInfo:nil repeats:YES];
}
-(void)timeFireMethod:(NSTimer *)countDownTimer{
//Countdown-1
secondsCountDown--;
//Modify countdown label reality content
[self setTitle:[NSString stringWithFormat:@"%ldsRetrieve after",secondsCountDown] forState:UIControlStateNormal];
//When the countdown reaches 0, do the required actions, such as the CAPTCHA expired can not be submitted
if(secondsCountDown == 0){
[countDownTimer invalidate];
[self setTitle:@"Retrieve" forState:UIControlStateNormal];;
secondsCountDown = allTime;
= YES;
}
}
@end