⬆️ ⬇️

Objective-C Minimalism

I often write small test projects on Objective-C to experiment or play with something. Usually, I put the code in main.m and get rid of everything else:



#!/usr/bin/env objc-run @import Foundation; @implementation Hello : NSObject - (void) sayHelloTo:name { printf("Hello %s, my address is %p\n", [name UTF8String], self); } @end int main () { id hello = [Hello new]; [hello sayHelloTo:@"sunshine"]; } 




This is a complete project from a single file, ready to run. Under the cut - a description of techniques that allowed to come to this minimalism.





')

Translator's note: in the absence of @interface warning warning annoys me:

 /dev/fd/63:3:17: warning: cannot find interface declaration for 'Hello' @implementation Hello : NSObject ^ 1 warning generated. 


This is a warn_undef_interface for which there is no corresponding -W flag (to silence warnings by type). So for myself, I left an empty interface.



 #!/usr/bin/env objc-run @import Foundation; @interface Hello : NSObject @end @implementation Hello - (void) sayHelloTo:name { printf("Hello %s, my address is %p\n", [name UTF8String], self); } @end int main () { id hello = [Hello new]; [hello sayHelloTo:@"sunshine"]; } 




image

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



All Articles