Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Fontano

macrumors member
Original poster
Jun 27, 2008
72
0
In Visual Studio, I had the ability to look at all the events and know methods for an inherited object and have the signature for that event/method fill into the code window, when I wanted to override or implement it.

Is there a similar method in XCode?
A way that I can see the defined Methods/Functions/Properties ..... for an inherited object. Select it and have it's signature/shell inserted into my object's .m file, so I can complete the coding.
 

kpua

macrumors 6502
Jul 25, 2006
294
0
Nope... unfortunately, that's a feature that is presently lacking in Xcode. It sure would be nice though! Why not file an enhancement request and see what happens? (bugreporter.apple.com)
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
I'm not quite sure what you mean? Is that like the class modelling tool included in Xcode 3/3.1 or something different?

I'm not sure what the class modeling tool is, but what he means is not as applicable to Objective-C as languages like Java and C++ where you can have abstract methods in the parent class that must be overwritten in a child class unless the child class is also abstract . The idea is that you can have a sort of thing that you can't have an instance of, but anything that extends/inherits from that class has access to the methods the parent does define, but must also implement the methods. You cannot actually instantiate a class until all of the abstract methods of the class(es) it extends are implemented. Other methods of the parent can also be overwritten, but they don't have to be.

The most applicable place for this in Objective-C (not sure if that's what the OP is working in, if they are working on C++ this would be a much more desirable feature) is with protocols. For example, if you created a new class, XCode could (but doesn't) allow you to define which Protocols the class will implement, and then give you skeleton methods necessary to implement all of those protocols, so you know right off the bat what you have to do. It would be a time-saver, and is worth a feature request. However, like I said, this is much more applicable in C++ and Java where the concept of abstract classes exists.

I don't know that it would be as useful when you create a class to put skeletons in for every method of the super class, as you may not want to override everything, whereas with abstract you are going to want to override everything (if you want to be able to instantiate this class).

The real drive with abstract classes is to allow a type of some sort. I'm going to be grasping for straws on this example, but we'll say animal just for kicks is your base class. You wouldn't want to just instantiate an animal. There would be very little known about the object, and it would be too vague to be useful. So animal would be abstract, and have fields like weight, length, number of limbs, number of digits, kingdom, phylum, class, order, family, genus, species, etc. that all animals have. It would implement getters and setters for these things, perhaps, and maybe some methods that get information like "canFly" that uses a few different fields (like i said this is a stretch... it might use the "hasWings" field and class equal to Aves, and species not penguin, emu, etc.). Then the class would define some abstract methods like getDescription, eats(Animal), etc. Then for each type of animal you would have a class that inherits from animal. It would override some methods as needed (say canFly now just returns a boolean that is set to true for the Quail class, etc.) and would have to override all of the abstract methods suitably.

I'm guessing no one was really asking for this information, but in my past experience with IDEs these were the cases where the feature the OP is requesting was most valuable.

-Lee

P.S. I know the animal example is somewhat contrived, i was trying to come up with something.
 

Cromulent

macrumors 604
Oct 2, 2006
6,802
1,096
The Land of Hope and Glory
I'm not sure what the class modeling tool is

This is what I was referring to: Xcode Design Tools for Class Modelling.

but what he means is not as applicable to Objective-C as languages like Java and C++ where you can have abstract methods in the parent class that must be overwritten in a child class unless the child class is also abstract . The idea is that you can have a sort of thing that you can't have an instance of, but anything that extends/inherits from that class has access to the classes the parent does define, but must also implement the methods. You cannot actually instantiate a class until all of the abstract methods of the class(es) it extends are implemented. Other methods of the parent can also be overwritten, but they don't have to be.

Ah, I see. Thanks for the info. I've got Visual Studio installed on my Vista partition, I really should see why so many people say it is better than Xcode. From my experience with it, it is a complete pain to do any C programming in.
 

Fontano

macrumors member
Original poster
Jun 27, 2008
72
0
Well here is the specific example of what I am working on...
I am using the SeismicXML as my template. The TableViewCell.m

The method:
-(id)initWithFrame.....

Is something from the baseclass UITableViewCell, which I have to define for my custom object.

So I was looking for a way from a drop down menu or some other way, to get the shell of that method into my .m

At least for this one, I know the function I need and have a full example of it, but one of the usefull things I had in VisualStudio... was I could look at a listing of methods/properties/events that I could define.
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
Well here is the specific example of what I am working on...
I am using the SeismicXML as my template. The TableViewCell.m

The method:
-(id)initWithFrame.....

Is something from the baseclass UITableViewCell, which I have to define for my custom object.

So I was looking for a way from a drop down menu or some other way, to get the shell of that method into my .m

At least for this one, I know the function I need and have a full example of it, but one of the usefull things I had in VisualStudio... was I could look at a listing of methods/properties/events that I could define.

I'd pull up the header file for the class you are overwriting. Unfortunately you'll have to make do. You could also type:
Code:
[super
then right click/ctrl+click and choose "Completion List" to see all of the methods supported by the parent. It's not what you're looking for, exactly, but might help.

-Lee

Edit: Forgot the key but it "came to me" while i was working on some example code for another post... you can type:
[super <esc>
(type the esc key there) and it will bring up the completion list, too.
 

Sayer

macrumors 6502a
Jan 4, 2002
981
0
Austin, TX
I am always holding the Command (Apple, pretzel) key down and double-clicking on methods to see their definition in some other file.

Autocomplete is okay, but it usually assumes the wrong method for me and I ignore its suggestions most of the time.

Xcode really expects you to already know what you are doing to use it I guess.
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
So I got curious how hard it would be to do this.

The method I came up with isn't ideal, but...

I have a script to pull all of the methods out of a protocol definition and put the skeletons into the clipboard to be pasted in your source file.

I thought, even though there aren't abstracts, that it might also be helpful to get all of the methods a superclass defines (though not things it has inherited) if you want to override them.

I couldn't figure out how to get plugins going, so i resorted to the user scripts. Unfortunately I could not come up with a way to get it with just the name of the superclass or protocol being highlighted in your source file. Instead, if you right click/apple click, and choose "Jump to definition". This will highlight the header of the protocol or interface/implementation. Depending on whether you have the source file for a class, you will either get the .h file with the interface line highlighted, or the .m file with the implementation highlighted. I tried to make this work with either.

I had to make some assumptions, mostly regarding things being on the same line. This isn't a requirement in the grammar, so... it won't work for everything. If most of the things you are extending use "normal" formatting it should be OK.

These are far from perfect, but I thought they might be useful for someone out there.

I have these in
/Library/Application Support/Apple/Developer Tools/Scripts/10-User Scripts/40-Code

I set up some hot keys, but they are easily changed in the scripts.

You'll have to rename them removing the .txt. I can't upload things called .pl.

Also, I didn't pick perl for any reason other than a script doing something that seemed like a good starting point was in perl. I won't pretend that this is the most elegant perl in history.

Have at it.

-Lee

P.S. This page was a lot of help writing these:
http://www.mactech.com/articles/mactech/Vol.23/23.01/2301XCode/index.html
 

Attachments

  • 40-superclassSkeletonsToClipboard.pl.txt
    3.3 KB · Views: 209
  • 30-protocolSkeletonsToClipboard.pl.txt
    1.4 KB · Views: 224
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.