Successfully reported this slideshow.
What is new on Xamarin.iOSXamarin Inc
New in Xamarin.iOS• Features added in the last year– Based on the Mono 2.10/Silverlight-ish stack• Features based on the B...
Visual Studio!Released
F# Support• Functional Programming comes to iOS!• The pitch is simple:– Fewer bugs– Focus on intent– Reuse C# libraries, e...
SIZE REDUCTIONS
TweetStation – Reference App• Comprehensive app• Networking• SQL• Background• Retina artwork• Full (unlinked)MonoTouch.Dia...
TweetStation Size Reduction6,2006,4006,6006,8007,0007,2007,4007,6004.2.2 5.0.4 5.2.13 5.4.1 6.0.10iOS 66.2.1 6.3.3.2Async(...
New: SmartLink• By default, all native code is linked-in• SmartLink merges Mono and System linker– Only code that is direc...
SmartLink effect on Samples-2,0004,0006,000All codeSmart LinkingBeta
Size Savings0100,000200,000300,000400,000500,000Savings
RUNTIME IMPROVEMENTS
Generic Value Type Sharing• Reduces these kinds of errors:Unhandled Exception: System.ExecutionEngineException: Attempting...
Source of the Error• Static compiler is unable to infer that certaingeneric methods will be used at runtime witha specific...
Generic Sharing• Consider: List<T>.Add (T x)• If “T” is a reference type:– Code can be shared between all reference types–...
Generics and Value Types• Value types use different storage:– byte – 1 byte– int – 4 bytes– long – 8 bytes• List<byte>.Add...
Generic Sharing Today• Using string, Uri, object, int, long on Add:– Generates one shareable for Uri, object, string– Gene...
With new Generic Value Type Sharing• Using string, Uri, object, int, long on Add:– Generates one shareable for Uri, object...
Shareable Value Type Generic• Runtime fallback for generic instantiations thatcould not be statically computed• Uses a “fa...
Cost of Value Type Sharing6,2006,4006,6006,8007,0007,2007,4007,6004.2.2 5.0.4 5.2.13 5.4.1 6.0.10iOS 66.2.1 6.3.3.2Async(M...
Native Crypto• System.Security.Cryptography nowpowered by iOS native CommonCrytpo• Covers– Symmetric crypto– Hash function...
SGen• SGen can now be used in production on iOS• It is no longer slower than Boehm• And much faster on most scenariosBeta
DEBUGGING AIDS
NSObject.Description• New API that provides Objective-C “ToString”• NSObject.ToString() calls Description• Sometimes overw...
Helping you write Threaded Apps• UIKit is not thread safe– No major commercial UI toolkit is thread safe– Thread safety is...
UIApplication.CheckForIllegalCrossThreadCalls• If set, accessing UI elements– Throws UIKitThreadAccessException• Most UIKi...
Thread Safe APIsThread Safe Classes• UIColor• UIDocument• UIFont• UIImage• UIBezierPath• UIDeviceKey Thread Safe Methods• ...
ASYNC
Async Support• Base Class Libraries:– Expect all the standard Async APIs from .NET BCL– Coverage is .NET 4.5 Complete for ...
Async Synchronization Contexts• For UI thread, we run a UIKit Sync Context– What you get from the main thread– Code resume...
General Async Pattern• Methods with the signature:void Operation (…, Callback onCompletion)• Become:Task OperationAsync (…...
API IMPROVEMENTS
More Strong Type Constructors• Where you saw– NSDictionary options• We now support strongly typed overloads– Give preferen...
Screen Capture• To capture UIKit views:– UIScreen.Capture ()• To capture OpenGL content:– iPhoneOSGameView.Capture ()Relea...
UIGestureRecognizersBeforevoid Setup (){var pan= new UIPanGestureRecognizer (this, new Selector (”panHandler"));view.AddGe...
UIAppearance• Previously:var appearance = CustomSlider.Appearance;appearance.SetMaxTrackImage (maxImage, UIControlState.No...
Notifications• Used in iOS/OSX to broadcast messages– Untyped registration– Notification payload is an untyped NSDictionar...
Xamarin.iOS Notifications• Discoverable, nested “Notifications class”• For example: UIKeyboard.Notifications• Pattern:– St...
Example – Full Code Completionnotification = UIKeyboard.Notifications.ObserveDidShow ((sender, args) => {// Access strongl...
NSAttributedString• On iOS 5:– Introduced for use in CoreText• On iOS 6:– It became ubiquitous on UIKit– UIKit views use i...
NSAttributedString• Standard Objective-C esque approach://// This example shows how to create an NSAttributedString for// ...
NSAttributedString – C# 4 stylevar text = new NSAttributedString ("Hello, World",font: UIFont.FromName ("HoeflerText-Regul...
AudioToolbox, AudioUnit, CoreMidi• Completed MIDI support– Our CoreMIDI binding is OO, baked into system– Equivalent to wh...
CFNetwork-powered HttpClient• Use Apple’s CFNetwork for your HttpClient– Avoid StartWWAN (Url call)– Turns on Radio for yo...
New Dispose Semantics• Changes in NSObject() Dispose• If native code references object:– Managed object is kept functional...
Razor Integration• Sometimes you want to generate HTML• Razor offers a full template system– Blend HTML and C#– Code compl...
New File -> Text Template -> RazorReleased
Razor• Creating template, passing data:– Model property, typed in cshtml filevar template = new HtmlReport () { Model = da...
THANK YOU
Upcoming SlideShare
Loading in …5
×

What's new in Xamarin.iOS, by Miguel de Icaza

2,289 views

Published on

Published in: Technology, Education
  • Be the first to comment

What's new in Xamarin.iOS, by Miguel de Icaza

  1. 1. What is new on Xamarin.iOSXamarin Inc
  2. 2. New in Xamarin.iOS• Features added in the last year– Based on the Mono 2.10/Silverlight-ish stack• Features based on the Beta channel:– Mono 3.0-based stack– SGen GC– Based on the .NET 4.5 API surfaceReleasedBeta
  3. 3. Visual Studio!Released
  4. 4. F# Support• Functional Programming comes to iOS!• The pitch is simple:– Fewer bugs– Focus on intent– Reuse C# libraries, experience– More features, less timeBeta
  5. 5. SIZE REDUCTIONS
  6. 6. TweetStation – Reference App• Comprehensive app• Networking• SQL• Background• Retina artwork• Full (unlinked)MonoTouch.Dialog
  7. 7. TweetStation Size Reduction6,2006,4006,6006,8007,0007,2007,4007,6004.2.2 5.0.4 5.2.13 5.4.1 6.0.10iOS 66.2.1 6.3.3.2Async(Mono3)Size in KBSize in KBReleased
  8. 8. New: SmartLink• By default, all native code is linked-in• SmartLink merges Mono and System linker– Only code that is directly referenced is included– Caveat: dynamic Objective-C code can fail– Big savings:Beta
  9. 9. SmartLink effect on Samples-2,0004,0006,000All codeSmart LinkingBeta
  10. 10. Size Savings0100,000200,000300,000400,000500,000Savings
  11. 11. RUNTIME IMPROVEMENTS
  12. 12. Generic Value Type Sharing• Reduces these kinds of errors:Unhandled Exception: System.ExecutionEngineException: Attempting toJIT compile method• By generating generics code that can be shared acrossvalue types– like reference types today• Enables more LINQ, RX and other generic-rich apps to runwithout changes, or without manual static stubsBeta
  13. 13. Source of the Error• Static compiler is unable to infer that certaingeneric methods will be used at runtime witha specific value type.• Because the instantiations are delayed untilruntime.Beta
  14. 14. Generic Sharing• Consider: List<T>.Add (T x)• If “T” is a reference type:– Code can be shared between all reference types– Only one List<RefType>.Add (RefType x) exists– Because all reference types use same storage (onepointer).Beta
  15. 15. Generics and Value Types• Value types use different storage:– byte – 1 byte– int – 4 bytes– long – 8 bytes• List<byte>.Add (byte x) has different codethan List<long>.Add (long x)Beta
  16. 16. Generic Sharing Today• Using string, Uri, object, int, long on Add:– Generates one shareable for Uri, object, string– Generates one for int– Generates one for long
  17. 17. With new Generic Value Type Sharing• Using string, Uri, object, int, long on Add:– Generates one shareable for Uri, object, string– Generates one for int– Generates one for long– Generates a value-type shareable• Can be used by dynamic users of Add<ValueType>Beta
  18. 18. Shareable Value Type Generic• Runtime fallback for generic instantiations thatcould not be statically computed• Uses a “fat” value type• Generates code that copies “fat” value types• Limitation: large value types can not be shared• You can disable if not needed:– -O=-gsharedvtBeta
  19. 19. Cost of Value Type Sharing6,2006,4006,6006,8007,0007,2007,4007,6004.2.2 5.0.4 5.2.13 5.4.1 6.0.10iOS 66.2.1 6.3.3.2Async(Mono3)VTSharingSize in KB Size in KB394 KbToday: For TweetStation, the cost is 394kbWe are working to reduce thisBeta
  20. 20. Native Crypto• System.Security.Cryptography nowpowered by iOS native CommonCrytpo• Covers– Symmetric crypto– Hash functions• Hardware accelerated– AES and SHA1 (when plugged)• Made binaries using crypto/https 100k lighterReleased
  21. 21. SGen• SGen can now be used in production on iOS• It is no longer slower than Boehm• And much faster on most scenariosBeta
  22. 22. DEBUGGING AIDS
  23. 23. NSObject.Description• New API that provides Objective-C “ToString”• NSObject.ToString() calls Description• Sometimes overwritten– You can always call NSObject.DescriptionReleased
  24. 24. Helping you write Threaded Apps• UIKit is not thread safe– No major commercial UI toolkit is thread safe– Thread safety is just too hard for toolkits• Very few UIKit methods are thread safe• During debug mode, you get an exceptionReleased
  25. 25. UIApplication.CheckForIllegalCrossThreadCalls• If set, accessing UI elements– Throws UIKitThreadAccessException• Most UIKit classes/methods• UIViewController implemented outside UIKit• Checks enabled on Debug, disabled on Release builds– Force use: --force-thread-check– Force removal: --disable-thread-checkReleased
  26. 26. Thread Safe APIsThread Safe Classes• UIColor• UIDocument• UIFont• UIImage• UIBezierPath• UIDeviceKey Thread Safe Methods• UIApplication.SharedApplication, Background APIs• UIView.DrawSee API docs for[ThreadSafe] attributeReleased
  27. 27. ASYNC
  28. 28. Async Support• Base Class Libraries:– Expect all the standard Async APIs from .NET BCL– Coverage is .NET 4.5 Complete for BCL• MonoTouch specific:• 114 methods on the beta• Easy to turn ObjC methods into Async ones– Details on the Objective-C bindings talkBeta
  29. 29. Async Synchronization Contexts• For UI thread, we run a UIKit Sync Context– What you get from the main thread– Code resumes execution on UIKit thread– Using async just works– Transparent• Grand Central Dispatch Sync Context– If you are running on a GCD DispatchQueue– Will resume/queue execution on the current queueBeta
  30. 30. General Async Pattern• Methods with the signature:void Operation (…, Callback onCompletion)• Become:Task OperationAsync (…)Beta
  31. 31. API IMPROVEMENTS
  32. 32. More Strong Type Constructors• Where you saw– NSDictionary options• We now support strongly typed overloads– Give preference to strongly typed overloads– Reduce errors– Trips to the documentation– Unintended effectsReleased
  33. 33. Screen Capture• To capture UIKit views:– UIScreen.Capture ()• To capture OpenGL content:– iPhoneOSGameView.Capture ()Released
  34. 34. UIGestureRecognizersBeforevoid Setup (){var pan= new UIPanGestureRecognizer (this, new Selector (”panHandler"));view.AddGestureRecognizer (pan);}[Export(”panHandler")]void PanImage (UIPanGestureRecognizer rec){// handle pan}Problems:• Error prone: Parameter of PanImage must be right type• No checking (mismatch in selector names)Nowvoid Setup (){var pan = new UIPanGestureRecognizer (PanImage);view.AddGestureRecognizer (pan);}void PanImage (UIPanGestureRecognizer rec){// handle pan}Pros:• Compiler enforced types• No selectors to deal withReleased
  35. 35. UIAppearance• Previously:var appearance = CustomSlider.Appearance;appearance.SetMaxTrackImage (maxImage, UIControlState.Normal);– Problem: does not work for subclasses• Now:var appearance = CustomSlider.GetAppearance<CustomSlider> ();appearance.SetMaxTrackImage (maxImage, UIControlState.Normal);Released
  36. 36. Notifications• Used in iOS/OSX to broadcast messages– Untyped registration– Notification payload is an untyped NSDictionary• Typically require a trip to the docs:– To find out which notifications exist– To find what keys exist in the dictionary payload– To find out the types of the values in dictionaryReleased
  37. 37. Xamarin.iOS Notifications• Discoverable, nested “Notifications class”• For example: UIKeyboard.Notifications• Pattern:– Static method ObserveXXX– Returns observer token– Calling Dispose() on observer unregisters interestReleased
  38. 38. Example – Full Code Completionnotification = UIKeyboard.Notifications.ObserveDidShow ((sender, args) => {// Access strongly typed argsConsole.WriteLine ("Notification: {0}", args.Notification);// RectangleF valuesConsole.WriteLine ("FrameBegin", args.FrameBegin);Console.WriteLine ("FrameEnd", args.FrameEnd);// doubleConsole.WriteLine ("AnimationDuration", args.AnimationDuration);// UIViewAnimationCurveConsole.WriteLine ("AnimationCurve", args.AnimationCurve);});// To stop listening:notification.Dispose ();Released
  39. 39. NSAttributedString• On iOS 5:– Introduced for use in CoreText• On iOS 6:– It became ubiquitous on UIKit– UIKit views use it everywhere• Cumbersome to createReleased
  40. 40. NSAttributedString• Standard Objective-C esque approach://// This example shows how to create an NSAttributedString for// use with UIKit using NSDictionaries//var dict = new NSMutableDictionary () {{ NSAttributedString.FontAttributeName,UIFont.FromName ("HoeflerText-Regular", 24.0f), },{ NSAttributedString.ForegroundColorAttributeName, UIColor.Black }};• Error prone:– Get right values for keys– Get right types for values– Requires documentation tripsReleased
  41. 41. NSAttributedString – C# 4 stylevar text = new NSAttributedString ("Hello, World",font: UIFont.FromName ("HoeflerText-Regular", 24.0f),foregroundColor: UIColor.Red);• Uses C# named parameters• Uses C# optional parameter processing• Use as many (or few) as you wantReleased
  42. 42. AudioToolbox, AudioUnit, CoreMidi• Completed MIDI support– Our CoreMIDI binding is OO, baked into system– Equivalent to what 3rd party APIs people use• AudioUnit– Now complete supported (since 6.2)– Full API coverage• AudioToolbox– Improved support for multiple audio channels– Strongly typed APIsReleased
  43. 43. CFNetwork-powered HttpClient• Use Apple’s CFNetwork for your HttpClient– Avoid StartWWAN (Url call)– Turns on Radio for you– Integrates with Async• Replace:var client = new HttpClient ()• With:var client = new HttpClient (new CFNetworkHandler ())Beta
  44. 44. New Dispose Semantics• Changes in NSObject() Dispose• If native code references object:– Managed object is kept functional– Actual shut down happens when native codereleases the reference.• Allows Dispose() of objects that might still beused by the system.Released
  45. 45. Razor Integration• Sometimes you want to generate HTML• Razor offers a full template system– Blend HTML and C#– Code completion in HTML• Easily pass parameters from C# to TemplateReleased
  46. 46. New File -> Text Template -> RazorReleased
  47. 47. Razor• Creating template, passing data:– Model property, typed in cshtml filevar template = new HtmlReport () { Model = data };• Run:class HtmlReport {string GenerateString ()void Generate (TextWriter writer)}Released
  48. 48. THANK YOU

×