Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Say hello to Cocoa development with Xamarin.Mac

ailen0ada
September 23, 2017

Say hello to Cocoa development with Xamarin.Mac

Session at MonkeyFest 2017 on Day 2 (23/09/2017), 16:00

ailen0ada

September 23, 2017
Tweet

More Decks by ailen0ada

Other Decks in Programming

Transcript

  1. Say hello to Cocoa development with Xamarin.Mac MonkeyFest 2017 -

    Day 2 Lifebear, Inc. Tsubasa HIRANO @ailen0ada
  2. AGENDA • Introduction to Xamarin.Mac • Demo: Creating Mac App

    using Xamarin.Mac • Showcase: Porting Windows.Forms app into Mac App • Wrap-up
  3. Xamarin.Mac • Full use of Mac APIs • JIT compiled

    to native code at run-time • side-by-side with the ObjC runtime • Mono runtime embedded into bundle • Allows the execution of dynamically generated code (in contrast to X.iOS) https://developer.xamarin.com/guides/mac/advanced_topics/mac-architecture/
  4. The first Mac App • A textfield and a button

    • Click to show alert with contents of textfield
  5. Cocoa Binding • Keeping model and view values synchronized without

    a lot of glue-code • NSObject could raise an alert such as INotifyPropertyChanged in XAML platforms • Only supported with Mac https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CocoaBindings/Concepts/WhatAreBindings.html
  6. Cocoa Binding Recipes 1.Remove glue-code from our first Mac App

    2.Bind to property in ViewController 3.Bind to properties in other class 4.Bind to multiple values to select one of them
  7. Cocoa binding basics NSString name;
 
 [Outlet]
 public NSString Name


    {
 get => name;
 
 set
 {
 this.WillChangeValue(nameof(Name));
 name = value;
 this.DidChangeValue(nameof(Name));
 }
 }

  8. DataSource Pattern • Providing data by implementing a data source

    class • Permits fine control of populating rows and columns • Implement the NSTableViewDataSource and the NSTableViewDelegate protocols
  9. Summary of live coding • Constructing Mac App using Visual

    Studio • Cocoa Binding basics • WillChangeValue/DidChangeValue • Protocol in C# • INSTableViewDataSource/Delegate
  10. Showcase: Gochiusearch A Fast Scene Search Engine for Anime Series

    'Is the order a rabbit?’ originally created with Windows.Forms ported to Cocoa with Xamarin.Mac published to MacAppStore • www.github.com/ksasao/Gochiusearch
  11. Windows Forms • One of cross platform GUI framework •

    thanks to WinForms in Mono • Is the best solution for enterprise apps with common controls?
  12. APPROACH 1.Wash away platform dependent codes 2.Construct user interface using

    XIB for supporting macOS 10.9 3.Implement features using Full Desktop Mono 4.Migrate core features to Xamarin.Mac Modern 5.Submit to AppStore
  13. Xamarin.Mac Modern • App runs on same tuned .NET framework

    used by X.iOS • Supporting a subset of the full Desktop framework • Linker behavior makes bundle size smaller • Could reference assemblies targeting netstandard>=1.0 or Xamarin.Mac20
  14. Migrating core features Input image StoryInfo Load DB Read Image

    Resize Image Calculate Bit Vector Search DB ImageSearch assembly System.IO.FileStream System.Drawing.Bitmap System.Drawing.Rectangle System.Drawing.Graphics Platform independent
  15. MIGRATING CORE FEATURE Input image StoryInfo Load DB Read Image

    Resize Image Calculate Bit Vector Search DB ImageSearch.Portable assembly PCLStorage Platform independent CoreGraphics ImageSearch platform impl Read Image
  16. APP SANDBOXING • Required for any app distributed from Mac

    App Store • Modify App Sandbox Resources by editing Entitlements.plist • Sandbox Violation does not throw NotAuthorizedException • Type of exception depends on operation • To determine whether violation occurred or not, use Console app
  17. Unleash the power of Xamarin.Mac • No simulator or tethered

    device needed • Cherry pick the best bits of .NET Framework and Cocoa • Consider whether sharing more code or writing convenient and/or efficient platform dependent code