Extensions for IOS oc07.2_ classes

Source: Internet
Author: User

Category
//1.系统已经写好的类目:按照功能对系统的类方法进行区分    //[email protected]开始,后面是当前类的名字,类名后面是分类的功能,到@end结束    //2.我们创建的类目,一般是为了把系统的类进行功能扩充
//NSString *[email protected] "2015-07-12 10:00:00";//NSString *[email protected] "2015-07-12 09:00:00"; ///[str sayhi];//     ///BOOL istrue=[str2 ISEQUALTWODATE:STR];//    //    //if ([str2 isequaltostring:str]) {//NSLog (@ "month of the same");//}else{//NSLog (@ "Month different");//    }//    //    //NSString *newtime=[str APPENDTWODATE:STR2];//NSLog (@ "%@", newtime);//    //NSDate *date=[str stringtodate];//NSLog (@ "%@", date);//    //NSDate *date1=[nsstring STRINGTODATE:STR];//NSLog (@ "%@", date1);
Nsstring+stringmethod.h
////Nsstring+stringmethod.h//extension of the Oc07_ class////Created by Dllo on 15/7/24.//Copyright (c) 2015 Zhozhicheng. All rights reserved.//#import <Foundation/Foundation.h>  @interface nsstring (stringmethod)-(void) Sayhi;//Enter two dates to determine whether two dates are in the same one months-(BOOL) Isequaltwodate: (NSString*) Otherdate;//Splicing date-(NSString*) Appendtwodate: (NSString*) Otherdate;//Given two time to determine if the time is within these two intervals-(BOOL) Isintimezone: (NSString*) BeginTime End: (NSString*) endtime;-(NSDate*) stringtodate;+ (NSDate*) Stringtodate: (NSString*) Datestr;@end
"Nsstring+stringmethod.h"
////NSSTRING+STRINGMETHOD.M//extension of the Oc07_ class////Created by Dllo on 15/7/24.//Copyright (c) 2015 Zhozhicheng. All rights reserved.//#import "Nsstring+stringmethod.h"  @implementation nsstring (stringmethod)-(void) sayhi{NSLog(@"Hello");} -(BOOL) Isequaltwodate: (NSString*) otherdate{//This method requires two parameters, the first parameter is the caller of the method, who called the method, so inside of this method, self is the object that uses the method//NSLog (@ "%@", self);    //Interception    Nsrangerange={5,2};NSString*str1=[ SelfSubstringwithrange:range];NSString*str2= [Otherdate Substringwithrange:range];return[str1 ISEQUALTOSTRING:STR2];} -(NSString*) Appendtwodate: (NSString*) otherdate{NSString*endtime=[otherdate Substringfromindex:Ten];return[ SelfStringbyappendingstring:endtime];} -(BOOL) Isintimezone: (NSString*) BeginTime End: (NSString*) endtime{return YES;}//Pass past a string that returns an object of the time NSDate type-(NSDate*) stringtodate{//Set formatNSDateFormatter *formatter=[[nsdateformatter alloc] init]; [Formatter setdateformat:@"Yyyy-mm-dd hh:mm:ss"];return[Formatter datefromstring: Self];} +(NSDate*) Stringtodate: (NSString*) datestr{nsdateformatter *formatter=[[nsdateformatter alloc] init]; [Formatter setdateformat:@"Yyyy-mm-dd hh:mm:ss"];return[Formatter datefromstring:datestr];}@end
Extension Girl.h (1)
////Girl.h//extension of the Oc07_ class////Created by Dllo on 15/7/24.//Copyright (c) 2015 Zhozhicheng. All rights reserved.//#import <Foundation/Foundation.h> //1. Declaration of an agreement//@protocol The key words of the agreement @protocol Marry <nsobject>//Contents of the Agreement//Declaration of the Protocol Method//Required is a method that must be implemented, which is the method that must be implemented by default//Optional is a selectable method of execution@required-(void) Makemoney;@optional-(void) Cook;@end @interface Girl : nsobject //2. Set the properties of the delegate@property(nonatomic,Assign)ID<Marry>delegate;///Two after marriage, the agreement will be formally entered into force .-(void) Getmarry;@end
GIRL.M (2) (3)
////  Girl.m//  OC07_类的扩展////  Created by dllo on 15/7/24.//  Copyright (c) 2015年 zhozhicheng. All rights reserved.//#import "Girl.h"@implementation Girl-(void)getMarry {    // 3.让代理人去执行协议里的方法    [self.delegate makeMoney];}@end
Boy.h (4)
////  Boy.h//  OC07_类的扩展////  Created by dllo on 15/7/24.//  Copyright (c) 2015年 zhozhicheng. All rights reserved.//#import <Foundation/Foundation.h>#import "Girl.h"// 4.引完头文件之后,BOY需要签订协议@interface Boy : NSObject<Marry>@end
MAIN.M (5)
//创建两个小人//    Boy *yadang=[[Boy alloc] init];//    Girl *xiawa=[[Girl alloc] init];//    //5.设置代理人//    xiawa.delegate = yadang;//    // 通过调用结婚的方法,来执行内部协议的方法//    [xiawa getMarry];
BOY.M (6)
////  Boy.m//  OC07_类的扩展////  Created by dllo on 15/7/24.//  Copyright (c) 2015年 zhozhicheng. All rights reserved.//#import "Boy.h"@implementation Boy//6.实现协议方法makeMarry-(void)makeMoney{    NSLog(@"买买买");}@end
Set up a new agent Man.h
////  Man.h//  OC07_类的扩展////  Created by dllo on 15/7/24.//  Copyright (c) 2015年 zhozhicheng. All rights reserved.//#import <Foundation/Foundation.h>#import "Girl.h"// 签订协议@interface Man : NSObject<Marry>@end
Man.m
////  Man.m//  OC07_类的扩展////  Created by dllo on 15/7/24.//  Copyright (c) 2015年 zhozhicheng. All rights reserved.//#import "Man.h"@implementation Man-(void)makeMoney{    NSLog(@"花花花");}@end
Main.m
Man *wangliqian=[[Man alloc] init];//    //设置代理人//    xiawa.delegate=wangliqian;//    [xiawa getMarry];

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Extensions for IOS oc07.2_ classes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.