nsthread

Creating threads in swift?

懵懂的女人 提交于 2019-12-04 08:37:30
问题 I am trying to spawn a thread in swift. So I have this line: . . . let thread = NSThread(target: self, selector: doSomething(), object: nil) . . . doSomething is a function within the scope of the class. That line gives this error: "could not find an overload for init() that accepts the supplied arguments" What am I missing here? Ho can I create a new thread in swift? 回答1: As of Xcode 7.3 and Swift 2.2, you can use the special form #selector(...) where Objective-C would use @selector(...) :

Delaying Code Execution on OSX 10.10

荒凉一梦 提交于 2019-12-03 21:58:30
I've encountered a very strange issue that affects my code running only on OSX 10.10 systems. I've seen this anomaly occur on over 25 OSX 10.10 systems running my code, whereas the exact same code did not exhibit this behavior before upgrading (10.7). Furthermore, this issue is not 100% reproducible in that it occurs randomly ~0-5% of the time. While testing the code, nothing else critical or CPU exhaustive is occurring on the machine. Even if something else was happening, the very fact that the delays I'm experiencing are soooo ridiculously long make that conclusion seem suspicious. Anyhow,

Keep an NSThread containing an NSTimer around indefinitely? (iPhone)

六月ゝ 毕业季﹏ 提交于 2019-12-03 21:43:50
I have some web service data in my app that needs to be updated every 3 minutes. I had tried out a few approaches but got a really good piece of advise in here last week, I should not build a new thread every 3 minutes and then subsequently try and dealloc and synchronize all the different parts so that I avoided memory bug. Instead I should have a "worker thread" that was always running, but only did actual work when I asked it too (every 3 minutes). As my small POC works now, I spawn a new thread in the applicationDidFinishLaunching method. I do this like so: [NSThread

calling selector with two arguments on NSThread issue

元气小坏坏 提交于 2019-12-03 19:25:04
问题 I'd like to make a Thread with multiple arguments. Is it possible? I have the function: -(void) loginWithUser:(NSString *) user password:(NSString *) password { } And I want to call this function as a selector: [NSThread detachNewThreadSelector:@selector(loginWithUser:user:password:) toTarget:self withObject:@"someusername" withObject:@"somepassword"]; // this is wrong How to pass two arguments on withObject parameter on this detachNewThreadSelect function? Is it possible? 回答1: You need to

What is the difference between +[NSThread detachNewThreadSelector:toTarget:withObject:] and -[NSObject performSelectorInBackground:withObject:]?

十年热恋 提交于 2019-12-03 17:36:44
问题 They seem to perform a reasonably similar task: launching a new thread that performs that selector quickly and easily. But are there any differences? Maybe with regards to memory management? 回答1: Both are identical. In iOS and Mac OS X v10.5 and later, all objects have the ability to spawn a new thread and use it to execute one of their methods. The performSelectorInBackground:withObject: method creates a new detached thread and uses the specified method as the entry point for the new thread.

Risk Assessment: Using Pthreads (vs. GCD or NSThread)

雨燕双飞 提交于 2019-12-03 13:33:54
A colleague suggested recently that I use pthreads instead of GCD because it's, "way faster." I don't disagree that it's faster, but what's the risk with pthreads? My feeling is that they will ultimately not be anywhere nearly as idiot-proof as GCD (and my team of one is 50% idiots). Are pthreads hard to get right? GCD and pthreads are both ways of doing work asynchronously, but they are significantly different. Most descriptions of GCD describe it in terms of threads and of thread pooling, but as DrPizza puts it to concentrate on [threads and thread pools] is to miss the point. GCD’s value

What is meant by CoreData is not thread safe?

笑着哭i 提交于 2019-12-03 12:42:41
问题 In Obj-C, what does it mean in simple terms; "CoreData is not thread safe" OR in general what is "not thread safe" ? 回答1: @d11wtq's answer is correct only when writing your own code or designing your own APIs . It is entirely incorrect when working with a set of APIs and quite specifically wrong when working with Core Data. In the context of working with Mac OS X and iOS, thread safety must always be considered in the context of working with the system APIs. Even using, say, an NSArray means

GCD, NSOperationQueue, or create a thread manually?

余生颓废 提交于 2019-12-03 12:38:33
问题 When you use threads, do you have any preferences? In general rule, to use any of these techniques : create a new thread manually and use the run loop use NSOperationQueue or use Grand Central Dispatch and the C version with dispatch_queue? Does NSOperationQueue simplify everything, and thus is better to be used when we need to create an asynchronous function? 回答1: I'm lazy, so my philosophy is to pick the simplest solution that does everything I need it to. (I like to think this is the "lazy

How to wait in NSThread until some event occur in iOS?

狂风中的少年 提交于 2019-12-03 12:16:23
How to wait inside the NSThread until some event occur in iOS? eg, We created a NSThread and started a thread loop. Inside the thread loop, there is condition to check whether the message queue has any messages. If there is a message, then it will call the corresponding method to do some operation, else it should wait until the message queue gets populated with a new message. Is there any API or methods available to wait until some event occur? For Example NSThread *thread = [NSThread alloc]....@selector(threadLoop) - (void)threadLoop { // Expecting some API or method that wait until some

Which is the best of GCD, NSThread or NSOperationQueue? [closed]

。_饼干妹妹 提交于 2019-12-03 03:59:05
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . What's the best way of multithreading in iOS as we have three options GCD, NSThread , and NSOperationQueue ? I am confused in which