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
eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

status posted:

code:

for (NSDictionary *dictionary in plistArray) {
    NSLog(@"%@",[dictionary objectForKey:@"name");
}

For this sort of thing just take advantage of the fact that sending -valueForKey: to an array returns an array collecting the result of sending -valueForKey: to each of its members:

code:

NSArray *names = [dictionary valueForKey:@"name"];

Key-Value Coding (KVC) is really powerful and worth leveraging every chance you get. Same with NSPredicate which is built atop it.

Also, in general it's also better to use real objects when you can instead of dictionaries with known keys and values. KVC will still work thanks to the magic of the Objective-C runtime.

Adbot
ADBOT LOVES YOU

lord funk
Feb 16, 2004

I have a method that iterates over a bunch of files to change the file metadata, then save them. I would like to know when they're all done, but I'm not sure how to get a single 'did finish' notification instead of a bunch of individual notifications.

Objective-C code:
for (NSDictionary *patchInfo in patches) {
        TCDDocument *doc = [[TCDDocument alloc] initWithFileURL:patchInfo[@"fileURL"]];
        [doc openWithCompletionHandler:^(BOOL success) {
            //check status
            //change metadata 

            [doc saveToURL:patchInfo[@"fileURL"] forSaveOperation:UIDocumentSaveForOverwriting completionHandler:^(BOOL success) {
                if (success) {
                    //individual notification from here
                }
            }];
        }];
}
I have a feeling it's staring me in the face, but I don't see it.

dc3k
Feb 18, 2003

what.
You could have the if (success) {} bit increment an integer, and if the integer is equal to the count of patches, post the final notification. You'd need to handle failure as well.

Doh004
Apr 22, 2007

Mmmmm Donuts...
^^^ YOU SON OF A BITC...
Maybe have an int that you're observing and increment it each time it finishes. Then in your observing method, if that int is the same number as the count of documents you're done?

Kinda ghetto but it'd work?

lord funk
Feb 16, 2004

Oh duh. I thought I couldn't do that because of the block syntax but you can just use int __block counter = 0 in the declaration. Thanks!

lord funk
Feb 16, 2004

God drat just did it:

Objective-C code:
- (NSDictionary *)patchInfo {
    if (_patchInfo) {
        _patchInfo = @{....

Doctor w-rw-rw-
Jun 24, 2008
Or use dispatch groups and block one on a background thread and dispatch to main after it unblocks.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

lord funk posted:

God drat just did it:

Objective-C code:
- (NSDictionary *)patchInfo {
    if (_patchInfo) {
        _patchInfo = @{....
This is why I now use a macro for lazy properties. Not because it saves four lines of code, but to avoid stupid typos and mistakes.

Objective-C code:
#define LAZY_PROPERTY(name, type, value) \
- (type)name { \
    if (!_ ## name) \
        _ ## name = (value); \
    return _ ## name; \
}

LAZY_PROPERTY(patchInfo, NSDictionary *, (@{...}))

Toady
Jan 12, 2009

Maybe Clang should detect that getter pattern and warn about the mistake.

lord funk
Feb 16, 2004

Plorkyeran posted:

This is why I now use a macro for lazy properties. Not because it saves four lines of code, but to avoid stupid typos and mistakes.
Gonna adopt this. I have a code snippet I made once to help me remember, but I never use it.

Just to vent: I'm getting really tired of Instruments causing the iPad to freeze completely. If I don't quit Instruments between each run it happens every time. :argh: And if I never see 'tintColor' again in my life I'll die happy. Holy god.

Hughlander
May 11, 2005

Toady posted:

Maybe Clang should detect that getter pattern and warn about the mistake.

I'm surprised the static analyzer doesn't detect infinite recursion in the simple case. (I know halting problem but I mean a literal recursive path with no branches)

Doh004
Apr 22, 2007

Mmmmm Donuts...
Does anyone else have experience with Smart Banners?

How the hell do I develop for this? It seems to only work with the app store version of the app and not the in development version that I've put onto my test devices (I know the simulator doesn't work). A couple SO questions say you can build the app onto the device after installing from the App Store - which seems to work - however; "- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation" doesn't get called when doing this and I need to pass in the arguments.

Anyone have any idea?

*edit* It appears this is a known issue with iOS7?

https://devforums.apple.com/message/897373#897373

Doh004 fucked around with this message at 19:34 on Dec 18, 2013

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

Hughlander posted:

I'm surprised the static analyzer doesn't detect infinite recursion in the simple case. (I know halting problem but I mean a literal recursive path with no branches)

If you file it, it would be a great little project to give to a new employee or intern.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost
edit: source of the problem found and it doesn't have to do with item ordering. Feel free to discuss if you know the answer though!

NSLayoutConstraint question regarding first and second items. I ran into a situation where I was building a top and bottom constraint manually and though the layout worked I was getting a broken constraint warning at runtime. I then built the same constraints using the visual format language and the warning went away. I started digging into why and found that the firstItem and secondItem properties were different depending on how I built the constraints. I'm trying to understand, in the general case, which is the first item and which the second but I haven't found anything useful.

Example:
Objective-C code:
    UIView *parentView = [[UIView alloc] init];
    UIView *childView = [[UIView alloc] init];
    
    childView.translatesAutoresizingMaskIntoConstraints = NO;
    [parentView addSubview:childView];
    
    // constrain child to equal top and bottom extent of parent, creating the constraints explicitly
    NSLayoutConstraint *topConstraint = [NSLayoutConstraint constraintWithItem:childView
											attribute:NSLayoutAttributeTop
											relatedBy:NSLayoutRelationEqual
											toItem:parentView
											attribute:NSLayoutAttributeTop
											multiplier:1
											constant:0];
    NSLayoutConstraint *bottomConstraint = [NSLayoutConstraint constraintWithItem:childView
												attribute:NSLayoutAttributeBottom
												relatedBy:NSLayoutRelationEqual
												toItem:parentView
												attribute:NSLayoutAttributeBottom
												multiplier:1
												constant:0];
    
    // constrain child to equal top and bottom extent of parent, using visual format
    NSArray *formatConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[childView]|"
										options:kNilOptions
										metrics:nil
										views:NSDictionaryOfVariableBindings(childView)];
    
    [parentView addConstraints:@[topConstraint, bottomConstraint]];  // <-- this results in a broken constraint at runtime
    
    [parentView addConstraints:formatConstraints]; // <-- this does not
    
Hopefully it's obvious that the intent is to create the same set of constraints. The difference is the following:

Objective-C code:
    // the top constraint in both cases has the child view as the first item and the parent view as the second
    topConstraint.firstItem == formatConstraints[0].firstItem == childView
    topConstraint.secondItem == formatConstraints[0].secondItem == parentView
    
    // the bottom constraint is flipped.
    // The visual format constraint sets the parent view as the first item and the child as second,
    // while my manually created constraint follows the same ordering as my manually created top constraint
    bottomConstraint.firstItem == formatConstraints[1].secondItem == childView
    bottomConstraint.secondItem == formatConstraints[1].firstItem == parentView
Unfortunately the Apple documentation only refers to the first item as the "left side of the expression" and the second item as the "right side of the expression" which doesn't clarify anything. In fact, based on the lexical ordering in the visual format (where "|" is the parent view and "[childView]" is the child view) the resulting constraints seem to do exactly the opposite of that.

Anyone have any insight on this? I can fix this easily enough by just doing what the visual format does but I'd like to understand what exactly the meaning of "first" and "second" item are.


IMPORTANT EDIT:
the act of posting this problem here made me take a closer look and it turns out the constraint breakage is actually caused by a transient bad height calculation in -viewWillLayoutSubviews and has nothing to do with the ordering of the items in the constraints. I still don't know what Apple intends by "first" and "second" but it doesn't seem to matter in my particular case. Welp.

Dr Monkeysee fucked around with this message at 22:11 on Dec 18, 2013

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Monkeyseesaw posted:

Unfortunately the Apple documentation only refers to the first item as the "left side of the expression" and the second item as the "right side of the expression" which doesn't clarify anything.

Auto Layout Guide posted:


You can think of a constraint as a mathematical representation of a human-expressable statement. If you’re defining the position of a button, for example, you might want to say “the left edge should be 20 points from the left edge of its containing view.” More formally, this translates to button.left = (container.left + 20), which in turn is an expression of the form y = m*x + b, where:

  • y and x are attributes of views.
  • m and b are floating point values.

First item is y, second item is x.

This is not particularly well noted in the docs and is worth you pressing that "Send Feedback" button.

unixbeard
Dec 29, 2004

I'm having a problem with audio in the iOS simulator.

I basically don't hear any sound output from the app. When I start the app in the 7.0 simulator, I no longer hear music playing in the background (in iTunes), and I also don't hear the blips when I raise/lower the volume via the keyboard buttons. If I stop the simulator app, itunes music and volume blips come back.

With the 6.1 simulator, I do hear background music and the volume change blips, but also no audio from the app.

When I run the app on a device (running 6.1) I hear the app audio fine.

I had been messing around with soundflower but I have turned it all off, rebooted etc. It seems like the simulator app is choosing some audio output which is not actually sending any output, and I cant see where to configure. I've tried headphones/no headphones, resetting the simulator and double checked my audio midi setup which looks all correct.

I am using CoreAudio and this is my output unit

code:
	AudioComponentDescription outputcd = {0};
	AUNode outputNode;
	outputcd.componentType = kAudioUnitType_Output;
        outputcd.componentSubType = kAudioUnitSubType_RemoteIO;
	outputcd.componentManufacturer = kAudioUnitManufacturer_Apple;
	CheckError(AUGraphAddNode(player->graph, &outputcd, &outputNode), "AUGraphAddNode[kAudioUnitSubType_DefaultOutput] failed");
I'm using Xcode v 5.0.2, does anyone have any ideas where I could see what the simulator is doing or how I can track this down?

kitten smoothie
Dec 29, 2001

I don't think I have ever had a not-janky audio experience when working in the simulator. That's just been one of those cases where I had to work on a real device.

ultramiraculous
Nov 12, 2003

"No..."
Grimey Drawer
Yeah, the Simulator audio situation typically ranges from janky to crashy in ways that don't show up on the device at all.

unixbeard
Dec 29, 2004

It's been fine so far :sigh:

oh well

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

pokeyman posted:

[url=https://developer.apple.com/library/ios/documentation/userexperience/conceptual/AutolayoutPG/AutoLayoutConcepts/AutoLayoutConcepts.html#//apple_ref/doc/uid/TP40010853-CH14-SW1]


First item is y, second item is x.

This is not particularly well noted in the docs and is worth you pressing that "Send Feedback" button.

That does help. Thanks. It also shows that my ordering of first and second item in my two constraints is correct so it's interesting the visual format swaps them for the bottom constraint. Fortunately it doesn't seem to matter, at least in this particular case.

edit: feedback sent

Dr Monkeysee fucked around with this message at 23:50 on Dec 19, 2013

ManicJason
Oct 27, 2003

He doesn't really stop the puck, but he scares the hell out of the other team.
Apparently it's screw Core Audio week. I am attempting to move some audio queue code to audio units. I now have it working at double speed, meaning my playback is a double speed robotic version of what I record. I'm sure there's something goofy with my data format somewhere, but it all looks fine after banging my skull into them for a few hours.

edit: I was getting tiny buffers in my play callback and not using a rolling buffer like I should have been. Silly me.

ManicJason fucked around with this message at 08:10 on Dec 20, 2013

Glimm
Jul 27, 2005

Time is only gonna pass you by

So, Facebook released a thing:

http://facebook.github.io/origami/
https://code.facebook.com/posts/604847252884576/2013-a-year-of-open-source-at-facebook/

quote:

Origami is a free toolkit for Quartz Composer—created by the Facebook Design team—that makes interactive design prototyping easy and doesn’t require programming.

Haven't got to play with it yet but seems really cool

Doctor w-rw-rw-
Jun 24, 2008

You wouldn't believe what kinds of things they've prototyped with it. This is a tool that the industry's best designers use or should use.

unixbeard
Dec 29, 2004

Sound now works in the simulator v:shobon:v

Must've been a bug somewhere in my code. I have nfi what fixed it.

Kallikrates
Jul 7, 2002
Pro Lurker
I've use quartz composer for some neat image editing tricks sans photoshop. I imagine it's useful for prototyping all those fancy photo filter apps.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Doctor w-rw-rw- posted:

You wouldn't believe what kinds of things they've prototyped with it. This is a tool that the industry's best designers use or should use.

I wish I had time to learn it. I goofed around a bit when Facebook revealed they prototyped with it, and suddenly there were a ton of 'hello world' tutorials coming out, but nobody ever seemed to move past that point. If only I didn't have to fill every other role on all our iOS and web projects as well... Then I'd feel justified in taking a week and just goofing off with composer.

lord funk
Feb 16, 2004

It's taken a while, but I finally get the fact that many of the Apple supplied UI elements just aren't for apps that want a custom look. I just finished rolling my own UIAlertView so I can have control over font, color, and not have it fly all over the screen with UIDynamics. I have a few UI elements I'll post here once this project is done.

Edit:

lord funk fucked around with this message at 18:03 on Dec 27, 2013

ManicJason
Oct 27, 2003

He doesn't really stop the puck, but he scares the hell out of the other team.
code:
(lldb) po segue
<UIStoryboardPushSegue: 0x8c17780>
(lldb) po [segue destinationViewController]
<not an object or object does not respond to description method>
(lldb) po [[segue destinationViewController] class]
error: Execution was interrupted, reason: Attempted to dereference an invalid ObjC Object or send it an unrecognized selector.
The process has been returned to the state before expression evaluation.
Well, that sure makes sense. My destination view controller, an id, is not even an Objective-C object. That's brilliant and makes perfect sense, I'm sure.

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

ManicJason posted:

Well, that sure makes sense. My destination view controller, an id, is not even an Objective-C object. That's brilliant and makes perfect sense, I'm sure.

The type of the property is immaterial here. If the object the property refers to was deallocated before you attempted to use it, the pointer you get back from the property could be garbage. (Unless the property or variable is specified to be a zeroing weak reference. Which I'm guessing it's not.)

Run the static analyzer and also run your app with zombies enabled, that will help you catch memory management issues.

Simulated
Sep 28, 2001
Lowtax giveth, and Lowtax taketh away.
College Slice
To be fair, compared to some IDE debuggers like VS, the Xcode/LLDB experience leaves something to be desired.

NSDictionary you say? What are the keys and values? Hmmm I don't think 0x8df01234 is the correct answer. To be fair, some of this has gotten better recently but it's still poo poo for just showing me the drat contents of my objects. I'm not even going to get into stuff like patching in live code changes.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
The frustrating thing about that is that showing the contents of collections works just often enough to make me expect it to work, making all the times when it doesn't work for no apparent reason all the more disappointing.

lord funk
Feb 16, 2004

My favorite is trying to peek into an NSIndexPath.

code:
indexPath NSIndexPath * 0x1666a240 0x1666a240
NSObject NSObject  
isa (Class) NSIndexPath 0x3b311130
_indexes (NSUInteger *) NULL 0x00000000
*_indexes (NSUInteger)  
_length (NSUInteger) 0
_reserved (void *) 0x16 0x00000016
Oh, okay. The section and row would have been nice.

dc3k
Feb 18, 2003

what.
I have no idea what you guys are doing to cause that. I print out NSDictionarys and NSIndexPaths probably 50 times a day and have never run into that. How does it happen?

Toady
Jan 12, 2009

Same here. Using po (print object) on an NSIndexPath calls -description, which returns something like this:

<NSIndexPath 0x79509d0> 2 indexes [0, 0]

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

status posted:

I have no idea what you guys are doing to cause that. I print out NSDictionarys and NSIndexPaths probably 50 times a day and have never run into that. How does it happen?

What lord funk showed was what happens when you twist open a variable pointing to an NSIndexPath, which shows its ivars rather than its logical contents.

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

eschaton posted:

What lord funk showed was what happens when you twist open a variable pointing to an NSIndexPath, which shows its ivars rather than its logical contents.

Correct. In VS, I don't have to manually invoke the debugger like an animal. Of course the VS debugger understands that the properties really exist (po obj.abc not found, po [obj abc] works. Arggg) and knows how to lookup return values even when they are structs so no casting is required.

I'm not annoyed that this doesn't work, I'm annoyed that a company with 150 billion in the bank couldn't hire an intern to crank out that feature across three major releases of their IDE. Something VB 5 did in 1997.

ManicJason
Oct 27, 2003

He doesn't really stop the puck, but he scares the hell out of the other team.
I thought dot syntax works correctly now in the debugger. It's still infuriating that you can type [someArray co..] and have it pop up with "-(NSUInteger) count" then spit back unknown return type if you don't cast the result.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

ManicJason posted:

I thought dot syntax works correctly now in the debugger.

someView.bounds anyone?

lord funk
Feb 16, 2004

Ender.uNF posted:

I'm not annoyed that this doesn't work, I'm annoyed that a company with 150 billion in the bank couldn't hire an intern to crank out that feature across three major releases of their IDE. Something VB 5 did in 1997.
The only part that bothers me is how they touted Quicklook™ like viewing of objects in Xcode 5 as an amazing new feature. So far all I've been able to use it for is viewing colors, which is great, but why didn't they take the opportunity to extend it to other standard objects?

Unrelated: forgot that you can't submit an app with a beta SDK. Only took me an hour of dancing with provisioning to remember.

Edit: Ugh. Add an entitlement to your app? Don't worry, Xcode's Capabilities feature will take care of everything invalidate your provisioning profiles, not only requiring you to generate new ones manually, but also to check a box for the entitlement for your App ID in the Member Center. Which is made perfectly clear by the errors in validation during submission.

lord funk fucked around with this message at 17:27 on Dec 30, 2013

Adbot
ADBOT LOVES YOU

Toady
Jan 12, 2009

LLDB has supported dot notation for at least two years.

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