Xamarin.Mac Seminar

  • 16,582 views
Uploaded on

Learn to write native Mac apps using C# and .NET directly from Miguel de Icaza, cofounder and CTO of Xamarin.

Learn to write native Mac apps using C# and .NET directly from Miguel de Icaza, cofounder and CTO of Xamarin.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
16,582
On Slideshare
0
From Embeds
0
Number of Embeds
6

Actions

Shares
Downloads
47
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Xamarin.Mac  Introduc0on   Miguel  de  Icaza,  CTO  Xamarin   miguel@xamarin.com   January  10th  2013  
  • 2. Xamarin.Mac  Overview  •  Build  Mac  applica0ons  with  C#   –  Use  C#  and  .NET  libraries  on  Mac   –  All  that  you  love:     •  LINQ,  Task  Parallel  Library,  async   •  GC,  type  safety,  generics,  dynamic  and  more.   –  Mac  AppStore  ready  •  Na0ve  Applica0ons   –  Use  na0ve  APIs  to  deeply  integrate  with  OSX  
  • 3. Xamarin.Mac Overview 2.2B devices reachable with C#
  • 4. Xamarin.Mac  at  a  Glance   Xcode   MonoDevelop  IDE   (UI  Designer)   Xamaric.Mac   Cocoa  Frameworks   Tools  and  SDK   Libraries    •  Binder   Mono  Core  Class  •  Bundler   System  Libraries   Libraries  •  Linker  •  Packager     Mono  Run0me   Darwin  OS  
  • 5. Xamarin.Mac  Frameworks   Graphics   User  Interface  •  CoreGraphics   •  ImageKit   •  AppKit   •  QCComposer  •  CoreImage   •  ImageIO   •  CoreAnima0on   •  QuickLook  •  CoreText   •  OpenGL   •  CoreImage   •  SceneKit  •  CoreVideo   •  PDFKit   •  WebKit   Audio  and  Video   System  Services   •  AddressBook   •  CoreWLan  •  AVFounda0on   •  CoreMidi   •  Bluetooth   •  Scrip0ngBridge  •  AudioToolbox   •  CoreMedia   •  OpenAL   •  CoreLoca0on   •  StoreKit  •  AudioUnit   •  CoreServices   Infrastructure  •  CoreData   •  Founda0on  •  CoreFounda0on   ObjCRun0me   • •  Darwin   •  Security  
  • 6. Lots  shared  with  MonoTouch  (iOS)   Graphics   User  Interface  •  CoreGraphics   •  ImageKit   •  AppKit   •  QCComposer  •  CoreImage   •  ImageIO   •  CoreAnima0on   •  QuickLook  •  CoreText   •  OpenGL   •  CoreGraphics   •  SceneKit  •  CoreVideo   •  PDFKit   •  CoreImage   •  WebKit   Audio  and  Video   System  Services   •  AddressBook   •  CoreWLan  •  AVFounda0on   •  CoreMidi   •  Bluetooth   •  Scrip0ngBridge  •  AudioToolbox   •  CoreMedia   •  OpenAL   •  CoreLoca0on   •  StoreKit  •  AudioUnit   •  CoreServices   Infrastructure  •  CoreData   •  Founda0on  •  CoreFounda0on   ObjCRun0me   • •  Darwin   •  Security  
  • 7. How  does  Xamarin.Mac  work?  •  OSX  Libraries  Projected  to  C#   –  1:1  mapping  from  OSX  na0ve  APIs  to  C#  •  Objec0ve-­‐C  (80%  of  APIs)   –  Object  system  mapped   –  Supports  subclassing  and  overriding  •  C-­‐based  APIs  (20%  of  APIs)   –  Exposed  as  C#  classes/methods   –  No  support  for  subclassing  or  overriding  
  • 8. The  Basics   Graphics   User  Interface  •  CoreGraphics   •  ImageKit   •  AppKit   •  QCComposer  •  CoreImage   •  ImageIO   •  CoreAnima0on   •  QuickLook  •  CoreText   •  OpenGL   •  CoreImage   •  SceneKit  •  CoreVideo   •  PDFKit   •  WebKit   Audio  and  Video   System  Services   •  AddressBook   •  CoreWLan  •  AVFounda0on   •  CoreMidi   •  Bluetooth   •  Scrip0ngBridge  •  AudioToolbox   •  CoreMedia   •  OpenAL   •  CoreLoca0on   •  StoreKit  •  AudioUnit   •  CoreServices   Infrastructure  •  CoreData   •  Founda0on  •  CoreFounda0on   ObjCRun0me   • •  Darwin   •  Security  
  • 9. Anatomy  of  a  Xamarin.Mac  App   NSDocument  version     Applicaon  Delegate   Called  with  applica0on  events,  among  them     “FinishedLaunching”   Info.plist   Applica0on  metadata,  used  by  the  OS   (app  name,  requirements,  doc  type  handlers,  etc)   Main  applicaon  menu   Interface  defini0on  for  your  main  menu   Main  Window  UI  Definion   UI  for  your  Main  Window,  edited  with  Implementaon  for  your  main  window   Xcode.  Code  to  implement  the  features  of  your  Document  handler.  
  • 10. Results  
  • 11. Structure  of  your  App   NSWindow     The  toplevel  window  in  your  app     NSWindow.ContentView     An  NSViews,  hosts  all  content  
  • 12. NSViews  –  Powerful  containers  •  NSViews  can  contain  other  NSViews  •  NSViews  can  handle  events  •  NSViews  can  paint  themselves  •  NSViews  can  layout  their  nested  NSViews  •  NSViews  can  be  backed  by  a  CALayer   –  CALayers  are  GPU  accelerated  •  NSView  proper0es  can  be  animated  
  • 13. NSWindow  and  nested  NSViews  
  • 14. AppKit  -­‐  Applica0on  Framework  •  Pervasive  use  of  Model  View  Controller   –  Unless  you  are  wri0ng  a  custom  control   –  All  logic  goes  into  your  controller  class   –  Controller  orchestrates  work  of  views  •  Goes  beyond  the  standard  offering   –  High-­‐level  NSDocument  does  the  heavy  lijing   –  Full  Menu,  Saving,  Loading,  mul0-­‐window  support  
  • 15. Extending  our  first  Window   Subclass   Create  +  Ini0alize  Object   Hook  up  some  code,  lambda  
  • 16. My  app  in  Ac0on  
  • 17. Crea0ng  Beau0ful  Interfaces   •  Launch  Xcode  to  edit   XIB  files.   •  Ac0vate  side-­‐by-­‐side     view           •  Control-­‐drag  to  source   file.  
  • 18. Connec0ng  your  code  
  • 19. Exposing  the  UI  to  Code  •  Outlets   –  Allows  you  to  reference  an  object  from  code   –  Control-­‐drag  to  source  pane,  and  give  it  a  name  •  Ac0ons   –  Allows  a  method  to  be  invoked  as  a  response   –  Control  drag  to  source  pane,  and  give  a  name  •  In  C#  land   –  Ac0ons  become  par0al  methods  in  your  class   –  Outlets  become  proper0es  in  your  class  
  • 20. Implemen0ng  Ac0ons  and  using  Outlets  
  • 21. Running  
  • 22. Behind  the  Scenes  
  • 23. Events  and  Callbacks  •  In  the  C#  world  we  are  used  to  objects   broadcas0ng  events.      Like  this:   –  var  myControl  =  new  SomeControl  ();   –  myControl.Clicked  +=  SaveFile;   –  myControl.FocusIn  +=  MakeFontBold;   –  myControl.FocusOut  +=  ResetFont;     SaveFile   MyControl   MakeFontBold   ResetFont  
  • 24. Apple’s  Idiom  •  Objects  instead  send  interes0ng  events  to  a   “Delegate”.      All  messages  are  sent  there.     var  myControl  =  new  SomeControl  ()   myControl.Delegate  =  new  MyControlDelegate  ()   myControl   myControlDelegate     class  MyControlDelegate  :  ControlDelegate  {    override  Clicked  ()  {…}    override  FocusIn  ()  {…}    override  FocusOut  ()  {…}   }  
  • 25. Xamarin.Mac  and  Delegates  •  Both  models  are  supported   –  You  get  to  choose  in  a  per-­‐instance  basis  •  Apple  Delegate  panern  mapped  to  C#  events   –  Internally,  we  create  the  Delegate  class,  map  it  to   your  C#  lambda/anonymous  method/delegate  •  One  replaces  the  other  
  • 26. SHIPPING  YOUR  APP  
  • 27. Shipping  Your  App  -­‐  Yourself  •  App  has  full  access  to  the  system  •  Applica0ons  are  shipped  as  “bundles”   –  Directory  with  .app  extension   –  Self-­‐contained,  with  no  external  dependencies   –  Op0onally:  generate  installer  from  IDE  as  well.  •  MacOS  recently  enabled  GateKeeper   –  This  requires  you  to  sign  your  app   –  Or  apps  wont  start  on  modern  systems1  (by  default)   1.  Technically  any  Mac  running  Mountain  Lion  (10.8.xx)  or  Lion  10.7.5  and  newer  
  • 28. Shipping  your  App  -­‐  AppStore  •  Mac  App  Store   –  Must  apply  to  Apple  for  developer  program   –  Must  sign  applica0on   –  Submit  app  for  review  •  App  will  be  sandboxed  •  IDE  signs,  packages  and  launches  uploader  •  See  Xamarin’s  docs  for  tutorial  
  • 29. MacOS  X  Sandbox    •  Kernel  enforced  sandbox  •  Limits  access  to  the  system:   –  Limita0ons  on  file  system  access   –  Use  special  Open/Save  dialog  panels   –  Limits  access  to  services,  and  some  kernel  APIs    
  • 30. Mac  AppStore  –  Sandbox  Configura0on  Info.plist      Edi0ng  this  file  brings  up  the  metadata  editor.    Use  this  editor  to  configure  your  applica0on  requirements  from  the  sandbox.  
  • 31. Next StepsLearn more at: Deep Dive at Xamarin Evolve 2013-  xamarin.com/mac April 14 – 17, Austin, TX-  Docs.xamarin.com 2 Days of Xamarin Technical Training & CertificationFree trial:-  xamarin.com/trial 2 Conference days covering all things mobile Keynotes by Nat, Miguel and Scott Hanselman Call for speakers officially open & sponsorship information available at evolve@xamarin.com
  • 32. Pricing  •  Free  trial  at  xamarin.com/trial  •  Professional:  $399    •  Enterprise:  $999  per  seat  •  Enterprise  Priority:  $2,499  per  seat  
  • 33. Resources  •  Xamarin’s  Mac  Resources:   –  hnp://docs.xamarin.com/mac  •  API  documenta0on:   –  Installed  on  first  use  (Apple  +  Xamarin  Docs)  •  C#  samples:  hnps://github.com/xamarin/mac-­‐samples  •  Support  Forum:  hnp://forums.xamarin.com/categories/mac  •  Apple  Developer  Portal:  hnp://developer.apple.com/mac  •  Xamarin’s  Evolve  conference:  hnp://xamarin.com/evolve  
  • 34. MORE  INFORMATION  
  • 35. TouchDraw  and  iCircuit  •  TouchDraw    •  iCircuit  
  • 36. PROJECTIONS  
  • 37. Objec0ve-­‐C  Projec0on  to  C#  •  What  we  map:   –  Classes     –  Structures   –  Methods  and  Proper0es   –  Objec0ve-­‐C  blocks   –  Public  global  fields   –  No0fica0ons   –  Dic0onaries   –  Core  data  types  •  Follow  the  .NET  Framework  Design  Guidelines  
  • 38. Projec0ng  Classes  and  Structs  •  Iden0cal  class  names  •  Scoped  by  namespace      Example:    NSWindow  and  NSURL    Become    MonoMac.AppKit.NSWindow    MonoMac.Foundation.NSUrl  
  • 39. Projec0ng  Methods  and  Proper0es  •  We  rename  methods  to  follow  .NET  FDG  •  Use  C#  overloading  Example:  -­‐(void)  drawString:(NSString  *)  str  atPoint:(CGPoint)pos  -­‐(void)  drawString:(NSString  *)  str    Becomes:  void  DrawString  (string  str)  void  DrawString  (string  str,  PointF  position)    
  • 40. Projec0ng  Blocks  •  Blocks  are  Objec0ve-­‐C  lambdas  •  They  are  mapped  to  C#  delegates   –  Can  be  used  with  C#  lambdas  or  methods  Example:   (int)(^)(string  msg,  int  flag)  Becomes:    delegate  int  X  (string  msg,  int  flag)  
  • 41. Projec0ng  No0fica0ons  •  No0fica0ons  are  posted  as  strings  +  Dic0onary  •  We  map  those  to  strong  types  +  EventArgs  Regular  Style/Objecve-­‐C   Strongly  Typed  
  • 42. Projec0ng  NSDic0onary  Op0ons  •  Dic0onaries  are  used  to  pass  parameters  •  Loosely  typed,  hard  to  debug,  hard  to  find  •  We  provide  strongly  typed  classes  •  They  implicitly  convert  to  NSDic0onary   –  With  the  right  magic  keys   –  With  the  correct  types  for  parameters  
  • 43. AppKit  –  The  Heart  of  Mac  Apps