Slide 1

Slide 1 text

Say hello to Cocoa development with Xamarin.Mac MonkeyFest 2017 - Day 2 Lifebear, Inc. Tsubasa HIRANO @ailen0ada

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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/

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

Cocoa binding basics NSString name;
 
 [Outlet]
 public NSString Name
 {
 get => name;
 
 set
 {
 this.WillChangeValue(nameof(Name));
 name = value;
 this.DidChangeValue(nameof(Name));
 }
 }


Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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