I am currently making some decisions for my first objective-c API. Nothing special, just help yourself a bit to make things faster in the future.
After reading a few hours about different templates, such as creating categories, singletons, etc., I got something that I like because it is easy for me to support me. I am creating a set of useful functions that can be useful everywhere.
So what I did:
1) I created two new files (.h, .m) and gave the โclassโ a name: SLUtilsMath, SLUtilsGraphics, SLUtilsSound, etc. I think of it as a "namespace", so all of these things will always be called SLUtils ******. I added them to the SL group containing the SLUtils subgroup.
2) Then I just put my function signatures in the .h file and the function implementations in the .m file. And guess what: It works! I am pleased with this and it is easy to use. The only unpleasant thing is that I have to include the appropriate header every time I need it. But this is normal, as it is normal. I could include it in the header header prefix file.
But then I went to the toilet, and a ghost appeared there, saying: โHey, isnโt it better to create real methods, not functions? Should you not create cool methods so that you call a method and not a function? Isn't that a lot cooler and doesn't have the best performance? " Well, for readability, I prefer features. On the other hand, they do not have such "named parameters" as methods, afaik.
So what would you prefer in this case?
, . .
, . . , :
MYNAMESPACECoolMath.h
#import <Foundation/Foundation.h>
@interface MYNAMESPACECoolMath : NSObject {
}
+ (float)randomizeValue:(float)value byPercent:(float)percent;
+ (float)calculateHorizontalGravity:(CGPoint)p1 andPoint:(CGPoint)p2;
@end
MYNAMESPACECoolMath.h :
CGFloat myValue = [MYNAMESPACECoolMath randomizeValue: 10.0f byPercent: 5.0f];
, , , . java, .
, , . CGRectMake (10.0f, 42.5f, 44.2f, 99.11f) , , , , . "named", , .
, , , /, . , . . . . .