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
wellwhoopdedooo
Nov 23, 2007

Pound Trooper!

fankey posted:

That's probably it - all three web servers I was trying to use would probably be classified as esoteric - homemade c#, busybox and whatever is build into our NAS.

On the plus side, HTML ranges are pretty easy to implement for a basic case--I did it once in VBScript (don't ask) in order to support resuming downloads.

Adbot
ADBOT LOVES YOU

wellwhoopdedooo
Nov 23, 2007

Pound Trooper!
Using Xcode 4, is there a keyboard shortcut to switch between the main editor and the assistant editor? The "Move Focus To Editor..." command would work and be only slightly annoying for requiring two keystrokes to switch, but I have to hit a different keystroke to switch to each editor, and I have to think about it every drat time and it's starting to drive me insane.

wellwhoopdedooo
Nov 23, 2007

Pound Trooper!
Is there a way to make things more ... complaney?

I'm creating an instance of a subclass of UIViewController I made inside my application:didFinishLaunchingWithOptions:, and initializing it with initWithNibName:, but as far as I can tell, it's just not loading the NIB. I made a UITabBarController in the XIB, and hooked it up to an outlet in my subclass, but I'm getting something like this:

code:
// MyViewControllerSubclass.h
@interface MyViewControllerSubclass : UIViewController { }

@property (nonatomic, readonly, retain) IBOutlet UITabBarController* tbc;

@end

// MyViewControllerSubclass.m
@implementation MyViewControllerSubclass

@synthesize tbc = _tbc;

@end

// AppDelegate.m (partial)
-(BOOL) application:(UIApplication*)application didFinishLaunchingWithOptions(NSDictionary*)launchOptions {
  
  MyViewControllerSubclass* vc = [[MyViewControllerSubclass alloc] initWithNibName:@"MyNibName"];
  
  // This would evaluate to TRUE. Why isn't my outlet being hooked up?
  // I suspect it's that "MyNibName" isn't actually being loaded, but I have
  // no idea how to tell--if I replace "MyNibName" with "blargle", which
  // doesn't exist in my project, no errors are raised.
  vc.tbc == 0x0;
  
  // This works just fine, even though it's nil. Argh! I get that properties
  // are implemented as messages, and sending a message to nil is allowable, but
  // is there a way to make this complain while I'm developing?
  vc.tbc.view == 0x0
  
}
Is there an error log somewhere that I can look at to at least see for sure whether my XIB/NIB is being loaded? Or something I can turn on so the app will
crash when it tries to load a XIB/NIB it can't find?

wellwhoopdedooo
Nov 23, 2007

Pound Trooper!

samiamwork posted:

Judging by your "==" tests it looks like you might want to use "assert()"?. Sorry if I've misunderstood.

Not really, I probably should have put in NSAssert() to make it more clear, this wasn't actual code, just an illustration of the question.

samiamwork posted:

Nibs aren't loaded on init. You have to call "view" on the controller to trigger nib loading. Your outlets and actions should be hooked up after that. I think that might be your problem.

Yep, this was exactly it, thanks!

samiamwork posted:

I'm sure there's probably a way you could cause this to fail, but it would probably wreak all kinds of havoc as I'll bet all the Apple frameworks lean on this (including synthesized accessors).

I guess I already ran into it when I had to turn off a bunch of the warnings because they were getting hit hundreds of times in the framework headers and couldn't figure out a way to get GCC or LLVM to treat them as system headers. Oh well, thanks again!

wellwhoopdedooo
Nov 23, 2007

Pound Trooper!

Tux Racer posted:

Also, the difference between NSArray and NSSet when finding an object is that with NSSet, you just ask the set using member: if that object exists within the set. That's an O(1) operation.
I don't think that's possible.

wellwhoopdedooo
Nov 23, 2007

Pound Trooper!

Oh, average case, sure I'll buy that. But, correct me if I'm wrong, that fills a set and dictionary with

"1"
"2"
"3"
...
"99997"
"99998"
"99999"

which is more of a test of how good of a string hash function you have (and not a very good test at that) than how well your hash table does lookups--and that's fair for the stack overflow question, but not great for the question of how fast you can do lookups on any arbitrary hash--do they do so well for objects whose hash value is their memory address? Is using memory addresses as the hash value even common in Objective-C?

Anyway, I'll believe first part, for the average case anyway, but if member: is faster than objectAtIndex: for anything other than the most pathological of cases, naming it NSArray is downright deceptive.

wellwhoopdedooo
Nov 23, 2007

Pound Trooper!
Well, never claiming to have any idea how this poo poo works again.

Anyway, I have a question: What's the right way to load a view from a NIB through code, and add it to a tabBarController? I've been just doing initWithNibName:, constructing an NSArray with that, and setting that array as the tabBarController.viewControllers, and all I get is a blank tab bar, and if I touch the center where the icon would be, it disappears. If I touch the tab bar anywhere else, it just does nothing.

I'm as sure as I know how to be that the view that I'm stuffing into the tabBar is loading--all the outlets do actually point to stuff, .tabBarItem included, verified by [[[NSAlert alloc] yaddayadda] show]; right after setting the array, but I've been looking for any little mistake for the last two days and I'm out of ideas.

Anyone else ever run into the disappearing tabBarController?

wellwhoopdedooo
Nov 23, 2007

Pound Trooper!
Sweet gently caress, finally have it working.

I have a window-based application. The main window XIB is just the default that's created with the project. I made another XIB that consists of only a UITabBarController. That XIB's outlets are as follows:

tbc = the UITabBarController
view = tbc.tabBar

In my application:didFinishLaunchingWithOptions: I do this:

code:
MyViewCtrlSpec* tbcvc = [[MyViewCtrlSpec alloc] initWithNibName:@"MyViewCtrlSpec" bundle:nil];

[self.window addSubView:tbcvc.view];  // This is tbc.tabBar
self.window.rootViewController = blah.tbc;

tbcvc.tbc.viewControllers = [[NSArray alloc] initWithObjects:
  [[v1 alloc] initWithNibName:@"v1" bundle:nil],
  [[v2 alloc] initWithNibName:@"v2" bundle:nil],
  nil
];

[self.window makeKeyAndVisible];
Can anybody tell me why I have to do it this exact way, and (even better) how I could have told that this is the way to do it? Is adding the tabBar itself as a subview right? It doesn't feel right, but it doesn't work without it. I've read that a UITabBarController needs to be the root view controller, and I suppose that's what I'm doing since a.) it's working and b.) I'm setting the property on the window, but am I actually doing this right? Am I doing something like when I first started learning C++ and blithely accessed freed memory that just hadn't been overwritten yet and didn't find out until I made it complex enough?

Also, as I'm picturing it, if the code posted was exactly what was in my application:blahblah: function, I'd have three memory leaks, one for each view, since tbcvc is a local variable and the array calls retain on everything that's added to it. Is that right? And if it is (or even if it isn't) why does it keep working when I release tbcvc in the function--is it just that the program isn't complex enough yet? Would the MyViewCtrlSpec functions like didReceiveMemoryWarning: still work? And if so, how, since as far as I'm aware, it's retain count would be 0?

gently caress I miss being able to run .NET Reflector on the system libraries so much.

wellwhoopdedooo
Nov 23, 2007

Pound Trooper!

pokeyman posted:

^^^^^
Well that was impressive timing.


Can you post your project, or an example of it? I'm having a hard time following you here.


You're also leaking the array, so four.

Sure. link

Right now I'm trying to figure out how to put the tabBarItem that's associated with a view in that view's XIB.

The reason I'm going to all this trouble is partially that I don't understand the stuff, and partially because I want to be able to pull a particular module out or put a new one in and only have to edit the code in a single place. I don't know how the in-app purchases thing works yet, and very likely won't end up using it, but I'd like to build the app in a way that it'd be easy to start using that as well if I do decide to go that way.

wellwhoopdedooo fucked around with this message at 01:30 on May 1, 2011

wellwhoopdedooo
Nov 23, 2007

Pound Trooper!

samiamwork posted:

The reason it doesn't work without the addSubview: is because you're inadvertently loading the nib when you pass self.moduleSelectorViewController.view as a parameter. Replace that line with [_moduleSelectorViewController view] and it works.

Ah, thanks. I'd assumed that .view ended up being called somewhere when I set it as a .rootViewController, I did think to verify that but I guess in my random flailing I did something else that appeared to confirm the assumption.

So, on to the next issues, I have a couple general Objective-C questions:

1: Is there a way to hide a method that a superclass implements in a subclass? I'm guessing there's not, but if that's the case, how do you handle subclasses requiring additional information before they're in a valid state? e.g. as in other languages where you have to manually implement every constructor in subclasses. Or is even requiring additional information not a good idea in Obj-C? Do subclasses not mean quite the same thing as in C++/C#/similar? How deep does this rabbit-hole go?

2: I see that I can sort of get pure virtual functions with protocols, but is there a way to make a superclass force its subclasses to implement a protocol? Or is there a better way to go about this? Am I thinking too C++ish again?

wellwhoopdedooo
Nov 23, 2007

Pound Trooper!

pokeyman posted:

I'm not entirely sure what "hiding a superclass's method" has to do with "subclasses requiring additional information". I'm kind of curious: can you give an example of a scenario that would motivate you to subclass but not support all of the superclass's methods?

I probably phrased that badly, so please don't be offended if I'm explaining something you're already familiar with.

The only real instance of it that doesn't involve breaking promises is in constructors. As an example:

Pseudocode (C++ish):
code:
// This class does the obvious and writes stuff to a file.
class FileWriter {
  
  // Constructor requires a file.
  FileWriter (string const& filename);
  
};

// This class does the same thing, but logs it.
class LoggingFileWriter {
  
  // Constructor requires both a file and a log.
  LoggingFileWriter (string const& filename, Logger& logger);
  
};
The advantage of developing this way is, provided I'm careful about exception safety, I never have to write "invalid object state" errors for when you, say, try to call loggingFileWriterInstance.write("some text") without supplying a logger, because you can't even construct the object in an invalid state. By extension, you don't have to handle invalid state errors, because they don't exist.

Granted it's a lot more complex in the real world and sometimes impossible, and this example in particular would have a host of other errors to handle which minimizes the benefit, but the best error handling is preventing them in the first place, and it's something I strive for anyway.

I imagine the answer will be that in Obj-C, the usual way to do things is that if somebody instantiated LoggingFileWriter with the single argument constructor you'd delay the error until they called [instance write:@"something"] without setting .logger, but I really like trying to make things as close to impossible to use wrong as I can, so I'm asking even though I'm fairly sure I already know the answer.

And thanks for your other answers, I really appreciate all your help.

wellwhoopdedooo
Nov 23, 2007

Pound Trooper!
If anyone has tips about how to improve Xcode 4, I know I'd appreciate the hell out of them, and I bet others would too.

I'm not looking to make Xcode into Visual Studio--their handling of the UI is infinitely better than Visual Studio, other than the game of loving Twister you have to play to hit any useful keyboard shortcut, and yet "Close the gently caress out of the application" is a single easy-to-hit keystroke. I looove the way it handles windows, and indenting wrapped lines, I don't get why I can't even find something like that for Visual Studio.

That said, there's a lot of thing I miss. Like Ctrl-Tab swapping between two source code windows. Or the life-changing AllMargins extension. Or multiple column guides. Or even being able to see what the gently caress column you're on at all. Seriously. What code editor, other than Xcode, offers NO goddamn way to see what column you're in? It's loving baffling.

So, is there like an Xcode extensions/tweaks site I don't know about? Some documentation of options that don't have a UI? Because honestly, it's like programming in a future full of graceful, swooping, impossibly tall buildings made of glass and pearl, but you have to dangle your rear end out the window to poo poo because ... "what the gently caress is a 'bathroom'?"

wellwhoopdedooo
Nov 23, 2007

Pound Trooper!

Ender.uNF posted:

Are you kidding? With the left and right bars open and the assistant view on there is absolutely no space. Using the assistant while editing an iPad XIB is almost useless and I have a 1920x1280 MBP.

I guess I need to setup a workspace with a second monitor.

You can make a separate tab to edit XIBs in, with the assistant editor much narrower, or on the bottom, or just off. It's kind of a pain, but a lot better than turning the assistant editor on and off.

The left and right bars on the other hand, are Cmd-0 and Cmd-Alt-0, so they're pretty easy to open and close at need.

If you have a second monitor, you can even open a new window, with its own tab setup. I gotta say, that's pretty sweet. I wish I wish I wish I could do that in Visual studio, instead of their loving awful tearoff editor implementation.

wellwhoopdedooo
Nov 23, 2007

Pound Trooper!
Is there any difference between declaring overridden methods in the overriding class's @interface and just defining the new @implementation?

wellwhoopdedooo
Nov 23, 2007

Pound Trooper!

rjmccall posted:

Not if you're not refining the parameter or return types and want callers to use your more accurate signature.

Oh SNAP you can do that in Obj-C?

So, all of these are valid?
code:
@interface SomeClass { }
@end

@interface SomeSubClass : SomeClass { }
@end

@interface Super { }

-(SomeClass*) methodOne:  (SomeClass*)firstParam;
-(SomeClass*) methodTwo:  (SomeClass*)firstParam;
-(SomeClass*) methodThree:(SomeClass*)firstParam;
-(SomeClass*) methodFour: (someClass*)firstParam;

@end

@interface Sub : Super { }

-(SomeClass   *) methodOne:  (SomeClass   *)firstParam;
-(SomeClass   *) methodTwo:  (SomeSubclass*)firstParam;
-(SomeSubclass*) methodThree:(SomeClass   *)firstParam;
-(SomeSubclass*) methodFour: (SomeSubclass*)firstParam;

@

@implementation Sub

-(SomeClass   *) methodOne:  (SomeClass   *)firstParam { return [super methodOne:  firstParam;] }
-(SomeClass   *) methodTwo:  (SomeSubclass*)firstParam { return [super methodTwo:  firstParam;] }
-(SomeSubclass*) methodThree:(SomeClass   *)firstParam { return [super methodThree:firstParam]; }
-(SomeSubclass*) methodFour: (SomeSubclass*)firstParam { return [super methodFour: firstParam]; }

@end
Actually I don't think I like the parameter version, but it'd be cool if I could do this instead:

code:
@implementation Sub

-(SomeSubclass*) balls:(SomeSUPERClass*)firstParam {
  return [super balls:makeSomeClassFromSuper(firstParam)];
}

@end

wellwhoopdedooo
Nov 23, 2007

Pound Trooper!
Is there a way to reference derived files in a project? I'm generating my images from SVG, and the logical place for the images to go seems to be $(DERIVED_FILE_DIR)/$(INPUT_FILE_BASE).png, but that just tosses them all in the same folder, which means name collisions. Is there a way to specify a part of a path in the Output Files for a custom build rule? e.g. my project is at /home/me/project, my image source file is in there at Subdir/image.svg, and I want to end up with /home/me/Library/.../DerivedSources/Subdir/image.png.

Is there a way to do that? Or is there a better way to do what I'm trying to do? Obviously I could just rename the images, but that's the easy way and I'm trying to learn.

wellwhoopdedooo
Nov 23, 2007

Pound Trooper!
OK, so after loving around with custom build rules and aggregates running custom scripts and building straight into the source tree and I don't know what else, I took a look in the app bundle it builds, and everything is just stuffed into one folder there even once I've got things building into separate folders.

Are subfolders other than the system-created stuff like *.lproj just a no-go? If you're not supposed to do it, whatever, I'll make blah-tabBarIcon.png instead of blah/tabBarIcon.png but I fuckin love me some subfolders.

wellwhoopdedooo
Nov 23, 2007

Pound Trooper!
[tell] me about Core Data.

As someone who's very comfortable in both SQL and C, and who started to miss things you can do in SQL in the first 15 minutes of modeling my data, why should I use it anyway? The advice to use it seems very emphatic.

wellwhoopdedooo
Nov 23, 2007

Pound Trooper!
Argh, somebody please explain countByEnumeratingObjectsWithState: to me. From reading the docs, and googling around, I can't see that we have any way to call cleanup code. There's a stackbuf, and a state, but nothing I've been able to find says that if I put objects in stackbuf or state->state or state->extra that there's any way to make sure dealloc gets called. Am I missing something, or is that just a constraint I need to deal with?

wellwhoopdedooo
Nov 23, 2007

Pound Trooper!

rjmccall posted:

It's just a constraint you need to deal with. You will not get any callbacks when the loop is complete, or if it's aborted part-way either normally or abnormally.

Crap. So, the implementation at line 354 is going to leak the NSEnumerator (and self, since enumerators retain the objects they enumerate) that's stored in state->state?

e: derp, forgot to link what I was talking about : Here it is

wellwhoopdedooo
Nov 23, 2007

Pound Trooper!

rjmccall posted:

No, because the default convention for methods is to return at +0, i.e. autoreleased or otherwise held.

poo poo, it looks like there's a core part of memory management I'm not aware of. I understand that newXXX and init are retain count +1, and that other methods are usually +0, but I thought that an object with a retain count of 0, in non-gc mode, is immediately deallocated, so unless you were returning a reference to an elsewhere-retained object, you always need to take ownership for the caller like new and init do.

I also thought (or still think) that objectEnumerator returns a new NSEnumerator*, which would have a retain count of 1 so it doesn't immediately dalloc, that you would have to clean up when you're done.

Is retain 0 something where it deallocs when it leaves scope? Because that would rule in about a thousand ways.

wellwhoopdedooo
Nov 23, 2007

Pound Trooper!
Read it, got it, thanks.

wellwhoopdedooo
Nov 23, 2007

Pound Trooper!

pokeyman posted:

tons of things can and are helpfully represented by strings when they really don't need to be

oh man, not to get all coding horrors up in here, but jesus christ I could not possibly disagree more. If I had a nickel for every bug caused by someone deciding that the type system was like underpants and just got in the way, I'd have about the same amount of money as I do right now, because I essentially get a nickel every time somebody decides the type system is like underpants and just gets in the way.

wellwhoopdedooo
Nov 23, 2007

Pound Trooper!

pokeyman posted:

Alright, so maybe I'm just not getting it, but why does calling [aString isEqualToString:someArray] not throw an exception? By your logic it should be a programmer error, right? Or it should blow up on some internal call to a string comparison function, or somehow not work. When in reality it simply returns NO.

(Also, did you miss the part where I countered your claims of "better expression of intent" or "faster performance" (see above question), or am I being so stupid that you'll simply repeat the same line until I get it?)

You didn't counter his claim of "better expression of intent". If you think isEqual means the same thing as isEqualToString, even if they do the same thing, you're doing a pretty good job of arguing for the viewpoint that the Objective-C "type system" is a travesty.

wellwhoopdedooo
Nov 23, 2007

Pound Trooper!

PT6A posted:

Oh Jesus, I just got a call (at half past midnight in this timezone, to be clear) from a woman who could barely speak English and was having trouble installing an app or using her credit card or some combination of the above. Maybe putting my phone number on my website was not a great idea (either that or I should just ignore my business phone after a certain time...)

Has anyone else had a bizarre experience like that?

You published a support number on the internet. If I was that lady, I'd think it was bizarre that the helpdesk rep sounded like I just woke him up.

wellwhoopdedooo
Nov 23, 2007

Pound Trooper!
Can anyone explain how IB actually works?

In VS, I can just go look at FormName.Designer.cs, and there's all my property setting and parenting turned into code. Is there an equivalent place I can look for IB?

I don't mind things doing things for me, but right now it's a bunch of magic to me, and that drives me up the wall when I'm trying to figure out why something isn't working like I expect it to.

Adbot
ADBOT LOVES YOU

wellwhoopdedooo
Nov 23, 2007

Pound Trooper!
Ah, the serialization (mostly) answers the question. I assume that there's some code that gets run in order to set the IBOutlet-type stuff in the ViewController classes (unless the ViewController instance is serialized too?) but, don't answer that parenthetical unless you know off the top of your head, I plan to research the details as soon as I get the chance.

Thanks everyone!

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