その後のその後

iOSエンジニア 堤 修一のブログ github.com/shu223

API Diffsから見るiOS 14の新機能 - 新フレームワーク編 #WWDC20 #iOS14

本日からはじまったWWDC 2020、まだ基調講演しか見てないのですが(SOTUも後で見ます)、ドキュメントは公開されたので、明日から始まるセッションでどのあたりをチェックするか当たりをつけるべく、例年通りAPIの差分を見て気になった新APIをピックアップしていきます。

f:id:shu223:20200623092201p:plain

まずは新フレームワークから。今年の新規追加フレームワーク1は21個。

ML Compute

ニューラルネットワークの学習とバリデーションを行うためのフレームワーク、とのこと。

Accelerate training and validation of neural networks using the CPU and GPUs.

macOS用かな?と思いきやiOSでも利用可

ML Compute utilizes the high performance BNNS primitives made available by the Accelerate framework for the CPU and Metal Performance Shaders for the GPU.

『ML Computeは、CPU用のAccelerateフレームワークとGPU用のMetal Performance Shadersによって利用可能になったハイパフォーマンスなBNNS primitivesを利用しています。』

とのことでこれらのラッパー的な位置づけっぽい。Core MLもBNNSとMPSをラップしており、iOS 13ではモデルの更新も可能になったが、あくまで学習済みモデルを更新するもの。こちらはレイヤークラス群も定義されてるので、PyTorchやTensorFlowみたいにネットワークを実装してiOSやmacOSのGPU/CPUを駆使して学習をまわせる、というものかと。

ちなみにMLCDeviceというクラスがあったのでもしやと思い見てみたが、Neural Engineを指定できるようにはなっていなかった。

https://developer.apple.com/documentation/mlcompute/mlcdevice?changes=latest_major

Metal Performance Shaders Graph

TensorFlowのように多次元テンソルのグラフを構築し、コンパイル、実行するフレームワークらしい。

Build, compile, and execute customized multidimensional compute graphs for linear algebra, machine learning, computer vision, and other similar domains.

f:id:shu223:20200623085100p:plain:w500

(画像は"Build customized ML models with the Metal Performance Shaders Graph"セッションのサムネ)

以前からあったMPSCNNとはどういう関係になるのか、またML Computeを使う場合はこのレイヤー(MPSフレームワーク)を気にする必要はないのか、それともここまで潜る必要があるのか、といったあたりをセッションでチェックする。

ちなみにサンプルコードもある。

Nearby Interaction

名前と一行説明からして、バックグラウンドでのすれ違い通信系(待望)かなと第一印象では思ったが、

Locate and interact with nearby devices using distance, direction, and identifier.

距離、方向、識別子を使用して、近くのデバイスの位置を特定し、対話することができます。(by DeepL)

リファレンスページみたら懐かしのBumpみたいなイラストが載っていて、

f:id:shu223:20200623085821p:plain:w500

なんだ?と思ってOverviewを読んでみると、

Use NearbyInteraction (NI) in your app to acquire the position of nearby iPhones with a U1 chip, such as iPhone 11 or later. To participate in an interaction, devices in physical proximity run an app and consent to share their position and device tokens that uniquely identify their device. When the app runs in the foreground, NI notifies the interaction session of the peer’s location by reporting the peer’s direction and distance in meters.

アプリでNearbyInteraction(NI)を使用して、iPhone 11以降などのU1チップを搭載した近くのiPhoneの位置を取得します。インタラクションに参加するには、物理的に近くにいるデバイスがアプリを起動し、位置情報とデバイスを一意に識別するデバイストークンを共有することに同意します。アプリがフォアグラウンドで実行されると、NIは、相手の方向と距離をメートル単位で報告することで、相手の位置をインタラクションセッションに通知します。

Devices that share their positions using the high frequency of the U1 chip enable a fluid, interactive session in which peer positioning within the physical environment becomes a primary driver of the user experience. For example:

U1チップの高周波数を使用して位置を共有するデバイスは、物理環境内でのピアの位置がユーザ体験の主要なドライバーとなる流動的なインタラクティブセッションを可能にします。例えば、以下のようなものです。(Translated by DeepL)

なんと、U1チップ使うやつだった!これはぜひ試したい。

ちなみにサンプルもある: "Implementing Interactions Between Users in Close Proximity"

SensorKit

ありそうでなかった、その名も「センサーキット」。

Retrieve data and derived metrics from an iPhone’s sensors, or from a paired Apple Watch.

これまで加速度センサーやジャイロetc.のセンサー類を扱う存在だったCore Motionはdeprecatedになるのかなと思ったがまだ現役だった。こちらのフレームワークではペアリングしてるApple Watchのセンサー値も取れるのが違いか。

扱えるセンサー一覧:

static let accelerometer: SRSensor
static let ambientLightSensor: SRSensor
static let gyroscope: SRSensor
static let onWristState: SRSensor
static let pedometerData: SRSensor
static let visits: SRSensor

App Clips

iOS 14の目玉新機能のひとつであるApp Clips、これは新しいUI/UXだけに何がどこまで実現できるのかを把握するためにも要チェック。

Create an app clip to make some of your app’s functionality available to users who don’t have the full app installed.

f:id:shu223:20200623091704p:plain:w450

WidgetKit

同じくiOS 14の目玉新機能のひとつであるウィジェット。これも専用フレームワークが新規で追加されたとなると当然要チェック。

Show relevant, glanceable content from your app on the iOS Home screen or macOS Notification Center.

f:id:shu223:20200623092105p:plain:w450

StoreKit Test

Create and automate tests in Xcode for your app’s subscription and in-app purchase transactions.(アプリのサブスクリプションとアプリ内購入トランザクションのためのテストをXcodeで作成し、自動化します。 by DeepL)

個人的にはここ最近はアプリ内課金の実装をする機会がないのだけど、これはかなり助かるやつでは...!

System

大層な名前に惹かれたが、中身を見てみたらちょっと期待したものと違った。

Perform low-level file operations using type-safe APIs.

Cの低レベルなファイル操作をSwiftでタイプセーフに書ける、というものらしい。

close ⟶ close()

lseek ⟶ seek(offset:from:)

open ⟶ open(_:_:options:permissions:)

pread ⟶ read(fromAbsoluteOffset:into:retryOnInterrupt:)

pwrite ⟶ write(toAbsoluteOffset:_:retryOnInterrupt:)

read ⟶ read(into:retryOnInterrupt:)

write ⟶ write(_:retryOnInterrupt:)

その他の新フレームワーク

(翻訳はby DeepL)

  • Accessibility
    • Make your apps accessible to everyone who uses Apple devices.(Appleデバイスを使用しているすべての人がアプリにアクセスできるようにしましょう。)
  • App Tracking Transparency
    • Request user authorization to access app-related data for tracking the user or the device.(ユーザーやデバイスを追跡するために、アプリ関連のデータにアクセスするためのユーザー権限を要求します。)
  • Apple Archive
    • Perform multithreaded lossless compression of directories, files, and data.(ディレクトリ、ファイル、データをマルチスレッドでロスレス圧縮します。)
  • Automatic Assessment Configuration
    • Prevent users from accessing specific system features during high-stakes assessment activities, such as administering an exam.(試験の実施など、高額な評価活動中にユーザーが特定のシステム機能にアクセスできないようにします。)
  • Developer Tools Support
    • Expose custom views and modifiers in the Xcode library.(Xcodeライブラリでカスタムビューとモディファイアを公開します。)
  • Exposure Notification
    • Implement a COVID-19 exposure notification system that protects user privacy.(利用者のプライバシーを保護するCOVID-19曝露通知システムを導入する。)
  • Kernel Management
    • Manage the loading and unloading of system extensions in the kernel.(カーネル内のシステム拡張のロードとアンロードを管理します。)
  • Media Setup
    • Enable configuration and account management of media services for use on HomePod.(HomePodで使用するメディアサービスの設定とアカウント管理を有効にします。)
  • Paravirtualized Graphics
    • Add limited graphics acceleration to your guest driver stack.(ゲストドライバスタックに限定されたグラフィックスアクセラレーションを追加します。)
  • Screen Time
    • Share and manage web-usage data and observe changes made by a parent or guardian.(ウェブ利用データを共有・管理し、保護者の変更点を観察することができます。)
  • Uniform Type Identifiers
    • Unified type information for files and data transfer.(ファイルやデータ転送のための統一された型情報。)
  • Wallet Passes
    • Create, distribute, and update passes for the Wallet app.(ウォレットアプリのパスを作成、配布、更新します。)
  • xcselect
    • A function that finds the path to a macOS SDK version on disk.(ディスク上の macOS SDK バージョンのパスを検索する関数です。)

まとめ

APIリファレンスの差分から見て気になる新APIをピックアップするシリーズ、新フレームワーク編でした。次は既存フレームワークの更新を見ていきます。

そしてそのあとは、サンプルやセッションを見てもっと具体的に実装方法や何ができて何ができないのかといったところを探っていきます。

昨年はそれらの知見を書籍にまとめましたが、今年はnoteの有料マガジンにまとめていきたいと思います。

note.com

まだ記事がないので今ならたったの500円です。サブスクではなく買い切り価格です。記事が充実してきたら価格改定していきたい所存です。


  1. https://developer.apple.com/documentation/technologies?changes=latest_majorのリストに載っている単位をここでは便宜的に「フレームワーク」と呼んでいますが、厳密にはフレームワークではないのも混じっています。