Are you new? Read the FAQ and catch up on!
7k views

Hola mundo para el iPhone

El hola mundo más básico que encontrado para el iPhone. Lo encontré en un post de O'Reilly.

Makefile:

GNU make
  1. CC=arm-apple-darwin-cc
  2. LD=$(CC)
  3. LDFLAGS=-lobjc -framework CoreFoundation -framework Foundation -framework UIKit -framework LayerKit -framework CoreGraphics
  4.  
  5. all:    SampleApp
  6.  
  7. SampleApp:  mainapp.o SampleApp.o
  8.     $(LD) $(LDFLAGS) -v -o $@ $^
  9.  
  10. %.o:    %.m
  11.         $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
  12.  
  13. clean:
  14.         rm -f *.o SampleApp
  15.  

­

mainapp.m

Objective-C
  1. #import <UIKit/UIKit.h>
  2. #import "SampleApp.h"
  3.  
  4. int main(int argc, char **argv)
  5. {
  6.     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  7.     return UIApplicationMain(argc, argv, [SampleApp class]);
  8. }
  9.  

­

SampleApp.h

Objective-C
  1. #import <CoreFoundation/CoreFoundation.h>
  2. #import <Foundation/Foundation.h>
  3. #import <UIKit/CDStructures.h>
  4. #import <UIKit/UIWindow.h>
  5. #import <UIKit/UIView-Hierarchy.h>
  6. #import <UIKit/UIHardware.h>
  7. #import <UIKit/UIKit.h>
  8. #import <UIKit/UIApplication.h>
  9. #import <UIKit/UITextView.h>
  10. #import <UIKit/UIView.h>
  11.  
  12. @interface SampleApp : UIApplication {
  13.     UIView      *mainView;
  14.         UITextView  *textView;
  15. }
  16.  
  17. @end
  18.  

­

SampleApp.m

Objective-C
  1. #import "SampleApp.h"
  2.  
  3. @implementation SampleApp
  4.  
  5. - (void) applicationDidFinishLaunching: (id) unused
  6. {
  7.     UIWindow *window;
  8.     struct CGRect rect = [UIHardware fullScreenApplicationContentRect];
  9.     rect.origin.x = rect.origin.y = 0.0f;
  10.  
  11.     window = [[UIWindow alloc] initWithContentRect: rect];
  12.     mainView = [[UIView alloc] initWithFrame: rect];
  13.     textView = [[UITextView alloc]
  14.         initWithFrame: CGRectMake(0.0f, 0.0f, 320.0f, 480.0f)];
  15.     [textView setEditable:YES];
  16.     [textView setTextSize:14];
  17.  
  18.     [window orderFront: self];
  19.     [window makeKey: self];
  20.     [window _setHidden: NO];
  21.     [window setContentView: mainView];
  22.     [mainView addSubview:textView];
  23.  
  24.     [textView setText:@"Hello World"];
  25. }
  26. @end
  27.  

­

Tags: Makefile Objective C Hello World iphone

Embed: