I'm trying to use boost's network_v4 class and included boost/asio.hpp convenience header as stated in documentation network_v4.
Actually it's not included there and I get 'network_v4': is not a member of 'boost::asio::ip' error. Only including boost/asio/ip/network_v4.hpp header solves the issue. Is this normal?
Related
I'm trying to write some code that uses git_diff_perfdata from the Libgit2 library.
git_diff_perfdata s;
However, when compiling on my Mac I get the error:
use of undeclared identifier 'git_diff_perfdata'
My understanding is that Libgit2 is meant to be used exclusively through the inclusion of git2.h. Is that correct?
git_diff_perfdata is defined in sys/diff.h and used in status.h
Should I be including sys/diff.h directly. If so, why? Alternatively, what errors might I be making? Looking at the header code I'm unable to see how sys/diff.h is included through anything that is included by git2.h.
Additionally, from what I can tell git_diff_perfdata isn't meant to be an opaque data type (i.e. only the pointer is defined).
I'm using the code downloaded from:
https://github.com/libgit2/libgit2/archive/v0.26.0.zip
The headers in sys are part of the public API, but they're a bit lower level. You can think of them as internal implementation details that have been made public because they might be useful to application developers. If you want to use them, include them directly.
So I think I have this kinda clear, based on this blog post and my experiments:
what's included by #import MyPod; is the auto-generated MyPod-umbrella.h header, which imports all the public headers according to the Podspec
the auto-generated module map also permits explicit import of those and only those same public headers
what's included by #import <MyPod/MyPod.h> header is a MyPod.h header that I still need to make, but it can import anything I choose that's in the module map
What I was hoping to achieve, however, was that the header for either #import or #import to include most but not all of my pod's public headers. I'd like one of my public headers contain optional declarations that are normally omitted, to only be included manually from the few .m files that need it. But it seems to not be possible when code uses #import since the includes in that umbrella header always matches all the public headers.
Specifying a custom module map is possible and would work, but doing that seems to precludes the benefits of auto-generated map & umbrella header.
Would it be kosher to do some macro & #ifdef tricks to skip the contents of my "optional" header when included by the #import but then use the contents if that header is pulled in again with an #include? This sounds ugly, but is it my only option?
I found problems with all the #ifdef tricks I attempted when using framework cocoapods, though I'm sure they'd work when not. But I don't really want to be biased against frameworks and would like a solution for both.
So to take another approach, I found its not hard for a project to access a pod's private headers! See here and here (that last tip is for Swift, but I'm sure the right #import will work in Objective-C too).
So in my cocoapod I'm going to make the optional header private, and then rely on my users to use those methods to access it if desired.
I've noticed that while editing header files, XCode does not auto-suggest header files to import or classes from imported files unless the file you are editing is itself imported by some file that is included in the target.
I kind of get the reasons for this, but it's super lame. I'm very happy to take the trade off of disappointment at compile time (oops! that wasn't a class that I could import) for the benefit of saving a ton of time while writing headers.
By the way I'm aware that I can use forward class and protocol declarations but this is not helpful because I often need to use something whose name I've not committed to memory. Once I know the thing to forward-declare, then I will!
Is there any way to get XCode to be more liberal about this?
Edit: with pictures
Here's what I see in a header file included by an implementation file that is added to a target when I type the letters "#i":
Now I comment out the include of the header I was editing
Now here's what I get - but autocomplete still works
When I make a new protocol, of course it is not imported by some implementation file (because it is new and it is not a class, so there is no associated implementation file already created).
So autocomplete of imports (and classes) doesn't work... until I import it from an implementation
And now autocomplete works
Hi I am new to the object-c and this might be silly question. I studied that I have to assign the name of the method on the header file(.h file) before I make a logic in m file. But I found some of examples assigning method only in the m file not from h file. And it works ok. I'm slightly confused what to follow now. Please explain me the difference.
All methods that shall be publicly available in your project go to the .h-file. If you want the method to be kind of private, don't add it to the h.-file but define it in the .m-file.
The newest versions of Xcode include a compiler that allows you to skip the declaration in the header file if you just are going to use the method in the same .m file in which it is defined.
That is probably what you have seen.
The same newer versions of Xcode also allow you to declare ivars in the .m file, which also contributes to simpler header files and a higher degree of locality in the implementation files.
Note: This is similar to this question but it is not the same. I promise.
I have a series of table views that call upon a modal view for sorting the table's contents. To do this, I set up a simple protocol in one table view controller's header file and it worked great. I then copied this protocol over to my other table view controllers and got this warning:
Duplicate protocol definition of 'ModalViewDelegate' is ignored
Now I realize it is just a warning, but I would rather not see it every time I compile. To get rid of the warnings, I imported the header file in which the protocol was originally defined. Once again, I was not completely satisfied. It seems sloppy to import the header file to every table view just so I can use the protocol without warnings.
If you have read this far, I thank you. My questions are 'Why is this happening? Is there a better way of getting rid of this warning while still using the same protocol?'
Is there a better way of getting rid of this warning while still using the same protocol?
The compiler needs to know about the protocol in order for you to refer to it. There's two ways you can make that happen: import the header where the protocol is declared into the files where you're using it, or make a forward declaration of the protocol in those files: #protocol MyProtocol;. The second is really only useful when protocols need to refer to each other (to avoid circular imports); if a class needs to adopt the protocol, it needs to see the declarations of the methods in the protocol, which means it needs to see the protocol declaration itself, i.e., the header.
It seems sloppy to import the header file to every table view just so I can use the protocol without warnings.
This is not sloppy, it's the way things work. It sounds like it may make sense for you to put the protocol declaration into its own header and import that wherever it's needed.
I discovered a similar warning where a #protocol was defined within the header of a class. Breaking that protocol out into its own .h and importing it elsewhere fixed it.