我克隆并修改了 Apple 的 iOS 项目模板,并且能够定义其方法之一,如下所示:
<key>Definitions</key>
<dict>
<key>___VARIABLE_classPrefix:identifier___AppDelegate.m:applicationdidFinishLaunchingWithOptions</key>
<string>- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIViewController *mainViewController = [[AppMainViewController alloc] init];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
self.window.rootViewController = mainViewController;
return YES;
}
</string>
代码在 AppDelegate.m 中生成得很好 但是以下内容不会生成“myMethod”
<key>___VARIABLE_classPrefix:identifier___AppDelegate.m:myMethod</key>
<string>- (void)myMethod:(NSManagedObjectContext *) managedObjectContext
{
//my code
}
</string>
如何通过模板定义将自己的方法引入到类中? 谢谢!!
最佳答案
您的方法没有出现的原因是您所做的还不够。这些模板形成了统一的层次结构。您只是给出了方法的定义。您还必须声明该方法存在。查看 templateInfo.plist 中的 Cocoa Touch 应用程序(模板的祖先),您将看到发生这种情况的位置。有一个 Nodes 数组列出了所有可能的方法。
关于iphone - 如何通过项目模板定义向 AppDelegate.m 添加方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15778925/