Header files without implementation - objective-c

I'm working on a open source project, which consist on a framework for iOS devices, and one of the methods is not working as I expected. I tried to search for the implementation of the method, but all I found was a a header file and the method declaration; I didn't find the implementation anywhere. Neither did I find the .m file corresponding to that class.
So I have some questions:
How can a class exist without it's implementation and still its methods perform certain operations?
What is the purpose of writing this kind of classes.
In this kind of situations where should be the methods implemented?
Note
The open source project is FastPdfKit and the method is wholeTextForPage:

Well, those methods are somewhere, so it's not that they don't exist, you just can't see them.
Try for example to open UITableView.h, you can see the methods definition, but not the implementation. The implementation is hidden in the library, but you can't see it.
In a nutshell, developers do this to hide the details of the implementation of a class to other users. You just receive a header that tells you which methods you can use, and how, but the details about how are they implemented are hidden for you.
For example, Apple doesn't want you to see how they implemented UITableView, but they want you to know how you can use it.
Here you can find a tutorial about how to create a library for Objective-C:
Creating Static Libraries for Objective-C

Related

How to organize Kotlin extension methods

Let's say I have a few extension methods for "MyClass".
My question is, what's the best practice to organize/store these methods?
Should they be simply put into a "MyClassExtensions" Kotlin file?
I have tried to encapsulate these methods within a class, but after importing the class I couldn't seem to figure out how to use/access the extension methods.
Edit:
For clarification, I was not asking for help what to call a file that contains extension methods. I was asking about best practices/approaches to store/organize such methods. Ie. should they be simply put into kotlin files, or should they be encapsulated in a class. I am coming from a Java background, so I'm used to store stuff in classes.
As far as I am concerned, you should put them into a utility file, as you did in Java code base before.
But mention, you no longer need to put them into a class. Top-level functions are the best choice.
You can refer to the kotlin standard library or some open source projects like anko, those would be good examples.
In my case, I put extensions of one class into a file which have the same name of the original file in another package, and use
#JvmMultifileClass
to reduce the number of generated class files.

In Objective-C, what is the standard way of extending and augmenting the behaviour of init?

Categories are used in Objective-C to implement extensions onto existing classes.
This is great for supplying new methods that could be used, but does not necessarily help augmenting behaviours of the existing class methods.
In particular, I'm interested in extending init methods and customize them such that necessary set up for my category is performed at object initialization time. If you must know, these are ReactiveCocoa signals that I'd like set up once per object lifetime. This ideally should go in init.
The obvious way of doing this is to call a setUpXYZExtension method defined in the category directly from init. However, this means the main source file now has knowledge of the extension. i.e. deleting the extension source file will lead to a compile error because the method setUpXYZExtension will not be found.
Is there a potentially neater way of doing this, such that when the category's source file is deleted, there is no compile error?
Not sure about this being standard but you can look at method swizzling. Swizzling allows you to either extend or exchange the implementation of methods of current classes.
http://nshipster.com/method-swizzling/

Auto-generate Objective-C method headers from implementation?

Is there a tool that will take a list of Objective-C methods and produce the corresponding header definitions?
Often when writing code in my implementation file, I find I need to add, remove, or modify method definitions. This requires the tedious (and thoroughly-automatable) step of switching back to my header file and making the exact same changes, twice.
What ever happened to DRY? What kind of tools can I use to make life easier here? Thanks.
You can try Accessorizer:
http://www.kevincallahan.org/software/accessorizer.html
It automates most work regarding properties, it might work for methods too.
Sadly, it's not free.
I don't know of any existing tools (although Interface Builder does allow you to define outlets and actions, and then generate a header and implementation skeleton for you based on those). Remember though that the implementation file can contain information that should not go in the header (such as private methods and instance variables/properties), so it would be difficult for any tool to do this in any case.
For the moment, in Xcode, you can split the window and see both side by side (in Xcode 4, this is the Assistant). Alternatively, you can press Alt-Command-UpArrow to see the corresponding file.

Can one autogenerate a protocols stubs

Still waiting on my MacBook.
When an interface that I create references a protocol e.g. CCLocationManagerDelegate does the various methods get autogenerated or does intellisense pop up with all the available methods to implement?
Xcode doesn't do this unless the methods are in a template file (and I'm not aware of a template for a <CLLocationManagerDelegate>.
That being said, you might want to check out Accessorizer, which is a neat app that can do a whole bunch of code generation for you, of which (I believe) protocol conformance is a part.

Xcode: Possible to auto-create stubs for methods required by Protocol interface?

Coming from an Eclipse / Java background, one of my favorite features is the ability to quickly stub out all the methods required by an interface. In Eclipse, I can choose 'Override / implement' from the source menu to generate stub methods for any method of the Interface.
I'd like to do the same thing in Objective-C. For instance, if I declare a class that implements the 'NSCoding' protocol, I'd like to have Xcode automatically generate the methods required to implement this Protocol. It's frustrating to have to look-up and then copy/paste the signatures of the required methods every Protocol that I'm trying to implement.
I've been trying for awhile to find out if this is possible, but haven't found anything promising yet. Is this possible in XCode?
I believe that Accessorizer will do what you want.
Accessorizer will write the encode and decode methods for ivars passed to it (NSCoding protocol and for NSDocument archiving). It will also generate string constants either static or #define with a custom prefix; copyWithZone:; and other things if you need - all from a simple shortcut via Services or from the toolbar. Accessorizer keyed archiving
Not the direсt answer, just hint:
Out of the box XCode can't.
But AppCode can.
It can do this things automatically (with your permission, of course).
If some methods of protocol marked as #required - AppCode will highlight the implementation and suggest to implement this methods.
#optional methods also available to implement automatically (shortcut: control + I).
Your can create scripts for the scripting menu item in AppleScript, Perl, Python, Ruby, or any other scripting language that go in the scripting menu.
Your could place the insertion point in the .m file and have the script look up the corresponding .h file. Locate the protocols supported and so forth...
MacTech ran an article in 2007 Xcode Menu Scripts
Xcode 3.2 will autocomplete known method implementations. In other words, if the method is declared somewhere (for example, in a protocol), when you start to type it in a .m file, Xcode 3.2 will autocomplete the method signature for you. This isn't quite what you asked for, but it is awfully handy.
I'm also looking for a way to generate method stubs for the protocols in my header file. I checked out Accessorizer and it looks to be a handy tool but unless I missed something I didn't find a way to get it to generate method stubs for a protocol.
Eric, If you found another solution please post what you found. It's amazing to me that XCode doesn't already have this built into the IDE.
Since the accepted answer's given link does not work anymore (and is redirected to an ad), here's another good explanation on how to use accessorizer to create protocol method stubs.
Based on AllanCraig's "Create #property, #synthesize & dealloc from Variable Declaration" ruby script, I made one to generate implementation stubs from interface ones: http://pastebin.com/4T2LTBh6
How to use?
Setup the script on your XCode (Shell Script) and assign a shortcut for it (e.g. CMD+5).
Select lines from your interface file in which you want to generate the implementation, and press the hotkey.
Your .m will contain your selected methods.
I know this is an old question but if you'd like to always see the latest definitions just right click on the class in question and Jump to Definition. Here lyes all the current non-deprecated functions so you aren't relying on a 3rd party to stay up to date.
In My case Below style helps me much, In a sense solved my problem.
Suppose you have following method declaration:
+(DBManager*)getSharedInstance;
From Implementation file you start typing +ge and xcode will automatically choose method
+(DBManager*)getSharedInstance;