1Băluță Cristian https://github.com/ralcr
Things to coverArchitectureImplementationCocoa vs FlashFuture2
Why?FunNo viable alternativeSpeedPassionKnowledge3
4iOS appscan be built with: Xcode, Haxe NME, one of thehundreds of HTML5 frameworks, Flash IDE,Unity
5Beautiful syntax- (int)changeColorToRed:(float)r green:(float)g blue:(float)b;[myColor changeColorToRed:5.0 green:2.0blue...
Architecture6
7.hxHxobjchaxelibsSupportingFileshxcocoa
8Compiler flags-objc-platform : iphone, ipad, ios, universal-objc-version : 4.0 - 6.1-objc-bundle-version : 1.0-objc-ident...
9Compiler flags-objc-lib-objc-framework-objc-linker-flag : ObjC-ios-orientation : UIInterfaceOrientationPortrait
Implementation10
11Genobjc.ml3400 lines of codestole code from genas3 and gencppfailed to split in genobjc + genxcodecamelCasedozens of rep...
12The magic behindString -> NSMutableString categoryArray -> NSMutableArray categoryAnonymous Object -> NSMutableDictionar...
13The magic behindarray access -> hx_objectAtIndex + castingoptional arguments -> if thenclass -> interface + implementati...
14Special classesnew SEL(method) -> @selector(method:arg:)new CGRect -> CGGeometry.CGRectMake()Concurrency -> static C met...
15Nullreplaced by nil or [NSNull null] in arraysobjective-c is a dynamic languagewhen it encounters a nil is not doing any...
16Dynamicit’s replaced by ‘id’‘id’ is used as a return of a constructor or canhold any objectbut can’t hold primitive valu...
17Metadata@:include -> #import <someheader.h>@:import -> #import “someheader.h”@:sel(“methodName:arg1:arg2:”)@:framework@:...
18Not workingReflect, Type, Ereg, Xml, Resourcesprimitives as objectssys, unit testsDynamic and untyped callscomplex enums...
19Memoryit’s done with ARC (automatic ref. counting)
20Memoryif you follow good programming principles you’llnot have leaks, but if you have try the @:weakmetadata
Cocoa, CocoaTouch21
22Do not reinventthe wheel
23Hxcocoahaxelib3 main packages: objc, ios, osxobjc: foundation, graphics, network, location,store, audio videoios: ui, ma...
24Lib.hxeach package has it’s own Lib.hxgeneric: log, printf, println, location, getURLios: attach, enumerateLibraryGroups...
25MVCControllerViewModel
26MVCControllerViewModelwill, should, diddata at, countdata sourcedelegate actiontargetNotifications& KVO
27ViewControllerlifecyclepublic function new ()override public function viewDidLoad ()override public function viewWillApp...
28Flash vs CocoaSprite -> UIViewx, y, width, height -> frame.origin, frame.sizeaddChild -> addSubviewclipsToBounds, backgr...
29Flash vs CocoaEventDispatcher -> Delegate andUINotificationCentre
30Flash vs CocoaTouchEvent -> UITouchoverride public function touchesBegan (touches:NSSet,withEvent:UIEvent) :Void {	 	 va...
31Flash vs CocoaMouseClick -> target-action patternbut.addTarget (this, new SEL(touch),UIControlEventTouchUpInside);but.ad...
32CoreAnimationUIView animationhidden, frame, alpha, transformthe properties are set immediately but theappearance is anim...
33Debuggingtraces are converted to println with Haxe posinformationnative NSLogInstrumens for finding leaks and profiling
34BenchmarksCompile time:Hxobjc - all utest takes 0.8 secNME - seconds to minutesSize:Hxobjc - almost as the .hx filesNME ...
35BenchmarksRuntime1mil mutable strings takes 2.5 sec comparing to1mil strings 0.012 secAdding this strings to an array ta...
Future36
37FutureImplement all the standard libraryobjc and ios externsosx externsbypass Xcode manual compilationsdk.ralcr hxobjc s...
38.hxHxobjchaxelibsSupportingFiles
39Distant future
402025Compile serverside would be niceHxobjcServer
Questions?41
Upcoming SlideShare
Loading in …5
×

Native iOS apps with haxe objective-C target

6,981 views

Published on

wwx2013 speech: Cristian Băluță "Native iOS apps with haxe objective-C target"

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
6,981
On SlideShare
0
From Embeds
0
Number of Embeds
2,522
Actions
Shares
0
Downloads
17
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Native iOS apps with haxe objective-C target

  1. 1. 1Băluță Cristian https://github.com/ralcr
  2. 2. Things to coverArchitectureImplementationCocoa vs FlashFuture2
  3. 3. Why?FunNo viable alternativeSpeedPassionKnowledge3
  4. 4. 4iOS appscan be built with: Xcode, Haxe NME, one of thehundreds of HTML5 frameworks, Flash IDE,Unity
  5. 5. 5Beautiful syntax- (int)changeColorToRed:(float)r green:(float)g blue:(float)b;[myColor changeColorToRed:5.0 green:2.0blue:6.0];function changeColorToRed (red:Float,green:FLoat, blue:FLoat) :Int;myColor.changeColorToRed (5.0, 2.0, 6.0);
  6. 6. Architecture6
  7. 7. 7.hxHxobjchaxelibsSupportingFileshxcocoa
  8. 8. 8Compiler flags-objc-platform : iphone, ipad, ios, universal-objc-version : 4.0 - 6.1-objc-bundle-version : 1.0-objc-identifier-objc-owner-objc-bundle-name-objc-supporting-files
  9. 9. 9Compiler flags-objc-lib-objc-framework-objc-linker-flag : ObjC-ios-orientation : UIInterfaceOrientationPortrait
  10. 10. Implementation10
  11. 11. 11Genobjc.ml3400 lines of codestole code from genas3 and gencppfailed to split in genobjc + genxcodecamelCasedozens of repetitive matches of type ‘t’
  12. 12. 12The magic behindString -> NSMutableString categoryArray -> NSMutableArray categoryAnonymous Object -> NSMutableDictionaryDate -> NSDate categoryprimitive -> primitivestatic -> static + getter + setter methodsdynamic func -> property + method + blocknew -> init. other inits are disabled
  13. 13. 13The magic behindarray access -> hx_objectAtIndex + castingoptional arguments -> if thenclass -> interface + implementationinterface -> protocolenum -> enum
  14. 14. 14Special classesnew SEL(method) -> @selector(method:arg:)new CGRect -> CGGeometry.CGRectMake()Concurrency -> static C methodsIterator?
  15. 15. 15Nullreplaced by nil or [NSNull null] in arraysobjective-c is a dynamic languagewhen it encounters a nil is not doing anythingyour app will not crashbut you might wonder why is not working
  16. 16. 16Dynamicit’s replaced by ‘id’‘id’ is used as a return of a constructor or canhold any objectbut can’t hold primitive values‘id’ does not require the *
  17. 17. 17Metadata@:include -> #import <someheader.h>@:import -> #import “someheader.h”@:sel(“methodName:arg1:arg2:”)@:framework@:weak@:c@:category@:getterBody
  18. 18. 18Not workingReflect, Type, Ereg, Xml, Resourcesprimitives as objectssys, unit testsDynamic and untyped callscomplex enumsInt32, Int64, Utf8, iostring + primitive concatenationimport one file into another and vice versa.
  19. 19. 19Memoryit’s done with ARC (automatic ref. counting)
  20. 20. 20Memoryif you follow good programming principles you’llnot have leaks, but if you have try the @:weakmetadata
  21. 21. Cocoa, CocoaTouch21
  22. 22. 22Do not reinventthe wheel
  23. 23. 23Hxcocoahaxelib3 main packages: objc, ios, osxobjc: foundation, graphics, network, location,store, audio videoios: ui, map, gl, assets, addressbook, iAd,mediaplayer, social, telephonyosx: addkit, webkitSupportingFiles : ios launch images and icons
  24. 24. 24Lib.hxeach package has it’s own Lib.hxgeneric: log, printf, println, location, getURLios: attach, enumerateLibraryGroups,fetchCameraItemsInGroup, isIpad, isIpod, alert
  25. 25. 25MVCControllerViewModel
  26. 26. 26MVCControllerViewModelwill, should, diddata at, countdata sourcedelegate actiontargetNotifications& KVO
  27. 27. 27ViewControllerlifecyclepublic function new ()override public function viewDidLoad ()override public function viewWillAppear ()override public function viewDidAppear ()override public function didReceiveMemoryWarning ()override public function viewDidDisappear ()override public function dealloc ()
  28. 28. 28Flash vs CocoaSprite -> UIViewx, y, width, height -> frame.origin, frame.sizeaddChild -> addSubviewclipsToBounds, backgroundColorvar sprite = new Sprite();sprite.x = 0;sprite.y = 0;var sprite = new UIView();var frame:CGRect = sprite.frameframe.origin.x = 0;frame.origin.y = 0;sprite.frame = frame;
  29. 29. 29Flash vs CocoaEventDispatcher -> Delegate andUINotificationCentre
  30. 30. 30Flash vs CocoaTouchEvent -> UITouchoverride public function touchesBegan (touches:NSSet,withEvent:UIEvent) :Void { var touches :Array = withEvent.touchesForView(this); var aTouch :UITouch = touchesForView.anyObject(); var pos :CGPoint = aTouch.locationInView(this);}this.addEventListener (TouchEvent.TOUCH_BEGIN, tapHandler);function touchHandler(e:TouchEvent) {var x = e.localX;var y = e.localY;}
  31. 31. 31Flash vs CocoaMouseClick -> target-action patternbut.addTarget (this, new SEL(touch),UIControlEventTouchUpInside);but.addEventListener (MouseEvent.MOUSE_CLICK, touch);
  32. 32. 32CoreAnimationUIView animationhidden, frame, alpha, transformthe properties are set immediately but theappearance is animatedUIView.animateWithDuration (duration:Float, delay:Float,options:UIViewAnimationOptions, animations:Void->Void,completion:Bool->Void);
  33. 33. 33Debuggingtraces are converted to println with Haxe posinformationnative NSLogInstrumens for finding leaks and profiling
  34. 34. 34BenchmarksCompile time:Hxobjc - all utest takes 0.8 secNME - seconds to minutesSize:Hxobjc - almost as the .hx filesNME - beyond imagination
  35. 35. 35BenchmarksRuntime1mil mutable strings takes 2.5 sec comparing to1mil strings 0.012 secAdding this strings to an array takes 5sec for themutable string and 0.46 for the simple strings
  36. 36. Future36
  37. 37. 37FutureImplement all the standard libraryobjc and ios externsosx externsbypass Xcode manual compilationsdk.ralcr hxobjc support
  38. 38. 38.hxHxobjchaxelibsSupportingFiles
  39. 39. 39Distant future
  40. 40. 402025Compile serverside would be niceHxobjcServer
  41. 41. Questions?41

×