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
Doh004
Apr 22, 2007

Mmmmm Donuts...
Yah, you guys are right I'm just being really stupid. I'm trying to do 3 steps too many. I ended up just changing the class that gets registered (for the UITableView) to be the inherited class and I'm able to get the correct class now.

Adbot
ADBOT LOVES YOU

haveblue
Aug 15, 2005



Toilet Rascal

Doh004 posted:

I have a property:

@property (nonatomic) Class myClass;

This allows me to do:

thing = [[self.myClass alloc] initBlah];

That's great and all, but why can't I do:

thing = (self.myClass*)thisIsCastable;

What am I doing wrong? It says I'm missing an expression. It's been a long day :saddowns:

This doesn't work because a class object isn't a type, so it thinks the * is a multiplication.

LP0 ON FIRE
Jan 25, 2006

beep boop
I just wasted a couple days of work trying to figure out a problem, and then I realized I didn't assign an object's parent equals self (object.parent = self) :doh:

I've made this mistake before, but I was wondering why it's necessary to do this. Why can't an object automatically assign this?

Doc Block
Apr 15, 2003
Fun Shoe
How?

Maybe the parent should instead have a addChild: method that (among other things) sets the child's parent property. You definitely shouldn't be doing it by hand every time you create an object, assuming the objects in your object graph require setting the parent property.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Yeah that's a little too "why doesn't the compiler guess what I want".

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Dev center is starting to come back online: https://developer.apple.com/support/system-status/

DreadCthulhu
Sep 17, 2008

What the fuck is up, Denny's?!
The whole "we'll overhaul our system in a week" claim is pretty absurd. It's obvious they're not willing to reveal what actually happened. Nothing of that size at an organization of that magnitude can be "overhauled" in a week. That's maybe how long it'd take to schedule a meeting with all the necessary parties to start planning an overhaul :)

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Everything related to the developer portal is such a hacked together mess that I can't imagine there's a significant number of people involved in it normally.

Toady
Jan 12, 2009

LP0 ON FIRE posted:

I just wasted a couple days of work trying to figure out a problem, and then I realized I didn't assign an object's parent equals self (object.parent = self) :doh:

I've made this mistake before, but I was wondering why it's necessary to do this. Why can't an object automatically assign this?

Core Data will do that for entity relationships.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Toady posted:

Core Data will do that for entity relationships.

What?

I guess maybe LP0 ON FIRE should clarify what's going on. I'm picturing this:

Objective-C code:
Section *parent = [Section new];
Row *child = [Row new];
NSAssert([child.parent isEqual:parent], @"why doesn't this work?");

Sticky Profits
Aug 12, 2011
So having just returned from holiday to find my dev iPhone needs its iOS 7 beta updating before it will work, I've run into the issue of the developer center being down. Any guesses as to how long it might be before its back up? Also do I have any alternatives to updating the beta?

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



Reverse/inverse relationships in Core Data are special and have stuff in the backend to handle it, ie -[NSRelationshipDescription inverseRelationship]

If you implement your own thing, you should create KVC collection accessors that sets/unsets the parent as needed, like so (untested):

Objective-C code:
@interface MyThing : NSObject

@property (readonly) MyThing *parent;
@property (readonly) NSMutableArray *children;

@end

@implementation MyThing

- (id)init
{
  self = [super init];

  if (self) {
    _children = [NSMutableArray new];
  }

  return self;
}

- (NSUInteger)countOfChildren
{
  return [_children count];
}

- (id)objectInChildrenAtIndex:(NSUInteger)index {
  return [_children objectAtIndex:index];
}

- (void)insertObject:(MyThing *)obj inChildrenAtIndex:(NSUInteger)index {
  if (obj.parent) { // remember to remove from old parent
    [obj.parent.children removeObject:obj];
  }
  obj.parent = self; // set new parent
  [_children insertObject:obj atIndex:index];
}


- (void)removeObjectFromChildrenAtIndex:(NSUInteger)index {
  MyThing *obj = _children[index]; // reset parent when removing
  obj.parent = nil;
  [_children removeObjectAtIndex:index];
}

@end

//usage:

MyThing *parent1 = [[MyThing alloc] init];
MyThing *parent2 = [[MyThing alloc] init];
MyThing *child = [[MyThing alloc] init];

NSAssert(child.parent == nil, @"woop");
NSAssert(parent1.children.count == 0, @"woop");
NSAssert(parent2.children.count == 0, @"woop");

[parent1.children addObject:child];

NSAssert(child.parent == parent1, @"woop");
NSAssert(parent1.children.count == 1, @"woop");
NSAssert(parent2.children.count == 0, @"woop");

[parent2.children addObject:child];

NSAssert(child.parent == parent2, @"woop");
NSAssert(parent1.children.count == 0, @"woop");
NSAssert(parent2.children.count == 1, @"woop");
KVC makes sure to use your accessor methods if they follow the naming convention so any manipulation of your children array automatically handles the parent as per insert/remove above.

Carthag Tuek fucked around with this message at 12:07 on Jul 25, 2013

Meat Street
Oct 17, 2004

knowin' nothin' in life but to be legit
I'll ask here since the dev forums are down: I'm assuming I'm missing something obvious, but how do I tell UITabBar (or its controller) to display in the text-only fashion that, for example, Calendar uses in iOS [redacted]? I found the attributes for UIToolbar, but the same techniques don't seem to apply to a tab bar.

Doc Block
Apr 15, 2003
Fun Shoe

Carthag posted:

Reverse/inverse relationships in Core Data are special and have stuff in the backend to handle it, ie -[NSRelationshipDescription inverseRelationship]

If you implement your own thing, you should create KVC collection accessors that sets/unsets the parent as needed, like so (untested):

Objective-C code:

@interface MyThing : NSObject

@property (readonly) MyThing *parent;
@property (readonly) NSMutableArray *children;

@end

@implementation MyThing

- (id)init
{
  self = [super init];

  if (self) {
    _children = [NSMutableArray new];
  }

  return self;
}

- (NSUInteger)countOfChildren
{
  return [_children count];
}

- (id)objectInChildrenAtIndex:(NSUInteger)index {
  return [_children objectAtIndex:index];
}

- (void)insertObject:(MyThing *)obj inChildrenAtIndex:(NSUInteger)index {
  if (obj.parent) { // remember to remove from old parent
    [obj.parent.children removeObject:obj];
  }
  obj.parent = self; // set new parent
  [_children insertObject:obj atIndex:index];
}


- (void)removeObjectFromChildrenAtIndex:(NSUInteger)index {
  MyThing *obj = _children[index]; // reset parent when removing
  obj.parent = nil;
  [_children removeObjectAtIndex:index];
}

@end

//usage:

MyThing *parent1 = [[MyThing alloc] init];
MyThing *parent2 = [[MyThing alloc] init];
MyThing *child = [[MyThing alloc] init];

NSAssert(child.parent == nil, @"woop");
NSAssert(parent1.children.count == 0, @"woop");
NSAssert(parent2.children.count == 0, @"woop");

[parent1.children addObject:child];

NSAssert(child.parent == parent1, @"woop");
NSAssert(parent1.children.count == 1, @"woop");
NSAssert(parent2.children.count == 0, @"woop");

[parent2.children addObject:child];

NSAssert(child.parent == parent2, @"woop");
NSAssert(parent1.children.count == 0, @"woop");
NSAssert(parent2.children.count == 1, @"woop");

KVC makes sure to use your accessor methods if they follow the naming convention so any manipulation of your children array automatically handles the parent as per insert/remove above.

Shouldn't the children array be hidden away as an implementation detail, though? It'd be better, IMHO, to just have addChild: and removeChild: methods, with the children array not publicly exposed.

Or, if it has to be exposed, have the publicly visible property be an NSArray with the readonly attribute set.

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



Doc Block posted:

Shouldn't the children array be hidden away as an implementation detail, though? It'd be better, IMHO, to just have addChild: and removeChild: methods, with the children array not publicly exposed.

Or, if it has to be exposed, have the publicly visible property be an NSArray with the readonly attribute set.

Any access to the array will be funnelled through the accessors by KVC (if they are named correctly) so you can guarantee that the parent will always be up to date.

When you go thing.children, you're actually given a KVC-proxy (might be isa-swizzled), which when you add/remove objects checks the thing class for accessors that fit the pattern, and uses them.

E: In fact, you don't even need to have an array for a backing store, it could be some weird homecooked poo poo.

Carthag Tuek fucked around with this message at 14:54 on Jul 25, 2013

LP0 ON FIRE
Jan 25, 2006

beep boop

Doc Block posted:

How?

Maybe the parent should instead have a addChild: method that (among other things) sets the child's parent property. You definitely shouldn't be doing it by hand every time you create an object, assuming the objects in your object graph require setting the parent property.

Yeah it's getting kind of annoying.

code:

plant = [[PlantClass alloc] initWithKind:kPlantKind_None];
						
[plants addObject: plant];
						
PlantClass *tmpPlant;
						
tmpPlant = [plants lastObject];
						
tmpPlant.parent = self;

I have an NSMutableArray called plants. I init a plant, and add it to the array. I then get a temporary one at the last index I added it to and then set parent = self. If I do plant = self after I init it before I add it to the array, it doesn't work. Not sure how addChild would work in this case.

Doc Block
Apr 15, 2003
Fun Shoe
You make a method on whatever self is that makes a plant, sets its parent property to self, and adds it to the plants array. You can call it addChild: or whatever you want. That way you're only writing that code once, and can know that it always works.

Doc Block
Apr 15, 2003
Fun Shoe

Carthag posted:

Any access to the array will be funnelled through the accessors by KVC (if they are named correctly) so you can guarantee that the parent will always be up to date.

When you go thing.children, you're actually given a KVC-proxy (might be isa-swizzled), which when you add/remove objects checks the thing class for accessors that fit the pattern, and uses them.

E: In fact, you don't even need to have an array for a backing store, it could be some weird homecooked poo poo.

I guess I just don't like magic side effects like that. IMHO, adding an object to a mutable array shouldn't do anything other than add the object unless you have a very good reason and it's very well documented that the other effects happen. An ordinary method makes it more obvious that other things can/will happen.

ultramiraculous
Nov 12, 2003

"No..."
Grimey Drawer
So I think the submission process is still borked. I've been sitting at "Processing for App Store" for almost an hour now.

Worst. Week. Ever.

Edit: And five minutes later it's in the store and Apple proves me wrong. gently caress you Apple. :argh:

ultramiraculous fucked around with this message at 04:30 on Jul 26, 2013

Toady
Jan 12, 2009

pokeyman posted:

What?

I guess maybe LP0 ON FIRE should clarify what's going on. I'm picturing this:

Objective-C code:
Section *parent = [Section new];
Row *child = [Row new];
NSAssert([child.parent isEqual:parent], @"why doesn't this work?");

I assumed he was talking about adding a child to a model object and having the parent get set automatically, so I was recommending the use of Core Data for his model since it'll maintain referential integrity for him.

Toady fucked around with this message at 05:46 on Jul 26, 2013

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



Doc Block posted:

I guess I just don't like magic side effects like that. IMHO, adding an object to a mutable array shouldn't do anything other than add the object unless you have a very good reason and it's very well documented that the other effects happen. An ordinary method makes it more obvious that other things can/will happen.

Eh, it's "magic" in Core Data too. But to each his own. I like being able to treat the property as a normal array and knowing that the parent on its contents will remain up to date.

DreadCthulhu
Sep 17, 2008

What the fuck is up, Denny's?!
Are there any kind of very thorough cheat sheets or references guides for ObjectiveC out there, and possibly Cocoa for people like me who don't work much with the ecosystem any longer, but occasionally need to jump back for a week or two and be immediately highly productive?

Simulated
Sep 28, 2001
Lowtax giveth, and Lowtax taketh away.
College Slice
Bunch of stuff is back up now, just FYI.

kitten smoothie
Dec 29, 2001

DreadCthulhu posted:

Are there any kind of very thorough cheat sheets or references guides for ObjectiveC out there, and possibly Cocoa for people like me who don't work much with the ecosystem any longer, but occasionally need to jump back for a week or two and be immediately highly productive?

I would love something like this as well just because I will be starting a full time job doing iOS work in three weeks and it has been probably a few months since I have cracked open Xcode except to do their pre-interview screening test. I could stand to have a refresher.

Doc Block
Apr 15, 2003
Fun Shoe
I'd better grab Xcode 5 DP3 before the PowerMac G3 running the dev center falls over again.

DreadCthulhu
Sep 17, 2008

What the fuck is up, Denny's?!
What are people's thoughts on wrapping JSON data passed by an API into a custom object? Both my API and web client think very heavily in terms of maps that fit very well a JSON-like schema. Things tend to change quite a bit, so these "objects" lose and acquire keys, variables go from strings to number to arrays etc. Obviously changes need to be made everywhere when this happens, but ObjectiveC would have the additional burden of requiring an update the boilerplate class you convert these JSON objects/dictionaries to. Actually, writing boilerplate to create those classes in the first place is a bit of a pita.

One option is to keep JSON data in a generic NSDictionary and hope you don't forget to keep the keys and value types in sync. You postpone type checking until that piece of data is already somewhere deep in your business logic where it can explode, potentially being very confusing. Parse works somewhat along those lines where they always return a generic PFObject and you can either make a proper object for it, with the right properties, or you can use it like a dictionary.

I'm curious if most people tend to opt towards flexibility and using a dictionary, avoiding the overhead of updating boilerplate classes. Did this scale at all? I'm also suspecting there might be a way of automating the generation of these classes, and I'm simply not aware of this.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Every time I try to get away without duplicating model definitions in the API and the thing consuming the API it's turned out to be more problematic than it's worth, especially when compile-time type checking is an option.

Minimizing the boilerplate involved is definitely important, though. Mantle is decent for that, although IMO it tries to be too flexible and so doesn't go far enough. If you have a bajillion model types then something based on class_copyPropertyList may be worth it to completely eliminate any sort of duplication in the obj-c code. CoreData + mogenerator + RestKit is another zero-duplication option.

DreadCthulhu
Sep 17, 2008

What the fuck is up, Denny's?!
Mantle looks pretty interesting, I'll give that a shot. I guess there's not that much work in addition to what I'm already doing, so no reason not to leverage type checking when possible.

DreadCthulhu
Sep 17, 2008

What the fuck is up, Denny's?!
Those of you familiar with AFNetworking, what is the interface for id responseObject you get back in the successful callback when fetching some JSON? Is it just a NSDictionary hiding behind that id? I suck and have not been able to determine what the specific interface to this object is besides KVC. In fact I suspect that might be it.

Nvm, in my case it was just a NSArray of NSDictionary, good enough for me.

DreadCthulhu fucked around with this message at 22:39 on Jul 27, 2013

Doc Block
Apr 15, 2003
Fun Shoe
You can always just do NSLog(@"class = %@", NSStringFromClass([someObject class])) to see what the class you're getting back is.

edit: I suspect the reason it returns id is because it can return either an NSArray or an NSDictionary like in Apple's own JSON serialization stuff.

Doc Block fucked around with this message at 23:58 on Jul 27, 2013

DreadCthulhu
Sep 17, 2008

What the fuck is up, Denny's?!

Doc Block posted:

You can always just do NSLog(@"class = %@", NSStringFromClass([someObject class])) to see what the class you're getting back is.

edit: I suspect the reason it returns id is because it can return either an NSArray or an NSDictionary like in Apple's own JSON serialization stuff.

Yeah I got a bit lazy there, life without a REPL is not worth living.

And yes, good point. It's probably because the smallest piece of valid JSON is a {} or [], hence one of those two classes.

Definitely pretty happy with Mantle + AFNetworking so far.

Unrelated note: what's a sane way of stating that a NSNumber property can be null? Is storing (NSNumber *)[NSNull null] kosher or a hack?

ManicJason
Oct 27, 2003

He doesn't really stop the puck, but he scares the hell out of the other team.

DreadCthulhu posted:

What are people's thoughts on wrapping JSON data passed by an API into a custom object?

My company ended up writing a little pseudocode language and a parser that outputs native objects in each of the languages we use, along with a bit of native language witchcraft to do the deserialization. I'm not sure the engineering time was totally worth it, but I am glad that we have it now.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

DreadCthulhu posted:

Unrelated note: what's a sane way of stating that a NSNumber property can be null? Is storing (NSNumber *)[NSNull null] kosher or a hack?

Just store nil.

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



Ya nil translates to null in NSJSON

Simulated
Sep 28, 2001
Lowtax giveth, and Lowtax taketh away.
College Slice

DreadCthulhu posted:

Unrelated note: what's a sane way of stating that a NSNumber property can be null? Is storing (NSNumber *)[NSNull null] kosher or a hack?

I'm sure you already know this, but this is ultimately C, so the only magic tricks the compiler knows is casting the integral types like int <-> double, and there are no overloaded operators. So that sort of cast is definitely a huge no-no; in C++ or C# you could overload the cast operator and actually support something like this and even Java understands how to coerce some user-defined types, but C has no clue.
Generally you just use nil for an empty or missing value. NSNull (why not NSNil? heh) is used for situations like collection classes that cannot actually represent nil internally like NSDictionary, which IIRC is due to the fact that varargs in C cannot tell you their length, which is due to the C ABI and whatever decisions were made in like 1970, so all the initializers have to use nil as a sentinel to indicate end of list, otherwise you'd have to pass an extra parameter indicating the number of items (NSLog/printf count the format strings)



I wish we could have a __varargs or something attribute that would say please pass a hidden struct that indicates the type of each parameter and the number of parameters, so you could get the number of passed params and their types at runtime, rather than relying on stuff like nil termination or format strings to tell you. I know we can never change how va_list/va_arg work until the end of time due to compatibility but at least we could introduce an opt-in behavior that was better.

For that matter, I wish something like @encode and whatnot were made standard and part of the blocks API and C in general so I could ask for the type signature of a function or a block, probably some standard structure like "struct __typedefinition { uint integralType, int membersLen, __typedefinition* members }" where the integral types are enums for int8/16/32/64/128, float 32/64/80, pointer, struct, etc that could also recursively indicate the type information for structures and functions like __typename(__typedefinition*)/__callsignature(fp*) , but rjmccall can probably tell me why that's a bridge too far or not workable. There's no way any of my ideas are new ones so I have to assume there is a good reason it hasn't been done.

Simulated fucked around with this message at 16:12 on Jul 28, 2013

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
There's https://github.com/jspahrsummers/libextobjc/blob/master/extobjc/EXTVarargs.h which automatically generates the format string with a bit of macro magic.

lord funk
Feb 16, 2004

Booo I just typed up a bug report only to have it error out when I hit send. Should have copied the report before hitting submit. :(

lord funk
Feb 16, 2004

Anybody playing with UIDynamics? I'm getting close to the behavior I want (pulling a view into the edge when it hits the blue target area), but I don't like the wobbly rotation of the view. Anyone know how to disable the rotation of the red view?



I'm triggering a UISnapBehavior once the red view collides with the blue view:

Objective-C code:
     CGPoint snapTo = CGPointMake(self.superview.bounds.size.width, self.superview.bounds.size.height / 2.0);
    UISnapBehavior *snapBehavior = [[UISnapBehavior alloc] initWithItem:self
                                                            snapToPoint:snapTo];
    [snapBehavior setDamping:1.0];
    [self.dynamicAnimator addBehavior:snapBehavior];
Screen capture gettin' pretty choppy...

Edit: figured it out. Add another UIDynamicsItemBehavior with the item properties, including allowsRotation

lord funk fucked around with this message at 01:16 on Jul 29, 2013

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!
Does anyone have the camera shutter closed-iris sphincter image for each of the three iPhone screen sizes? I have the retina 3.5" since I was able to just grab a screenshot from my phone no sweat. Problem is I don't have real devices for the other two sizes.



I can't just pull a screenshot from the simulator since it's very insistent that it does not support camera image capture, so trying to launch a UIImagePickerController throws an exception before it ever shows the shutter.

I did find a stackoverflow post that outlined how to trigger the camera iris animation anywhere (cool). This did work, but the gradients looked like poo poo because it's the simulator. Comparing the authentic screenshot and the fake animation showed it was surprisingly bad.

Finally, Google has been insistently refusing to find these images.

Adbot
ADBOT LOVES YOU

Doc Block
Apr 15, 2003
Fun Shoe
iOS Artwork Extractor, a little utility that will let you see all the various images and whatnot used in iOS. Run it on the simulator, find the camera iris images, and save them to your desktop.

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