Singleton managedObjectContext [英] Singleton managedObjectContext

查看:146
本文介绍了Singleton managedObjectContext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用单例UIApplication来访问AppDelegate的managedObjectContext。但是当我写的时候

I want to use the singleton UIApplication to access the managedObjectContext of the AppDelegate. But when I write

[[[UIApplication sharedApplication] delegate] managedObjectContext]

[[[UIApplication sharedApplication] delegate] __managedObjectContext]

它不起作用。

但是这行很好用:

NSLog(@"Seeking for the AppDelegate : %@", [[[UIApplication sharedApplication] delegate] class]);

你有解决方案吗?
Niels

Do you have a solution ? Niels

推荐答案

尝试将其投射到您的实际应用代理实施中,例如

Try casting it to your actual app delegate implementation, like

 [(MyAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];

并添加

#import "MyAppDelegate.h"

位于文件顶部。

这篇关于Singleton managedObjectContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆