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

    View Slide

  2. AGENDA
    • Introduction to Xamarin.Mac
    • Demo: Creating Mac App using Xamarin.Mac
    • Showcase: Porting Windows.Forms app into Mac App
    • Wrap-up

    View Slide

  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/

    View Slide

  4. The first Mac App
    • A textfield and a button
    • Click to show alert with contents of
    textfield

    View Slide

  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

    View Slide

  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

    View Slide

  7. Cocoa binding basics
    NSString name;


    [Outlet]

    public NSString Name

    {

    get => name;


    set

    {

    this.WillChangeValue(nameof(Name));

    name = value;

    this.DidChangeValue(nameof(Name));

    }

    }


    View Slide

  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

    View Slide

  9. DataSource Pattern Recipes
    1.Implementing ITableViewDataSource and ITableViewDelegate
    2.Recall previous value
    3.Sorting previous values with direction (time permits)

    View Slide

  10. Summary of live coding
    • Constructing Mac App using Visual Studio
    • Cocoa Binding basics
    • WillChangeValue/DidChangeValue
    • Protocol in C#
    • INSTableViewDataSource/Delegate

    View Slide

  11. 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

    View Slide

  12. Windows Forms
    • One of cross platform GUI framework
    • thanks to WinForms in Mono
    • Is the best solution for enterprise apps with common controls?

    View Slide

  13. 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

    View Slide

  14. 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

    View Slide

  15. 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

    View Slide

  16. 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

    View Slide

  17. 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

    View Slide

  18. 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

    View Slide

  19. THANKS
    • Twitter/Facebook/GitHub/Medium: ailen0ada (unreadable)
    • Today’s slide: https://speakerdeck.com/ailen0ada
    MonkeyFest 2017 was sponsored by

    View Slide