小编Ami*_*Sri的帖子

performSelectorInBackground和NSOperation Subclass之间的区别

我已经创建了一个测试应用程序来运行深度计数器循环 我使用performSelectorInBackground和NSOperation子类分别在后台线程中运行循环函数.

我也使用performSelectorOnMainThread来通知backgroundthread方法中的主线程和NSOperation子类中的[NSNotificationCenter defaultCenter] postNotificationName来通知主线程更新UI.

最初这两个实现都给了我相同的结果,我能够更新UI而不会有任何问题.我找到的唯一区别是两个实现之间的线程数.

performSelectorInBackground实现创建了一个线程,并在循环完成后终止,我的应用程序线程计数再次变为1.

NSOperation子类实现创建了两个新线程并保持在应用程序中,我可以在main()函数中完成循环后看到3个线程.

所以,我的问题是为什么NSOperation创建了两个线程,为什么它没有像第一个后台线程实现那样被终止?

我有点迷惑,无法确定哪种实现在性能和内存管理方面是最佳的.

cocoa multithreading objective-c nsoperation

4
推荐指数
1
解决办法
2388
查看次数

如何使用objective-c在Finder中使文件不可见

如果可能的话,我需要使用objective-c或使用C调用在finder和spotlight中隐藏文件.

谢谢

macos cocoa file objective-c

4
推荐指数
1
解决办法
2344
查看次数

如何从后台线程更新cocoa应用程序中的UI控件

以下是.m代码:

#import "ThreadLabAppDelegate.h"
@interface ThreadLabAppDelegate()

- (void)processStart;
- (void)processCompleted;

@end


@implementation ThreadLabAppDelegate

@synthesize isProcessStarted;

- (void)awakeFromNib {
    //Set levelindicator's maximum value
    [levelIndicator setMaxValue:1000];
}

- (void)dealloc {
    //Never called while debugging ????
    [super dealloc];
}

- (IBAction)startProcess:(id)sender {
    //Set process flag to true
    self.isProcessStarted=YES;

    //Start Animation
    [spinIndicator startAnimation:nil];

    //perform selector in background thread
    [self performSelectorInBackground:@selector(processStart) withObject:nil];
}

- (IBAction)stopProcess:(id)sender {
    //Stop Animation
    [spinIndicator stopAnimation:nil];

    //set process flag to false
    self.isProcessStarted=NO;
}

- (void)processStart {
    int counter = 0;
    while (counter …
Run Code Online (Sandbox Code Playgroud)

cocoa notifications multithreading objective-c

2
推荐指数
1
解决办法
4709
查看次数

在iPhone Core Data或SQLite中存储长期数据的最佳方法是什么?

我正在开发针对3.1.3及更高版本SDK的iPhone应用.我想知道在iphone上存储用户长期数据的最佳方法,同时不会降低性能,一致性和安全性.

我知道,我可以使用Core Data,PList和SQL-Lite以自定义格式存储用户特定数据.但是,想要知道哪一个好用,而不会在不久的将来影响应用程序性能和可伸缩性.

iphone store core-data ios

0
推荐指数
1
解决办法
1554
查看次数