Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Aug 29, 2008, 01:09 PM   #1
Fontano
macrumors member
 
Join Date: Jun 2008
XCode; Method signatures inserting them into the code

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.
Fontano is offline   0 Reply With Quote
Old Aug 29, 2008, 01:50 PM   #2
kpua
macrumors 6502
 
Join Date: Jul 2006
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)
kpua is offline   0 Reply With Quote
Old Aug 29, 2008, 02:57 PM   #3
Cromulent
macrumors 603
 
Cromulent's Avatar
 
Join Date: Oct 2006
Location: The Land of Hope and Glory
I'm not quite sure what you mean? Is that like the class modelling tool included in Xcode 3/3.1 or something different?
__________________
Neural Advance - Mac OS X, UNIX and Windows Development
Last.fm Profile | Extreme Metal Reviews
MP 4x 2.66Ghz Xeons / 6GB RAM / 640GB + 500GB + 750GB + 1TB HDDs / ATI Radeon 4870 / iPad 3
Cromulent is offline   0 Reply With Quote
Old Aug 29, 2008, 03:27 PM   #4
lee1210
macrumors 68040
 
lee1210's Avatar
 
Join Date: Jan 2005
Location: Dallas, TX
Quote:
Originally Posted by Cromulent View Post
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.

Last edited by lee1210; Aug 29, 2008 at 04:07 PM. Reason: Dumb typo
lee1210 is offline   0 Reply With Quote
Old Aug 29, 2008, 03:42 PM   #5
Cromulent
macrumors 603
 
Cromulent's Avatar
 
Join Date: Oct 2006
Location: The Land of Hope and Glory
Quote:
Originally Posted by lee1210 View Post
I'm not sure what the class modeling tool is
This is what I was referring to: Xcode Design Tools for Class Modelling.

Quote:
Originally Posted by lee1210 View Post
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.
__________________
Neural Advance - Mac OS X, UNIX and Windows Development
Last.fm Profile | Extreme Metal Reviews
MP 4x 2.66Ghz Xeons / 6GB RAM / 640GB + 500GB + 750GB + 1TB HDDs / ATI Radeon 4870 / iPad 3
Cromulent is offline   0 Reply With Quote
Old Aug 29, 2008, 03:45 PM   #6
Fontano
Thread Starter
macrumors member
 
Join Date: Jun 2008
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.
Fontano is offline   0 Reply With Quote
Old Aug 29, 2008, 04:10 PM   #7
lee1210
macrumors 68040
 
lee1210's Avatar
 
Join Date: Jan 2005
Location: Dallas, TX
Quote:
Originally Posted by Fontano View Post
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.

Last edited by lee1210; Aug 29, 2008 at 04:38 PM.
lee1210 is offline   0 Reply With Quote
Old Aug 30, 2008, 04:14 PM   #8
Sayer
macrumors 6502a
 
Sayer's Avatar
 
Join Date: Jan 2002
Location: 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.
__________________
Obama is a true statesman whose experience as a state senator, half-term US Senator & guest lecturer in a Constitutional Law class has fully prepared him to take control of our nuclear arsenal.-Me
Sayer is offline   0 Reply With Quote
Old Sep 7, 2008, 04:08 AM   #9
lee1210
macrumors 68040
 
lee1210's Avatar
 
Join Date: Jan 2005
Location: 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/mact...ode/index.html
Attached Files
File Type: txt 40-superclassSkeletonsToClipboard.pl.txt (3.3 KB, 125 views)
File Type: txt 30-protocolSkeletonsToClipboard.pl.txt (1.4 KB, 137 views)

Last edited by lee1210; Sep 7, 2008 at 01:02 PM.
lee1210 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Fake Code Sign Xcode 5 newtoiphonesdk iPhone/iPad Programming 1 Jan 22, 2014 10:17 AM
How to code a newsfeed in Xcode ebbandflow1 iPhone/iPad Programming 0 Jan 9, 2014 03:35 PM
Building and Running C++ Code from within XCode 5 Duroduto Mac Programming 2 Nov 19, 2013 04:16 PM
Getting a bad access code in xcode 31rhcp Mac Programming 7 Aug 21, 2013 10:26 PM
Xcode telnet code MagicJordan iPhone/iPad Programming 0 Oct 8, 2012 05:01 PM

Forum Jump

All times are GMT -5. The time now is 01:54 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC