Organizing C code in my Xcode project

I want to include some direct C functions in my Objective C project. Simple things like this:

CGPoint vectorSum (CGPoint point1, CGPoint point2) {
    return CGPointMake(point1.x+point2.x, point1.y+point2.y);
}

What is the best way to organize events?

In particular, I notice that when I go to create a .c file, it gives me the opportunity to create a header file. Is this a useful thing?

EDIT - adding more details:

I can get everything to work by telling Xcode to create the Objective-C class "VectorSum", removing the actual title and implementation of the class, defining the above vectorSum function in the implementation file and having the header file contains the following:

#import <Foundation/Foundation.h>

CGPoint vectorSum (CGPoint point1, CGPoint point2);

This works, but it seems β€œwrong." Why do I start by creating an objective C class when I really want C code?

, Xcode, C, . , , , CGPoint. , zillion, , Xcode C.

+3
1

C- objective-C (Cocoa/Foundation/etc).

C...

.

#include <ApplicationServices/ApplicationServices.h>

#include <CoreFoundation/CoreFoundation.h>

Xcode .m, .c, .m.

, , .

+1

Source: https://habr.com/ru/post/1753617/


All Articles