Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
So everyone who can should check out automatic reference counting, because it looks fantastic. It's like fake garbage collection! (I say this based entirely on the commit to the public llvm repository and in no way on anything under NDA.)

Adbot
ADBOT LOVES YOU

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

rjmccall posted:

Just to be clear, ARC itself is no longer under NDA, q.v., so you can run wild.

Awesome! Run wild I shall.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Choadmaster posted:

Interesting, but it looks to me like a "solution" to a nonexistent problem that only serves to increase complexity.

The most obvious existent problem this helps solve is the lack of garbage collection on iOS.

quote:

Memory management is very simple and straightforward to begin with.

Yet it's surprisingly hard to consistently do right, and is frequently a source of confusion for newcomers to the platform. (See the number of tired repostings of the memory management guide in this and previous threads.)

It's not clear to me whether someone could soon write a nontrivial iOS/OS X app without writing a single retain. Like you point out, I'm not sure how much of an advantage it is to go from "always retain/release/autorelease like this" to "well sometimes you have to add this in here but normally it's ok". If we can somehow get all the way to "don't worry about it", that sounds ideal.

(Also, reading the ARC document on the Clang site, I wonder if this is what rjmccall had in mind during the earlier discussion on exceptions...)

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Carthag posted:

Edit: Are there any good blogs/books on how to best write Cocoa-like Objective-C? I seem to come up against this sort of thing often, where I'm writing something, and it just doesn't seem very Cocoa...

If you have a developer account, check out some videos from past (especially 2010) WWDC sessions. Many sessions are quite full of sample code that's written Cocoa-like, and there are even sessions specifically about making your code Cocoa-like. (One that comes to mind is a session last year that was about how Cocoa methods are named.)

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Carthag posted:

Thanks, I just signed up for a free one. I guess the "Session 138 - API Design for Cocoa and Cocoa Touch" video is the one you're talking about?

Yup, and that's definitely not the first time I got the name horribly wrong.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Doc Block posted:

Is it normal for the root view controller's viewDidLoad method to be called before the app delegate's application:didFinishLaunchingWithOptions: method?

That sounds abnormal but not impossible, especially if the root view controller is in your main nib file. Do you have a problem triggered by the ordering of the calls, or are you just curious?

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Small White Dragon posted:

WWDC 2011 videos are up.

And just so we're all clear, all you need is the free developer account to watch the videos. So do it.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

wolffenstein posted:

Does this mean the WWDC NDA is gone?

As far as I know it's replaced with the Developer NDA, so you still can't talk about session contents on a forum such as this one.

The rule of thumb I use: if I don't need to log in to see Apple's page/docs about it, I can probably talk about it. IANAL etc. but that's my thinking.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Vinlaen posted:

What are some popular (?) options for developers not wanting to code in Objective-C?

Check the OP.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Yakattak posted:

I feel like its harder to go through all the loops and bounds to not use Objective-C, than it is to learn and use Objective-C.

You can get pretty far learning just enough to translate library calls in the docs to your language of choice. Though I'd argue one's understanding of how to use said libraries benefits enormously from understanding its native and targeted languages.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Bob Morales posted:

How would you accomplish a custom view (or whatever it would be called) like the 'downloads' window in Firefox?

I'll assume you're just interested in the view part, and none of the possible implementation details.

Well, it's its own window, so I'd start with a subclass of NSWindowController. There's two main parts: the scrollable list of downloads and the little status bar at the bottom. Easiest first: the status bar is just (in order) a label, an NSPathControl, then a standard push button.

For the lits of downloads, I'd use an NSCollectionView. For its Item, the view has an image view (for the icon), two labels (for the filename and done/percentage), then two hyperlink buttons (make your own or grab from e.g. BWToolkit).

This can all be done in nibs, and if you end up using bindings there's very little code that needs to be written at all. I'll go a bit into implementation: have your window controller subclass maintain an array of paths, then plug it into an NSArrayController. Bind the collection view to the array controller, then bind each part of the item view (icon, filename, etc.) to the item itself. Here's where you write a bit of code: implement icon and filename properties on the collection view item that derives their values from the path (make sure to use keyPathsForValuesAffectingValueForKey:) , then implement a couple IBActions for the open and remove links that just hands the path off to NSWorkspace or the array controller.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

stray posted:

The problem is this: when you tap an entry in the BranchListing view to see that particular BranchDetail view, the "back" button is present. However, there's no "back" button on the BranchListing view to go back to the RootView. In short, it's a one-way trip, once you tap the RootView's "branch listing" button; there's no going back.

When you push the branch listing on to the navigation stack, the back button should show up for you automatically. Are you sure you're sending -pushViewController:animated: to the UINavigationController? Is the RootView properly set as the root view controller of the UINavigationController?

Feel free to post some code for us to help you with.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Looks fine to me, and I can't think of any other bright ideas.

I noticed in iOS 5 there's a note about leaving the title property of the view controller empty and that that's ok, but the same note is missing in the iOS 4 docs. Did you try setting a title like Echo Video suggested?

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Echo Video posted:

I had to revise my post - it's not due to having the title of the view controller not set, it's having title of the navigationItem for the view controller not set. I have this line:

code:
self.navigationItem.title = @"My Fridge";
in my viewDidLoad method for my root view controller (it should probably go in initWithNibName). Without that line, nothing shows up for the title in the navigation bar and no back button is present when a new view controller is pushed onto the navigation stack. This is in iOS 4.3.

e: just tested if self.title works as well as self.navigationItem.title , it does.

That's really good to know, thanks for trying it out. Dunno if it fixes stray's problem but I could see myself getting tripped up by this.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

chaosbreather posted:

Since the whole of the window is a WebView, I have reason to believe that perhaps it is this WebView or a sub-view such as FrameView that is not only claiming itself first responder but is not letting my window controller have a crack at them like some jealous garden snake.

Test this out by instantiating an instance of your window controller without a web view.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Flobbster posted:

Is there something wrong with UIKeyboardTypeNumberPad?

On the iPad it's the full keyboard set to the mode that has numbers on one row, so you get a bunch of other poo poo alongside the numbers.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

lord funk posted:

I've got a view updating problem. I have a method in my view's delegate that updates some slider colors, which works as expected (the user interacts with the interface, the other sliders update to reflect the change).

Post some code.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Nothing obvious jumps out at me. Are you sending messages to views from the main thread?

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

KidDynamite posted:

So when working with foundation in Xcode 4

code:
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
...
[pool drain];
is replaced by
code:
@autoreleasepool {
  ...
}

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

carry on then posted:

Are there any good guides (in the Apple documentation or otherwise) for creating GUI applications for OS X, especially with advice on how to structure the controllers, how to get controllers talking to each other, and other design patterns?

Check out the Cocoa Design Patterns section of the Cocoa Fundamentals Guide for a start.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

stray posted:

I've got this big dictionary in a plist of addresses, phone numbers, etc. I'm accessing it through a standard UINavigationController / UITableViewController setup, but there might be modes of the app where we want to open that data from whatever view we're in.

So essentially: how do I create a view controller that takes/requires a parameter to instantiate correctly?

Subclass UIViewController, make a new init method (and label it the designated initializer so others know), then override UIViewController's designated initializer to call yours. So:

code:
@interface MyViewController : UIViewController

// Designated initializer.
- (id)initWithAddresses:(NSDictionary *)addresses;

@end
code:
@implementation MyViewController

- (id)initWithAddresses:(NSDictionary *)addresses
{
  self = [super initWithNibName:nil bundle:nil];
  if (self) {
    // ...
  }
  return self;
}

- (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)bundle
{
  return [self initWithAddresses:nil];
}
And if you really don't want your view controller instantiated without the dictionary, throw an exception in your overridden -initWithNibName:bundle:.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
I got curious tonight and looked around for a bit to see if there's any consensus about how to implement -dealloc. The questions I was curious about were:

1. Is there any point to niling out instance variables after releasing them?
2. Can I use accessors (e.g. self.something = nil) instead of releasing directly?

The only relevant Apple documentation I came across says

Apple posted:

Typically in a dealloc method you should release object instance variables directly (rather than invoking a set accessor and passing nil as the parameter) ... If you are using the modern runtime and synthesizing the instance variable, however, you cannot access the instance variable directly, so you must invoke the accessor method

Which contains incorrect information (you can in fact directly access a synthesized instance variable and have been able to for awhile). I also came across a blog post from last year by Jeff LaMarche, Daniel Jalkut's response, and a StackOverflow question from Dave DeLong. In case any of those names are unfamiliar, they're all people who should know the answer, yet everything I've linked seems to say something different.

So I guess I'm wondering if anyone has come across a definitive explanation for what works best and why?

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

rjmccall posted:

Please file a bug against the documentation; that's old information.

Done.

quote:

dealloc words

Thanks for clearing that up. I kind of wish there was a constantly-updated quick reference list to things like this. "Do this in dealloc, here's why"; "yes, you should assign to self in an init method"; and so on.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

newreply.php posted:

backing out of core data managed object creation

Fundamentally, what you're trying to do (I think) is:

1. Make a new instance of a managed object.
2. Let the user dick around with it.
3. If they hit 'save', keep it. If they back out entirely, lose it.

The idiomatic way to do this is to instantiate a new managed object context, then insert your new managed object into this 'scratchpad' context. If you decide you want to keep the new object (user hits 'save'), merge the changes into your main managed object context. If you choose instead to forget about the new object, just reset the scratchpad context.

There's a section of the Core Data Programming Guide that talks about this kind of thing, and check out the sample code project "CoreDataBooks" for an example of how to do exactly this.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

newreply.php posted:

It seems terribly convoluted when compared to Java/.NET ORM's though, first time I've encountered something that doesn't seem intuitive at all in CocoaTouch.

For what it's worth, Ender.uNF's suggestion of just deleting the object should work too. My (thankfully limited) experience with NSFetchedResultsController has led me to believe that you're best off letting the managed object context and fetched results controller figure poo poo out themselves and to stay out of their way. (And this is why I've stopped using NSFetchedResultsController.)

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Mighty Zoltar posted:

Short version - can i create hyperlinks that would open something like goodreader with a specific document opened within it?

What Lumpy said, though if you're trying to link to someone else's app, you're at their mercy. If they ever change their URL scheme, your links stop working. If you're talking about an app you control, then obviously you can handle that.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Mighty Zoltar posted:

Thats pretty much wha i wanted to hear, and it would be for my own app.

Final question on this i think - could i have an app create a html link which looks how i want (small webpage image for example), which the app then saves to the app main ipad/iphone app screen, then open the right area of the app on open?

Again using the goodreader example, i make a doc, ask for it to save as a quick link, where it drops a html link icon on the homescreen, shows a preview pic of the doc, and open the doc on a press?

You'll need to do this through Safari, instructing the user to save a link to the home screen. You can set its icon there through a <link> tag.

Unless you don't plan on distributing your app through the app store, in which case you can check out the UIWebClip class and the web clip methods on UIApplication.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
I can't figure this thing out about a table view cell's editing accessory view. I've made a little project to show off the issue I'm having. If you have a minute, could you run it in the simulator for me? Selecting a cell toggles its editing state if you want to play with it.

In words, the problem I'm having is some weird animation in a UITableViewCell's editingAccessoryView on the first time the cell enters editing mode. I've found a workaround but I'd like to understand what's going on.

If you run the app in the project, you'll see a table view. Edit it. Each cell has a round rect push button for an editingAccessoryView, which should slide in when entering edit mode. Watch the animation closely! The first time you hit the edit button, the rows without the workaround have the button's title slide in from the top, while the rows with the workaround slide in as expected. And it's only the first time entering edit mode; each subsequent time, you see the normal animation.

Can anyone see why this is happening?

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

OHIO posted:

I don't know if that's helpful. Something about the button title's frame not being created at first?

Good catch. I think what's happening is the UIButton's titleLabel's frame isn't set until it's accessed, or until the button appears on screen. The title label is set as a subview of the button as soon as it's created, but its frame starts at zero.

In other words,
code:
UIButton *button = [UIButton buttonWithStyle:whatever];
[button titleLabel];
makes a button that doesn't have its label animating in weirdly.

I just assumed that whatever initialization that goes on here would occur on the first invocation of -setTitle:forState:. Thinking about it more, maybe it's done this way so the label can be given a size that fits the longest title set for the button? (Though isn't that what -sizeToFit is supposed to accomplish?)

Anyway, I'm much happier with this getter workaround, so thanks for having a look.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Sinestro posted:

http://pastie.org/2393496 is the .m, the .h is stock.

Pretty sure you're leaking your UIWindow there. Otherwise nothing looks fishy. Can we see ForumListViewController?

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Sinestro posted:

links I stupidly missed

Sorry!

I just grabbed your code and threw it into a new project and it works no problem, though obviously I'm faking the number of sections, number of rows, and their contents. What's the number of sections you're reporting to your table view?

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

nolen posted:

So I attempted to start a new test project and run it in the Simulator immediately. 13 errors and I haven't even touched a line of code? What the gently caress is this bullshit?



I've googled around a bit but can't find anything other than "reinstall 10.7 and try again". Please tell me that isn't the solution. I really really really shouldn't have to wipe my OS just to install this hosed up version of the developer tools...right?

Well, the errors all seem to stem from whatever build process not having permissions for the files/directories it needs to use. So: is your ~/Library folder owned by you? (chown -R or Get Info.) And can you try closing Xcode, deleting ~/Library/Developer, then opening Xcode again?

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

2nd Rate Poster posted:

Can someone recommend a good merge tool that is not filemerge?

git

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Is there any point to implementing -dealloc in an app delegate? It's seemingly never called, which makes sense because why bother calling it if the process is about to die anyway, but then I'm pointlessly implementing it. Literally dead code that I have to keep up. And it's painful enough having to declare properties three times.

ARC can't get out of beta soon enough.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

lord funk posted:

I must have downloaded this example project, and now this pops up every time I open another project. I've deleted the repository again and again, but it always comes back. Where is this POS living?



Check out the organizer, I think there's lists of projects and/or repositories. Try deleting anything that looks relevant to that dialog box.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

lord funk posted:

Is there a good way to determine the exact model iPad at compile time (1 or 2)? I need to change some things to optimize between the two, and I'd rather do it at compile time than runtime.

As Small White Dragon says, both iPads load and run the same code. They won't differentiate.

I feel like you should actually ask your question about what you're trying to do.

quote:

If it needs to be runtime, is there a better solution than this StackOverflow answer?

Sure: check for the presence of features you need, e.g. whether a camera is present, or some amount of video memory.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

SeventySeven posted:

I've thrown my entire project up at http://www.mediafire.com/?ddnyjx2wof6cia7 and I was hopeful one of you fine folk could tell me what's gone wrong. As you can see from the quality of the app I'm still very much just playing around and learning.

I can't speak for anyone else, but this is normally a pretty helpful (and quick) thread, and I notice nobody's tried to help you out yet. Personally, I skipped over your query because "what's wrong?" is far too general a question. If you can do a bit more legwork in figuring out what's wrong (such as "I get this error message" or "I expect to see X when I do Y but I see Z instead", and/or narrow down which part of your project seems to have the problem, I'd feel more willing to help.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
I'm guessing it's to reflect the default behaviour of NSLocalizedString of simply returning the key if it doesn't find it in a string table.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

GazChap posted:

Stupid question time, from a near-newbie to iOS development:

My app uses a tab bar as the root view controller, and each tab will then be a navigation controller with an assortment of view controllers inside it.

On Tab 1, if I create an array inside the first view controller loaded into the navigation controller, and then through user-interaction push another view controller on to the stack (a different one), how do I access the array from inside that second view controller?

I've been led to believe that the navigation controller logic takes care of it for me but I'm not sure.

Any help appreciated! :)

You're responsible for giving your view controllers whatever information they need to do their jobs.

For example, say you have a master view controller with an array, and a detail view controller that just takes a single object from that array.

You'd have:

code:
@interface MasterViewController : UIViewController

@property NSArray *someArray;

@end


@implementation MasterViewController

@synthesize someArray = _someArray;

// stuff to set up someArray

- (IBAction)pushDetails
{
    NSUInteger someIndex = 0; // get the index somehow

    // Make an instance of the view controller I want to push.
    DetailsViewController *detailsViewController = [DetailsViewController viewController];

    // Give it the objects it needs to do its job.
    detailsViewController.item = [self.someArray objectAtIndex:someIndex];

    // Now push it on to the navigation stack.
    [self.navigationController pushViewController:detailsViewController animated:YES];
}

@end


@interface DetailsViewController : UIViewController

@property id item;

@end


@implementation DetailsViewController

@synthesize item = _item;

// stuff

@end
See where I make the details view controller, then set its property, and then push it? That's the idea.

Adbot
ADBOT LOVES YOU

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

GazChap posted:

If I then change the contents of said variable though (e.g. the name of a player) how can I pass that back through to the master view controller so that it updates the array?

I've just seen a tutorial online that sets it up through the App Delegate and with some sort of "NSNotificationCenter" stuff that looks like it'll work, is that generally the best way of doing it?

You can do as Sir Davey suggests and keep a reference to the parent controller, or you can use a notification centre, or you can use key-value observing, or a delegate on the navigation controller, or have the master view controller itself deal with reloading the changed item, or just reload everything in -viewWillAppear:.

I'm a fan of the last two options, because they're the least fragile for when you switch to Core Data and/or involve other view controllers. For example, you could maintain a 'toReload' property on the master view controller, set it just before you pop the detail view, and then in -viewWillAppear: reload the object you remembered. Or you could simply reload all the views that display data from the array in -viewWillAppear:.

It's nice to keep relationships between view controllers simple. Parent view controllers set up child view controllers and that's that, no going up the object graph. You prevent retain cycles and make it easy to swap view controllers out, plus there's no future dickery needed if modal views get involved.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply