views:

170

answers:

2

In Xcode (3.2 on Snow Leopard) when I start to type out a function such as

-(void)myFunctionName {

}

When I first start typing the code hint is

-(voidPtr
  1. What is the difference between void and voidPtr? I assume that voidPtr is a pointer of some kind, what cases call for its use? Do I want to be using voidPtr instead of void?

  2. Can I change a preference in the editor that will default to void and then I can type P and tab complete to voidPtr if I want?

  3. Is there a general way to configure or prioritize code hints so that common hints show up before more obscure code hints?

  4. Can I create code hint shortcuts? Where I type a couple of characters and a command to expand common boilerplate code?

  5. What are some recommended practice tutorials for getting really productive in Xcode editing?

Update: Based on Darren's suggestion it looks like voidPtr comes from

CarbonCore/Threads.h

...

/*
    The following ProcPtrs cannot be interchanged with UniversalProcPtrs because
    of differences between 680x0 and PowerPC runtime architectures with regard to
    the implementation of the Thread Manager.
 */
typedef void *                          voidPtr;

I am running Xcode on a fresh vanilla install of Snow Leopard. And I have not done anything exotic with my projects. Just starting some very basic tutorials on Xcode and Objective C. Any experienced Objective C folks have useful background info here?

+1  A: 

voidPtr isn't a standard Objective-C or Cocoa type. XCode is likely presenting voidPtr because it found that symbol somewhere in your project.

You can select "File > Open Quickly" (⌘⇧D) from the menu and type voidPtr to see where that symbol is defined. You can also do the same by holding down the Command key and double-clicking a symbol in your source code.

Darren
+1  A: 

This is a bug in Xcode. If you start typing a C-style function declaration:

void SomeFunc(...

Then "void" appears as the first suggestion. Xcode's code sense applies different rules depending on the surrounding syntax, and when you are creating an Objective-C function declaration, it appears to exclude all of the built in types, including void.

I have filed a bug with Apple (via bugreport.apple.com), and I recommend that you do the same. Apple prioritizes their software fixes (at least partially) based on the number of duplicate reports that they see for a given problem.

update: Here is the full text of the bug report I submitted to Apple:

Summary:
Xcode's code sense provides a list of suggested matches as you type. This list is filtered depending on context. When typing an Objective-C method declaration, the built-in types (void, int, float, etc.) are filtered out. Numeric types such as int and float may be intentionally missing in order to encourage the use of NSInteger or NSNumber, but the void type is still used all the time, and should really appear in the list of suggestions.

Steps to Reproduce:
1. Open Xcode
2. Create a new project with the Cocoa Application template
3. Open the application delegate header file
4. Begin creating a method declaration with a void return type:
    - (vo
5. Press escape to bring up the complete list of suggested completions

Expected Results:
I would expect to see "void" at the top level of the suggestion list, and I would expect it to be highlighted as the most likely choice.

Actual Results:
The list does not even contain "void", and the selected candidate is "voidPtr", which is declared in CarbonCore/Threads.h

Regression:
Unknown, but it definitely happens in the latest build of Xcode (3.2 (1610)) on Mac OS X10.6

Notes:
See discussion on StackOverflow.com (http://stackoverflow.com/questions/1484154/xcode-editor-default-to-void-instead-of-voidptr/)

e.James
Thank you for your response. Filed a bug report as well.Is there a way to customize the filter options in Xcode?
Gordon Potter
Not that I know of. I've found a few of the defaults frustrating at times, but overall it still works. If you find a way to customize them, be sure to let us know!
e.James