zoukankan      html  css  js  c++  java
  • 关于UIApplication单例传值

    由于UIApplication的是一个系统级别的单例,那么就能够省去自己创建单例的方法,将需要需要的类对象,在UIApplication单例内声明一个,通过点语法来实现单个

    需要调用的实现单例模式的类为User类

    在AppDelegate.h内声明一个User对象,通过UIApplication 来获得该对象

    AppDelegate.h

    1 #import <UIKit/UIKit.h>
    2 #import "User.h"
    3 
    4 @interface AppDelegate : UIResponder <UIApplicationDelegate>
    5 
    6 @property (strong, nonatomic) UIWindow *window;
    7 @property (strong, nonatomic)User *currentUser;
    8 
    9 @end

    AppDelegate.m文件内不需要增加任何的方法与属性

    currentUser的get与set

    User * current = ((AppDelegate*)[[UIApplication sharedApplication] delegate]).currentUser;

    ((AppDelegate*)[[UIApplication sharedApplication] delegate]).currentUser=[[User alloc]init];

    点语法前为获取UIApplication 单例对象,.currentUser为获取AppDelegate对象的currentUser属性

  • 相关阅读:
    ASP.NET Web Form(八)
    ASP.NET Web Form(八)
    软考知识点总结
    软考知识点总结
    c# 引用外部dll
    c# 引用外部dll
    ORA600 [Kcbz_check_objd_typ_1] Running a Job (Doc ID 785899.1)
    oracle创建em
    1918: 等值数目
    1917: 支配值数目
  • 原文地址:https://www.cnblogs.com/thxios/p/4828205.html
Copyright © 2011-2022 走看看