|
How can I do something like this with GCD? Bad pseudocode follows. Sorry it's messy, but my actual code is messier, so I've spared you and me that disgrace. EDIT for 'clarity' dispatch_async(queue, ^{ for item in arrayOfItems { [item doAwesomeCoolAsynchronousMethodOnABackgroundThreadOnEachItem] dispatch_async(dispatch_get_main_queue(), ^{ [do something after each item loads with my mbprogress hud to update progress loading animation on the main thread]; }); } } What's happening is the iterator is looping through all my items. But the instance method on each item which runs in a background thread is getting called on each item and my app only jumps to the main thread to update my "progress loading animation" after all the items have finished their way through my for loop. Is there a way to call a UI method on the main thread after each individual item runs through the iterator? Here's what my log looks like. Current Record is being logged after each record is processed. However, the second set of log statements are being logged from inside the for loop but are happening on the main thread. -- those floats show the progress loader percentage that should be updating my loader animation. But it's all happening at once, after all my items load. 2013-03-20 22:52:43.866 Game Alert[13425:c07] FINSHED JSON GET 2013-03-20 22:52:43.867 Game Alert[13425:c07] Current Record:1 2013-03-20 22:52:43.868 Game Alert[13425:c07] Current Record:2 ... 2013-03-20 22:52:43.877 Game Alert[13425:c07] Current Record:14 2013-03-20 22:52:43.878 Game Alert[13425:c07] Current Record:15 2013-03-20 22:52:43.879 Game Alert[13425:c07] 0.066667 2013-03-20 22:52:43.879 Game Alert[13425:c07] 0.133333 ... 2013-03-20 22:52:43.883 Game Alert[13425:c07] 0.933333 2013-03-20 22:52:43.884 Game Alert[13425:c07] 1.000000 plasticbugs fucked around with this message at 07:35 on Mar 21, 2013 |
# ? Mar 21, 2013 07:14 |
|
|
# ? May 22, 2024 11:37 |
|
What's the awesome cool asynchronous method? Maybe you can modify that method to pass in a completion handler, which dispatches back to the main thread to update a progress animation. For more elegance, but maybe more work, have a look at dispatch sources.
|
# ? Mar 21, 2013 07:59 |
|
pokeyman posted:What's the awesome cool asynchronous method? Maybe you can modify that method to pass in a completion handler, which dispatches back to the main thread to update a progress animation. I'm hitting my S3 bucket to download and store an image for each item into core data. I'd like to show download progress as the operation takes 20 seconds or so. Thanks for the help!
|
# ? Mar 21, 2013 16:10 |
|
Just a tip, you can use code tags, makes it easier to read:Objective-C code:
|
# ? Mar 21, 2013 19:27 |
|
Carthag posted:Just a tip, you can use code tags, makes it easier to read: Won't that block the main thread, causing the UI to lock up as each item is downloaded? This is all very new to me. Everything I know about GCD I learned from the CS193p Stanford class on iTunes U.
|
# ? Mar 21, 2013 20:53 |
|
plasticbugs posted:Won't that block the main thread, causing the UI to lock up as each item is downloaded? This is all very new to me. Everything I know about GCD I learned from the CS193p Stanford class on iTunes U. You're right that doing UI updates from off the main thread is a bad idea. I generally do a variation of this when I have a long queue of things that I want to process in the background: Objective-C code:
E: The important thing I guess is to wrap UI updates in the async/main_queue thing when you're working off-main. E2: VVV Doy. Fixed! Thanks pokeyman. So it goes when cutting & pasting and replacing with comments E3: There, that looks better. It's 10 pm, no more writing objc in a webform for me today! Carthag Tuek fucked around with this message at 21:48 on Mar 21, 2013 |
# ? Mar 21, 2013 21:20 |
|
edit: fixed above
pokeyman fucked around with this message at 02:12 on Mar 22, 2013 |
# ? Mar 21, 2013 21:30 |
|
Can somebody help me make sure I've got a halfway sane plan please? I'm converting a sort of finished AppleScript project to an Objective-C app to help me learn Obj-C/OS X programming. It's a simple developer tool for processing clipboard text with Ruby. When launched it prompts the user for a line of Ruby code which is run on the clipboard contents. The output is then copied back to the clipboard. Right now this is done via the shell, pbpaste, pbcopy, and ruby. In moving to Objective-C, apart from using NSPasteboard, I want to embed the ruby interpreter (written in C). Communicating with the interpreter is what I'm least sure of how to approach. From what I've read, I think I should be looking at newer technologies like GCD or XPC (via NSXPCConnection) rather than just threads. GCD seems like it might be the quicker/easier route, but also more limited. When embedding ruby, there is some setup involved. Am I correct in thinking that GCD would require doing the setup on every call to ruby? With the interpreter as an XPC service, I'd have a background process running where I could do the ruby setup once and then wait to hear from the main application. An XPC service would also allow for sandboxing and a more plugin-like architecture which might be good if I want to add something in addition to Ruby in the future. Am I basically headed the right direction? Any recommendations or other advice?
|
# ? Mar 22, 2013 00:14 |
|
Wrap the "Ruby interpreter" into an object with a simple interface. Then, to get started, implement it by simply shelling out to the installed ruby. Once that works, you can work on compiling the interpreter yourself.Objective-C code:
|
# ? Mar 22, 2013 02:32 |
|
Carthag posted:You're right that doing UI updates from off the main thread is a bad idea. That's virtually what my code looks like, except I'm working with my document's managed object context, which I understand was created on the main thread. Is that what's screwing me up? Can I not save objects to core data in a background thread this way? Thanks for the help. Here's my actual code: Objective-C code:
|
# ? Mar 22, 2013 06:51 |
|
Using the context outside of the thread where it was created is an immediate red flag. You can use performBlock to let the system make sure your managedObjectContext is used on the "correct" thread. Writing multithreaded behavior with the MOC requires some understanding. If you decide to look into it, please share. Otherwise, you will probably need to use it on the main thread. code:
Jam2 fucked around with this message at 12:09 on Mar 22, 2013 |
# ? Mar 22, 2013 12:07 |
|
Another option is to create a child context and use that in the thread, then merge it back up into its parent when you're done. I think that's how it goes, haven't tried it myself.
|
# ? Mar 22, 2013 12:27 |
|
pokeyman posted:Wrap the "Ruby interpreter" into an object with a simple interface. Then, to get started, implement it by simply shelling out to the installed ruby. Once that works, you can work on compiling the interpreter yourself. I implemented an object that compiles/links ruby and then uses it via fork & pipes (though maybe I should have used NSTask). I just wanted to make sure I was right in thinking I should look at GCD or XPC for the actual application. From what I've read, the fork implementation won't be safe once I'm using Cocoa and other frameworks. I'm thinking I'll learn more from creating an XPC service so I'll probably go that route. Thanks.
|
# ? Mar 22, 2013 14:24 |
|
Is there some reason I am unable to find a clear example of retrieving the mobile number from an ABPersonRef? Seems like that would be an extremely common task, but every example I've seen starts going a bunch of weird places I don't understand. This can't be that complicated, right?
|
# ? Mar 22, 2013 16:48 |
|
Carthag posted:Another option is to create a child context and use that in the thread, then merge it back up into its parent when you're done. I think that's how it goes, haven't tried it myself. Yes; init the main context with the appropriate threading model, then the child MOC can be created (but only on the child thread!). When the child is "saved", it just forwards its changes on to the parent. I think I posted about this earlier in the thread but the pattern also works to allow easily discarding changes if the user cancels out of a screen. The threading model of CoreData is... Non-intuitive, but Apple has made some improvements. I'm hoping they can make more as time goes on. Of course I wish iCloud CoreData was worth using too so YMMV. Pro-tip: don't use iCloud CoreData. You'll regret it.
|
# ? Mar 22, 2013 16:56 |
|
In the past, I've gotten a decent amount of experience with RAD (thus, Eclipse) under my belt with a fair amount of Java/C/Perl coding. Now I'm tooling around with Xcode, and there are a few things about RAD that I'm trying to figure out how to do in Xcode, or if Xcode can do them at all. Overall, I'm rather happy with Xcode, though; it seems like a good IDE. The first and biggest is in RAD, when I mouse over a method or a variable, it'll give me a tooltip of comments for it. I know about holding alt for methods in Xcode, but that only seems to work with Apple-provided stuff, not my own. Is there a special comments format I'm missing or something? Or does Xcode just not do this--and if not, any particular reason? Another small thing in RAD is that if I'm typing away at a method and happen to refer to a class that I haven't yet imported, when I mouse over the class name (which has a warning on it), it's smart enough to know that the class is either one in my project or a standard Java one, and give me the option to just put the import in for me--or create a new class with that name. It also has some of these smarts with methods and variables. So far, I haven't figured out a way to do this sort of automation in Xcode, or is it just not there yet? Also, with RAD if I have something selected, I can hit F3 and it'll pop over to the definition of that method/variable, which is really useful for tracing through code. Is there an equivalent shortcut key in Xcode? (I've looked through the menus to no avail) The last little thing is that with block comments, if I start a line with my /* and hit enter, it automatically builds the block for me: code:
And lest people thing I'm berating Xcode, I will say I really do like it as an IDE. The autocomplete is so much better than RAD's in my opinion, and the way its logging works is pretty slick. I really am enjoying it, there's just a few environment things that have been a little jarring.
|
# ? Mar 23, 2013 01:00 |
|
Axiem posted:Also, with RAD if I have something selected, I can hit F3 and it'll pop over to the definition of that method/variable, which is really useful for tracing through code. Is there an equivalent shortcut key in Xcode? (I've looked through the menus to no avail) Command-click on the method/variable (or class/type).
|
# ? Mar 23, 2013 01:05 |
|
Axiem posted:The first and biggest is in RAD, when I mouse over a method or a variable, it'll give me a tooltip of comments for it. I know about holding alt for methods in Xcode, but that only seems to work with Apple-provided stuff, not my own. Is there a special comments format I'm missing or something? Or does Xcode just not do this--and if not, any particular reason? I've never seen Xcode do this. My understanding is this info comes from installed documentation. You can add other documentation (some third-party libraries do this) in the Preferences, under Downloads then Documentation. quote:the option to just put the import in for me--or create a new class with that name. It also has some of these smarts with methods and variables. So far, I haven't figured out a way to do this sort of automation in Xcode, or is it just not there yet? Haven't seen Xcode do this either. quote:The last little thing is that with block comments, if I start a line with my /* and hit enter, it automatically builds the block for me: Again, haven't seen it. quote:And lest people thing I'm berating Xcode, I will say I really do like it as an IDE. The autocomplete is so much better than RAD's in my opinion, and the way its logging works is pretty slick. I really am enjoying it, there's just a few environment things that have been a little jarring. This is certainly higher praise than Xcode tends to get. There are unofficial Xcode plugins if you search around. I haven't come across any that fix your specific problems, but a) I haven't looked very hard for plugins in general and b) maybe you can hack one up. I've seen a few on GitHub at least. If you're looking for alternative Objective-C IDEs for Apple stuff, the only real contender I'm aware of JetBrains's AppCode. If you get sour on Xcode, have a look.
|
# ? Mar 23, 2013 03:18 |
|
You can open the inspector tab or whatever, and click a thing, and the tab will show you the definition if you have it in your docs. I dunno, XCode is kindof a mess. 3 wasn't so hot, but they took out a lot of stuff to make 4, and are bringing it back piecemeal.
|
# ? Mar 23, 2013 04:25 |
|
gooby on rails posted:Command-click on the method/variable (or class/type). Awesome! That's what I was looking for. Thanks. Carthag posted:You can open the inspector tab or whatever, and click a thing, and the tab will show you the definition if you have it in your docs. Ah, I hadn't noticed that because I'm on a tiny-rear end screen so I leave the right sidebar off. That's good to know, though it also seems to have the limitation of only going with the official documentation pokeyman posted:I've never seen Xcode do this. quote:Haven't seen Xcode do this either. quote:Again, haven't seen it. That's what I was afraid of. It'll take a while to get used to, I guess. quote:There are unofficial Xcode plugins if you search around. I haven't come across any that fix your specific problems, but a) I haven't looked very hard for plugins in general and b) maybe you can hack one up. I've seen a few on GitHub at least. Cool, I didn't know about the plugins thing (though in retrospect, that makes sense). I'll have to dig a little to see if I find anything that does what I want. Though I might look into writing one or two myself, if it's not too difficult. Why do people get so down on Xcode? It seems like a pretty good IDE.
|
# ? Mar 24, 2013 00:50 |
|
Mostly because they're comparing it to Visual Studio. It's a very Apple product- if you're doing it their way, it's like a dream, but if you're trying to adapt it to your way you constantly run into pitfalls and frustrations. I still miss multiple window mode.
|
# ? Mar 24, 2013 00:53 |
|
How is XCode's built-in unit testing framework?
|
# ? Mar 24, 2013 03:56 |
|
Axiem posted:Why do people get so down on Xcode? It seems like a pretty good IDE. It's also way worse than it used to be, in a couple of respects, IMO. Crash-happy and chugs with Interface Builder integrated in. Thanks to LLVM, though, much better autocomplete, though.
|
# ? Mar 24, 2013 04:52 |
|
Jam2 posted:How is XCode's built-in unit testing framework? Entirely adequate.
|
# ? Mar 24, 2013 05:33 |
|
Axiem posted:Why do people get so down on Xcode? It seems like a pretty good IDE. I'm not sure, it seems to have trailed off around Xcode 4. Legitimate grievances, I mean. There's never a shortage of opinion or unhelpful comparisons.
|
# ? Mar 24, 2013 05:42 |
|
Most of my bitching has moved from Xcode in general to just LLDB. It was doing pretty well in the second to last release, but now it frequently decides to freeze for 2+ minutes at a time if you so much as look at the interactive console. I also have to run fuxcode at least three times a day in the latest release to unbreak something, usually Xcode refusing to copy nibs or pngs to the bundle. It just wouldn't be Xcode if some feature wasn't completely broken in each release.
|
# ? Mar 24, 2013 09:34 |
|
I'm pretty satisfied with it. I just realized that I've only had one crash in recent memory. There was a time I could consistently make it crash, usually in IB. I wish Xcode automated some common advanced tasks, such as creating a framework for embedding in the app--I never remember the build settings I need to configure--or sharing a group among multiple projects in a workspace. Feature requests already filed (and determined to be dupes).
|
# ? Mar 24, 2013 11:04 |
|
I almost never have problems with Xcode, but then again I don't do anything too weird with my build settings and I don't try to make Xcode behave like other IDEs. My Mac also has 8GB RAM, which helps with memory hogs like Xcode. Some people apparently stuck with the base 2 or 4GB configurations when getting their Macs. I do run Build Clean, close Xcode, run fuxcode, then reopen Xcode before doing an App Store build, though. Just In Case.
|
# ? Mar 24, 2013 14:51 |
|
TC-11 update is done (w0000000t). Now time to press (Choose File...) 60 times on iTunes Connect to upload the new screenshots!
|
# ? Mar 24, 2013 15:59 |
|
lord funk posted:TC-11 update is done (w0000000t). Now time to press (Choose File...) 60 times on iTunes Connect to upload the new screenshots! 180 screenshots here my friend; I feel your pain and then some.
|
# ? Mar 24, 2013 23:59 |
|
Ender.uNF posted:180 screenshots here my friend; I feel your pain and then some. This is so frustrating. If the only thing announced at WWDC is that iTunes Connect has been made sensible it will be the best WWDC of all time.
|
# ? Mar 25, 2013 00:24 |
|
Ender.uNF posted:Yes; init the main context with the appropriate threading model, then the child MOC can be created (but only on the child thread!). When the child is "saved", it just forwards its changes on to the parent. If you use the appropriate threading model — private queue concurrency — when you create an NSManagedObjectContext, you don't need to worry about which thread you create it on. The general pattern to use is to have a "primary" context initialized with private queue concurrency, then to have one or more child contexts using main queue concurrency for your UI. That way you can do saves, fetches, etc. from your persistent store without blocking your UI easily. You can also have one (or more) child contexts using private queue concurrency for other purposes, such as synchronizing with a web service; again, this lets you do much of the work without blocking either the UI or interaction with your persistent store. One caveat is that before saving changes in a child store, you'll want to obtain permanent IDs for any inserted objects. That way you won't have to do your own temporary-to-permanent-ID mapping when propagating changes between parts of your app. That's one trivial pair of methods on the context though, in advance of the save.
|
# ? Mar 25, 2013 02:00 |
|
rjmccall posted:It's definitely a bug; thanks for the report. Indeed! (Also, there's always the implicit "just because someone works at a company doesn't mean they speak for that company" disclaimer.)
|
# ? Mar 25, 2013 02:07 |
|
Ender.uNF posted:180 screenshots here my friend; I feel your pain and then some. At the very least it would be great if you could shift-click multiple files to upload. Or not have to wait while the thumbnail is generated. But yeah, at least it isn't a universal app.
|
# ? Mar 25, 2013 20:35 |
|
I've got a question about scrollViews, paging, and outlets. I'm making an app that allows the user to page back and forth between screens. Each screen contains the same fields, currently some labels. in the view controller that's holding the uiscrollview, I want to be able to access the screen currently showing's IBOutlets, then when a new screen is paged out, the VC's connections are updated to the new screen's. How do I do that?
|
# ? Mar 25, 2013 23:21 |
|
Make the VC the owner of a newly loaded copy of the nib? The load process should remake all the connections once you drop the old screen.
|
# ? Mar 25, 2013 23:47 |
|
Aaand it's finally out! It's a relief to finally see it up on the app store after waiting for so long.
|
# ? Mar 26, 2013 19:26 |
|
Congrats! Also, you got mentioned on The Loop so hopefully that will give you a lot of sales.
|
# ? Mar 26, 2013 20:38 |
|
Gordon Cole posted:Aaand it's finally out! It's a relief to finally see it up on the app store after waiting for so long. Man, that really confused me for a second. I thought Chromatik had some dark horse spinoff product, but then I remembered they had a 'k' at the end of their name. Also that app looks pretty slick. Nice work!
|
# ? Mar 26, 2013 22:28 |
|
|
# ? May 22, 2024 11:37 |
|
Doc Block posted:Congrats! Also, you got mentioned on The Loop so hopefully that will give you a lot of sales. Thanks! I just saw that...it seems like it's getting a pretty good response so far. I've been trying to get coverage from blogs but haven't gotten much of a response from them so far unfortunately. It seems pretty tough to market an app as a new developer. ultramiraculous posted:Man, that really confused me for a second. I thought Chromatik had some dark horse spinoff product, but then I remembered they had a 'k' at the end of their name. Whoa...weird. I suppose I have "Labs" at the end of my name as well so the name's at least not identical. The similarity is kind of unfortunate though.
|
# ? Mar 26, 2013 22:41 |