目前这是我的代码
NSFileManager *fileManager = [[NSFileManager alloc] init];
BOOL receiptExists = NO;
BOOL didLog = NO;
while (!receiptExists) {
receiptExists = [fileManager fileExistsAtPath:PATH];
if (!didLog) {
NSLog(@"[NOTICE]: Waiting for the file to appear...\n");
didLog = YES;
}
}
// rest of the code
Run Code Online (Sandbox Code Playgroud)
这个while循环消耗了大量资源,我确信有更好的obj-c实现.任何想法 ?
用一个窗口制作应用程序.窗口的根视图将是带有4个按钮的几个图像.这4个按钮中的每一个都将显示不同的(主)视图.每个主视图将显示其他(子)视图,每个主视图和子视图应该能够"返回"到根视图.
我做了什么(它基于Apple的ViewController项目)
我用他们受人尊敬的XIB文件创建了1 NSWindowController和4 NSViewController.
AppDelegate NSWindowController使用包含窗口和根视图的nib来分配/初始化一个对象,然后showWindow在其上调用方法.
NSWindowController有两个ivars:一个NSView表示IB中绑定的根视图,另一个NSViewController表示当前视图控制器.以下是Apple的ViewController项目如何实现它http://pastie.org/private/zmqpzgnudgovagwigal8dq
尽管如此,这对我不起作用,它只是在根视图的顶部添加视图.
如你所见,我有点迷失,随时分享你的想法!
我想将自定义对象分配给实例变量.
这是代码:
- MyController.h/.m
#import "CustomData.h"
@interface MyViewController : NSViewController
@property (retain) CustomData* theData;
- (void)aRandomMethod;
@end
@implementation MyViewController
@synthetize theData;
- (void)aRandomMethod {
NSData* rawData = [someOtherObject someOtherMethod];
// option 1
self.theData = [[CustomData alloc] initWithData:rawData];
// option 2
CustomData* _theData = [[Custom alloc] initWithData:rawData];
// option 3
self.theData = [[[CustomData alloc] initWithData:rawData] autorelease];
// option 4
theData = [[CustomData alloc] initWithData:rawData];
// ... later code calls some methods on theData or _theData, not useful here.
}
@end
Run Code Online (Sandbox Code Playgroud)
当在Xcode中运行Analyze功能时,它告诉我,对于选项1和2,有一个"泄漏的对象未被引用...",但是对于3和4没有.看来我 …