File Manager and design mode-singleton mode and file manager Design Mode

Source: Internet
Author: User

File Manager and design mode-singleton mode and file manager Design Mode

# Import <Foundation/Foundation. h> # import "User. h "/* 1. file Manager simple Singleton mode */int main (int argc, const char * argv []) {// File Manager // It is generally not used // NSFileManager * fileManage = // [[NSFileManager alloc] init]; NSFileManager * fm = [NSFileManager defamanager manager]; NSLog (@ "% p", fm ); // create a singleton object // the lifecycle of the singleton object is from the start of the function to the end of the function NSFileManager * fm1 = [NSFileManager defaultManager]; NSLog (@ "% p ", fm1); User * user1 = [User defaultUser]; NSLog (@ "% p", user1); user1.age = 10; NSLog (@ "% p age: % d ", user1, user1.age); User * user2 = [User defaultUser]; NSLog (@ "% p age: % d", user2, user2.age); NSLog (@ "% p ", user2); return 0 ;}
#import <Foundation/Foundation.h>@interface User : NSObject{    int _age;}-(void)setAge:(int)age;-(int)age;+(User *)defaultUser;@end
# Import "User. h "static User * instance = nil; @ implementation User-(void) setAge :( int) age {_ age = age ;}- (int) age {return _ age ;} + (User *) defaultUser {// determines whether the object is null if (instance = nil) {// if it is null, initialize instance = [[self alloc] init];} return instance;} @ end



Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.