12

I have the method:

- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section 
{
    return items.count;
}

What I do now is to copy the whole first line and then remove the words about the formal parameters. Is there a better way to copy the method name so that I can get tableView:numberOfRowsInSection: quickly?

Hamed Ghadirian
  • 6,159
  • 7
  • 48
  • 67
Jeff.Lu
  • 574
  • 3
  • 16
  • Xcode autocomplete in Swift is probably the fastest way instead of copy pasting obj-c. – Kalzem Nov 23 '15 at 02:19
  • Yes, autocomplete is a effective way in writing code. The reason I want to copy the method name is that I am documenting something where I have to list the method name. – Jeff.Lu Nov 23 '15 at 02:24
  • If you want to document your class hierarchy consider the native markup: http://stackoverflow.com/q/19168423/1271826. Then you have documentation right in Xcode. And if you use appledoc, you can generate external HTML documentation from this, too. – Rob Nov 23 '15 at 02:29

3 Answers3

30

In Xcode 7.3 and above you can simply do the following:

Given a class ReportsListViewController and the -tableView:numberOfRowsInSection: method:

To "Copy Qualified Symbol Name"

Place your cursor anywhere on a method name. Press Shift-Cmd-Ctrl-Option-c (All the modifiers) - This will place the following in your clipboard:

-[ReportsListViewController tableView:numberOfRowsInSection:]

To "Copy Symbol Name"

Place your cursor anywhere on a method name. Press Shift-Cmd-Ctrl-c - This will place the following in your clipboard:

-tableView:numberOfRowsInSection:
DeepFriedTwinkie
  • 3,865
  • 1
  • 21
  • 21
  • Considering when [this tweet](https://twitter.com/joar_at_work/status/765293744736260096) was posted, it's probably available earlier (likely Xcode 7). – Dominic K Aug 24 '16 at 22:26
  • Thank you very much, this should the shortcuts what I want. Thi should be the answer. Sorry I cannot mark it as I have marked another one. Thanks again. – Jeff.Lu Aug 31 '16 at 10:55
  • 1
    Both of the 2 ways also work with the latest Xcode and swift 3. E.g, I copied this method: webView(_:shouldStartLoadWith:navigationType:). – Golden Thumb Apr 20 '17 at 17:44
  • glad I bothered to google this again (back to Objective-C, long story), thanks!!! – Dan Rosenstark Feb 11 '20 at 19:42
0

you can use the Xcode's code snippet library. In Xcode,View->Show Code Snippets Library Select the code ,Long press on it,then you can find it being dragging,put it in the code snippet library,name an other name,such as “tns”

lsdoy
  • 129
  • 12
-1

This seems not very nice, but you can right-click on method name, then Refactor -> Rename and Cmd+C to copy method name.

For even better access you can set the shortcut for this in Xcode -> Preferences -> Key Bindings -> Rename. That will require one click on method name and two shortcuts for getting signature

medvedNick
  • 4,512
  • 4
  • 32
  • 50
  • thanks for the answer. Anyway two shortcuts are more quick than the copy + paste + remove. – Jeff.Lu Nov 24 '15 at 02:44
  • There's an even easier method: You can right-click on any part of method name, and choose "Find Selected Symbol in Workspace". The whole name will appear in the search field. – Grzegorz D. May 25 '16 at 09:46