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
Star War Sex Parrot
Oct 2, 2003

Thanks for the feedback. I'll stick with the VM that I set up for .NET stuff.

Adbot
ADBOT LOVES YOU

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

The one thing I'd recommend is to install Notepad++ in the VM if you haven't, it has a very nice syntax scheme for assembly (and MASM's editor is shockingly old/awful.)

Yodzilla
Apr 29, 2005

Now who looks even dumber?

Beef Witch
How can I tell if a string within a JSON object is empty? This seems like it'd be so damned simple but absolutely nothing is working so far. For example a JSON object like:
code:
{"StoredProcedure":"spProject","CALLID":0,"ID":41,"TYPE":2,"NAME":"Innovation Landing Page","COMPANIES":"|2|","CATEGORIES":"","CLIENTS":"|12|","THUMBNAIL":"","INFO":"","CONTENT":"","ACTIVE":"A"}
I'm iterating through a bunch of these and I want to check if the THUMBNAIL field is empty and do something else by default. I've tried the following options:
code:
if ([dict objectForKey:@"THUMBNAIL"] == @"") { DO SOMETHING HERE } 
code:
if ([dict objectForKey:@"THUMBNAIL"] == nil) { DO SOMETHING HERE } 
code:
if ([[dict objectForKey:@"THUMBNAIL"] isKindOfClass:[NSNull class]]) { DO SOMETHING HERE } 
...and none of these work. If I try to NSLog([[dict objectForKey:@"THUMBNAIL"]) it will only output the objects that have values to the log as standard since it doesn't log empty strings. If I try to show the empty string within another string like NSLog(@"---%@---",[dict objectForKey:@"THUMBNAIL"]) sure enough it will output the value "------".

So what the hell is going on here? It's a string object but apparently not an empty string nor nil nor is it NULL. How do I detect this thing?


e: argh i had to do
code:
if ([[dict objectForKey:@"THUMBNAIL"] length] == 0) { }
i still don't know why the other methods didn't work though

Yodzilla fucked around with this message at 15:36 on Aug 22, 2012

Carthag Tuek
Oct 15, 2005

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



== is pointer comparison (ie is this object *literally* the same as another object). There are a couple of ways to check empty strings:

Objective-C code:

//check the length:
if ([myString length] == 0) {
}

//check if is equal to empty string:
if ([myString isEqualToString:@""]) {
}

E: An empty string is not nil, it is still a valid object.

Yodzilla
Apr 29, 2005

Now who looks even dumber?

Beef Witch
I thought I had tried isEqualToString as well since I've used it everywhere else in the project. Apparently not. :downs:

Toady
Jan 12, 2009

Yodzilla posted:

i still don't know why the other methods didn't work though

@"" creates an NSString, and like Carthag said, == compares pointer values. The empty NSString literal and the JSON NSString are different objects.

Fun fact, you can send messages to literals; e.g., [@"blah" length]

duck monster
Dec 15, 2004

Comparisons(etc) are the one area objective C really does suffer a bit.

It would be NICE to be able to go if([blah string] == @"ra") { stuff; } but poo poo just doesnt work like that.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
I look forward to @==, @>, @>=, @<, @<=, @~, @>>, @<<, @|, @&, @||, @&&

But yeah you're right, pointer equality's pretty unhelpful.

Doctor w-rw-rw-
Jun 24, 2008

Toady posted:

@"" creates an NSString, and like Carthag said, == compares pointer values. The empty NSString literal and the JSON NSString are different objects.

Fun fact, you can send messages to literals; e.g., [@"blah" length]

You're right but your explanation is wrong. @"" does not create an object (not at runtime, anyway). It points to a NSConstantString. I believe its value is stored in the program data and, to my knowledge, retain and release re no-ops on it.

I don't have access to a working XCode at the moment but do some tests and see if @"" == @"" and @"foo" == @"foo".

Doc Block
Apr 15, 2003
Fun Shoe
They probably will, since the compiler eliminates duplicate string literals.

Carthag Tuek
Oct 15, 2005

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



String literals point to the same object even if defined in multiple places.

Objective-C code:
//literals.m
#import <Foundation/Foundation.h>

int main( int argc, char **argv )
{
	NSString *a = @"";
	NSString *b = @"";
	NSString *c = @"foo";
	NSString *d = @"foo";
	NSString *e = [NSString string]; //empty, but not a literal
	
	NSLog(@"%@ == %@: %d", a, b, a == b); //YES expected
	NSLog(@"%@ == %@: %d", a, c, a == c); //NO
	NSLog(@"%@ == %@: %d", c, d, c == d); //YES
	NSLog(@"%@ == %@: %d", a, e, a == e); //NO
}
pre:
//output:
[ carthag@mbp.local:~ ]$ clang -framework Foundation literals.m && ./a.out
2012-08-23 00:57:26.806 a.out[37523:707]  == : 1
2012-08-23 00:57:26.807 a.out[37523:707]  == foo: 0
2012-08-23 00:57:26.807 a.out[37523:707] foo == foo: 1
2012-08-23 00:57:26.808 a.out[37523:707]  == : 0

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

pokeyman posted:

I look forward to @==, @>, @>=, @<, @<=, @~, @>>, @<<, @|, @&, @||, @&&

But yeah you're right, pointer equality's pretty unhelpful.

Apple's eventually gonna have to stop overloading everything onto @ and introduce a new memory-managed language. There is no way we are still writing Objective-C code in 10 years where we still get seg faults because we stomped on memory.

In my dream world they buy Xamarin and introduce Objective-C#. I'll take nsArray.Where().Select() for 500 Alex.

Yodzilla
Apr 29, 2005

Now who looks even dumber?

Beef Witch
Today I also learned that initWithNibName is case insensitive in the iOS Simulator but case sensitive on actual devices. It was a stupid mistake but one that took me a while to catch on to because, well, I thought it was a memory problem or something wrong with my pushing a view to the stack. Turns out I just didn't capitalize a letter. :downs:

Doc Block
Apr 15, 2003
Fun Shoe
The filesystem on iOS is case sensitive. The filesystem on OS X is not (though it does preserve case).

Which is why, on the simulator, initWithNibName: works regardless of case.

unpurposed
Apr 22, 2008
:dukedog:

Fun Shoe
I'm interested in doing something similar to a train ticker flip effect. Should I be using Core Animation for this? If so, what is the best resource to start learning CA?

kitten smoothie
Dec 29, 2001

Doc Block posted:

The filesystem on OS X is not (though it does preserve case).
You can format an OS X volume to be case-sensitive, and I tried it once after burning a few hours on a case sensitive asset issue with iOS and thinking I was due for a flatten/reinstall anyway.

I then realized the only reason to do that is if you like your software not working - a lot, like Adobe Creative Suite, won't even install on a case sensitive volume.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
I suggest keeping all your data on a case-sensitive partition but leaving a large case-insensitive root partition to install things on. We're basically forced to do that here for OS-testing purposes, but it works out pretty well regardless. It also means you can extra-special encrypt your data partition if you're into that kind of thing.

duck monster
Dec 15, 2004

Ender.uNF posted:

In my dream world they buy Xamarin and introduce Objective-C#. I'll take nsArray.Where().Select() for 500 Alex.

*pukes furiously all over your vision*

I'll pass on dot net shoehorned onto mobiles thanks

Yodzilla
Apr 29, 2005

Now who looks even dumber?

Beef Witch

kitten smoothie posted:

You can format an OS X volume to be case-sensitive, and I tried it once after burning a few hours on a case sensitive asset issue with iOS and thinking I was due for a flatten/reinstall anyway.

I then realized the only reason to do that is if you like your software not working - a lot, like Adobe Creative Suite, won't even install on a case sensitive volume.

Oh hell that sounds like a nightmare. I'm guessing you re-wiped and went back to case-insensitive?

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice
I have a screen with a bunch of UITextFields. They all have incremental tags on them. When I focus on the first text field (r any other one for that matter) and hit the TAB key on my keyboard in the simulator, every single text field has textFieldShouldBeginEditing: called on it, with no other delegate notifications called at all, even on the one that was first responder.

Has anyone else seen this? Is it a simulator bug (I do not have a bluetooth keyboard to test on device)? It's causing all sorts of awful stuff to happen since a couple text inputs display popovers to let the user select a value. It's very likely users of this App will have keyboards, so it's something I need to address.

cereal eater
Aug 25, 2008

I'd save these, if I wanted too

ps i dont deserve my 'king' nickname
If I'd like to get into developing apps, is the base Mac Mini a good choice if that is all I am using it for? Just curious since there is no room for upgrading the model itself.

Toady
Jan 12, 2009

Doctor w-rw-rw- posted:

You're right but your explanation is wrong. @"" does not create an object (not at runtime, anyway). It points to a NSConstantString. I believe its value is stored in the program data and, to my knowledge, retain and release re no-ops on it.

Though the data is stored in the executable, it is an NSString object at runtime, which is all I meant.

LP0 ON FIRE
Jan 25, 2006

beep boop

Carthag posted:

Man pages are your friend:

Bash code:
#!/bin/sh
sed -i .bak -e 's/oldword/newword/g' somefile.xml
Remove the .bak part (but keep -i) for the same functionality as the other example (ie. overwrite the existing file).

Thanks, this worked perfectly. I tried making one that is supposed to check every file, but I don't see the changes on the files. :confused:

find . -type f -exec sed -i 's/onclick="js(setPanoName(/onloaded="js(setPanoName(/g' {} \;


Edit:

I changed my command to:

sed -i '' 's/onclick="js(setPanoName(/onloaded="js(setPanoName(/g' *.xml;

And it works!

LP0 ON FIRE fucked around with this message at 18:10 on Aug 23, 2012

kitten smoothie
Dec 29, 2001

Yodzilla posted:

Oh hell that sounds like a nightmare. I'm guessing you re-wiped and went back to case-insensitive?
Yeah, the Adobe stuff was the first thing I tried installing, at least, so I was able to just turn right back around and burn the drive down again.

Doctor w-rw-rw-
Jun 24, 2008

Toady posted:

Though the data is stored in the executable, it is an NSString object at runtime, which is all I meant.

I know, I was just :spergin:.

:spergin::eng101: The class itself actually doesn't change location, either, so the object itself is there before runtime!
NSString *asdf = @"asdf";
NSLog(@"address: %d", asdf); // Ignore the warning

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
%p

Doc Block
Apr 15, 2003
Fun Shoe

cereal eater posted:

If I'd like to get into developing apps, is the base Mac Mini a good choice if that is all I am using it for? Just curious since there is no room for upgrading the model itself.

Yes, the Mac Mini is a great little computer. I bought one to use for iOS dev and wound up making it my main machine (until I bought an iMac).

ultramiraculous
Nov 12, 2003

"No..."
Grimey Drawer

pokeyman posted:

I look forward to @==, @>, @>=, @<, @<=, @~, @>>, @<<, @|, @&, @||, @&&

But yeah you're right, pointer equality's pretty unhelpful.

Wait, is that an actual thing or are you just anticipating what will probably end up coming? I don't remember @==, etc coming up in the "Modern Objective-C" sessions.

LP0 ON FIRE
Jan 25, 2006

beep boop
I've been developing at work on a 2010 model Mac Mini for iOS, and it's been fine. The only thing that gets a little slow is when I'm using some kind of tool like leaks. When I upgraded from 2 gigs of ram to 8, it was like I had a whole new machine, so I'd definitely recommend that.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

ultramiraculous posted:

Wait, is that an actual thing or are you just anticipating what will probably end up coming? I don't remember @==, etc coming up in the "Modern Objective-C" sessions.

Just joking.

Toady
Jan 12, 2009

Doctor w-rw-rw- posted:

I know, I was just :spergin:.

:spergin::eng101: The class itself actually doesn't change location, either, so the object itself is there before runtime!
NSString *asdf = @"asdf";
NSLog(@"address: %d", asdf); // Ignore the warning

Since we're :spergin:, Apple folks have hinted at someday allowing collection literal syntax to be used to initialize globals, which C requires to be compile-time constants, so maybe we'll see NSConstantArrays someday.

fankey
Aug 31, 2001

Anyone have any experience with CocoaAsyncSocket? I'm using the GCDAsyncSocket and am getting notifications into my object after it has been deallocated. I'm running with ARC if that matters. I am closing down my code before it gets dealloced to stop any subsequent notifications
code:
-(void)close
{
  [asyncSocket synchronouslySetDelegate:nil delegateQueue:NULL];
  [asyncSocket disconnect];
  asyncSocket = nil;
}
The delegate is stored in the socket as __weak id delegate; and the setDelegate call resolves to
code:
- (void)setDelegate:(id)newDelegate synchronously:(BOOL)synchronously
{
	dispatch_block_t block = ^{
		delegate = newDelegate;
	};
	
	if (dispatch_get_current_queue() == socketQueue) {
		block();
	}
	else {
		if (synchronously)
			dispatch_sync(socketQueue, block);
		else
			dispatch_async(socketQueue, block);
	}
}
Finally, the code that is actually calling into my code looks like
code:
	if (delegateQueue && [delegate respondsToSelector:@selector(socket:didReadData:withTag:)])
	{
		__strong id theDelegate = delegate;
		GCDAsyncReadPacket *theRead = currentRead; // Ensure currentRead retained since result may not own buffer
		
		dispatch_async(delegateQueue, ^{ @autoreleasepool {
			
			[theDelegate socket:self didReadData:result withTag:theRead->tag];
		}});
	}
Since it looks like they are checking the delegate and queue before calling ( which I have set to nil ) I'm wondering if there is a vulnerability from when it's placed in the queue to when it's called - if my object gets dealloced between those 2 events there will be issues. It's definitely deallocated - I have printouts in my code and I see a callback after the dealloc.

Any ideas what might be happening or workarounds that might be worth a shot?

crazysim
May 23, 2004
I AM SOOOOO GAY
Any idea if it is possible to codesign an Applescript Applet app to pass Gatekeeper? I'm trying to get the printer setup utility for the residential network I work for to work with minimal hassle in 10.8.

If you have a Developer ID, my team would be very grateful if you can see if you can sign this App and check if Gatekeeper is cool with that. We're not a Mac shop so dropping $100 for what might be useless would not be ideal. We don't have other things to sign other than this:

https://www.dropbox.com/s/p60rzk0umu7ti9a/mac_print.zip

If it works, we'll be getting our ID and signing that ASAP before September move-in. Otherwise, we will be providing temporary bypass instructions.

Thanks in advance.

crazysim fucked around with this message at 00:53 on Aug 24, 2012

tarepanda
Mar 26, 2011

Living the Dream
I'm coming from a C/C++/Python background and Objective C's syntax (punctuation? Not sure what I want to say here -- all of the symbols and the way it uses it) are really screwing me up. XCode's autosuggest/correct is also constantly interfering and writing crap I don't need/want and is screwing my code up when I try to type things and XCode makes it something else that I don't want.

Is there anything else I could be doing/not doing or should I just soldier on?

I'm using BNR's iOS Programming v3, by the way.

Edit: I just hit page 77 on Dot Syntax and my headache magically went away.

tarepanda fucked around with this message at 07:00 on Aug 24, 2012

Sch
Nov 17, 2005

bla bla blaufos!bla bla blaconspiracies!bla bla bla

Carthag posted:

String literals point to the same object even if defined in multiple places.

Note that this will no longer be true in the future. From http://clang.llvm.org/docs/ObjectiveCLiterals.html:

quote:

Objects created using the literal or boxed expression syntax are not guaranteed to be uniqued by the runtime, but nor are they guaranteed to be newly-allocated. As such, the result of performing direct comparisons against the location of an object literal (using ==, !=, <, <=, >, or >=) is not well-defined. This is usually a simple mistake in code that intended to call the isEqual: method (or the compare: method).

This caveat applies to compile-time string literals as well. Historically, string literals (using the @"..." syntax) have been uniqued across translation units during linking. This is an implementation detail of the compiler and should not be relied upon. If you are using such code, please use global string constants instead (NSString * const MyConst = @"...") or use isEqual:.

Doc Block
Apr 15, 2003
Fun Shoe

tarepanda posted:

I'm coming from a C/C++/Python background and Objective C's syntax (punctuation? Not sure what I want to say here -- all of the symbols and the way it uses it) are really screwing me up. XCode's autosuggest/correct is also constantly interfering and writing crap I don't need/want and is screwing my code up when I try to type things and XCode makes it something else that I don't want.

Is there anything else I could be doing/not doing or should I just soldier on?

I'm using BNR's iOS Programming v3, by the way.

Edit: I just hit page 77 on Dot Syntax and my headache magically went away.

You can change Xcode's preferences so that it doesn't autocomplete as you type.

Plorkyeran
Mar 22, 2007

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

Doc Block posted:

You can change Xcode's preferences so that it doesn't autocomplete as you type.
But typing a paragraph for every method call would be awful, so really you just need to get used to it. Xcode's autocomplete annoys me frequently, but the language would be pretty much unusable without it.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Whoever was lusting after C#'s class and property attributes (Ender.uNF?), check out extobjc.

lord funk
Feb 16, 2004

Where do you guys get the memo about the new additions? I knew NSNumber *n = @123 was going to be a thing but I didn't know it was in there already.

Adbot
ADBOT LOVES YOU

Carthag Tuek
Oct 15, 2005

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



If you have a dev account you get access to seeds of pre-release versions. For non-developers, there might be some murmurs on lists like objc-language.

The literals were formally introduced at WWDC '12 - check out the videos ("what's new in Objective-C")

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