IOS _ proxy design demo, ios design demo

Source: Internet
Author: User

IOS _ proxy design demo, ios design demo

Main. m

//// Main. m // proxy design mode/* Three Use Cases of proxy design mode 1. A wants B to do something for him, and B can become A proxy for A. 2, A wants to notify B and A that something has happened, so that B can be the proxy of A. 3. B wants to listen to something that has happened to, let B become the proxy of A first proxy set mode standard 4 step 1, define A protocol 2, B wants to act as A proxy, must first comply with and implement the above protocol 3, define A member id <protocol> delegate 4 in A and assign the Instance Object of B to the member variable delegate * // Created by beyond on 14-7-25. // Copyright (c) 2014 com. beyond. all rights reserved. // # import <Foundation/Foundation. h> # import "Baby. h "# import" nana. h "int main (int argc, const char * argv []) {@ autoreleasepool {Baby * bb = [[Baby alloc] init]; bb. age = 1; bb. nanny = [[nana alloc] init]; // [bb hungry];} return 0 ;}



Protocol

BabyNannyDelegate. h

/// BabyNannyDelegate. h // proxy Setting Mode /// Created by beyond on 14-7-25. // Copyright (c) 2014 com. beyond. all rights reserved. // # import <Foundation/Foundation. h> @ class Baby; @ protocol BabyNannyDelegate <NSObject> // three methods stipulated in the babysitter agreement // feed the Baby-(void) feedBaby :( baby *) Baby; // happy Baby-(void) amuseBaby :( baby *) Baby; // pat the baby to make it fall asleep-(void) patBaby :( Baby *) baby; @ end



Baby. h

//// Baby. h // proxy Setting Mode /// Created by beyond on 14-7-25. // Copyright (c) 2014 com. beyond. all rights reserved. // # import <Foundation/Foundation. h> # import "BabyNannyDelegate. h "@ interface Baby: NSObject // if the object is strong id, it indicates that any object can be used as a nanny, as long as it complies with the nanny agreement and implements three methods in the Protocol @ property (nonatomic, strong) id <BabyNannyDelegate> Nanny; @ property (nonatomic, assign) int age;-(void) cry; // baby crying-(void) sleep; // baby wants to sleep-(void) hungry; // baby wants to eat milk @ end



Baby. m

//// Baby. m // proxy Setting Mode /// Created by beyond on 14-7-25. // Copyright (c) 2014 com. beyond. all rights reserved. // # import "Baby. h "@ implementation Baby-(void) cry {NSLog (@" % d years old Baby... cry ", _ age); // call the method of happy baby in the proxy [_ Nanny amuseBaby: self];}-(void) sleep {NSLog (@ "% d years old baby... want to go to bed ", _ age); // call the method in the proxy to beat the baby to make it fall asleep [_ Nanny patBaby: self];}-(void) hungry {NSLog (@ "% d years old baby... want to eat milk ", _ age); // call the method in the proxy for feeding the baby [_ Nanny feedBaby: self];} @ end




Nanny nana. h

//// Nana. h // proxy Setting Mode /// Created by beyond on 14-7-25. // Copyright (c) 2014 com. beyond. all rights reserved. // # import <Foundation/Foundation. h> # import "BabyNannyDelegate. h "// if nana wants to take care of a baby now, she must abide by the babysitter agreement and implement the method @ interface nana: NSObject <BabyNannyDelegate> @ end



Nanny nana. m

//// Nana. m // proxy Setting Mode /// Created by beyond on 14-7-25. // Copyright (c) 2014 com. beyond. all rights reserved. // # import "nana. h "# import" Baby. h "@ implementation nana-(void) feedBaby :( Baby *) baby {NSLog (@" nana is breastfeeding % d ", baby. age);}-(void) amuseBaby :( Baby *) baby {NSLog (@ "Nana is yelling at % d-year-old baby happy", Baby. age) ;}- (void) patBaby :( Baby *) baby {NSLog (@ "Nana is gently tapping % d-year-old baby to fall asleep", Baby. age) ;}@ end














How to Set up a proxy server on ios

Well
 
I am a beginner in ios development and want to learn some demos.

After XCode is downloaded,
Then download its offline help.

There are actually a lot of DEMO projects in the help.

Related Article

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.