Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You have to use a .h file, just like with .m files, to declare what you're doing in another file. So, you need something like this for this scenario (these are incomplete):</p> <p><strong>returnfloat.c</strong></p> <pre><code>float returnFloat() { return 10.0; } </code></pre> <p><strong>returnfloat.h</strong></p> <pre><code>float returnFloat(void); </code></pre> <p><strong>usefloat.m</strong></p> <pre><code>#import "returnfloat.h" - (void) someMethod { float ten = returnFloat(); } </code></pre> <p>The problem (given away by your "implicit declaration" warnings) is that the compiler is assuming that you are calling something that returns an <code>int</code> or <code>id</code>, not a <code>float</code>. When you work with C, things need to be prototyped (GCC will treat the .c file like C, and all C rules apply, even though you're in an Objective-C project).</p> <hr> <p>If you'd like to see an example, here's something from one of my projects -- production code (you can write pure C in a file ending in .m, and GCC will treat it like Objective-C in some ways):</p> <p><strong>DebugF.m</strong></p> <pre><code>#import "DebugF.h" void __Debug(const char *file, int line, NSString *format, ...) { #ifdef DEBUG /* Wraps NSLog() with printf() style semantics */ #endif } </code></pre> <p><strong>DebugF.h</strong></p> <pre><code>#ifndef __DEBUGF_H_INCLUDED__ #define __DEBUGF_H_INCLUDED__ #ifdef DEBUG #define DebugF(args...) __Debug(__FILE__, __LINE__, args) #else #define DebugF(...) #endif /* DEBUG */ void __Debug(const char *file, int line, NSString *fmt, ...); #endif /* __DEBUGF_H_INCLUDED */ </code></pre> <p><strong>SomeViewController.m</strong></p> <pre><code>DebugF(@"Got these arguments: %u, %@, %@", 4, anObject, [anObject somethingElse]); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload