2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

import AppKitでNo such module 'AppKit'とエラーが出る時の対処法

Last updated at Posted at 2018-12-06

はじめに

以下のようにimport AppKitをしてフレームワークであるAppKitを読み込もうとした際に、No such module 'AppKit'とエラーがでる原因と対処法について書いていきます。
error.png

動作確認環境

  • macOS Mojavaのバーション:10.14
  • Xcodeのバーション:10.1
  • Swiftのバーション:4.2.1

エラーの対処法

まず、一番左にあるナビゲーターエリアのSampleProductをクリックします。
reference01.png

そして、Build SettingsのBase SDKをiOSからMacOSに変更します。
(プロジェクトを特に指定せずに作成するとBase SDKの初期値はiOSになっています)

変更前
reference02.png

変更後
reference04.png

すると、以下のように補完の候補としてAppKitが出てくるようになります。
Completion.png

ちゃんと読み込まれているのがわかります。
 OK.png

AppKitとUIKitの違いについて

エラーが起きていた理由として、AppKitとUIKitを比較して説明していきます。

  • AppKitはMacOSアプリケーションのユーザーインターフェースを構築・管理するフレームワーク
  • UIKitはiOSまたは、tvOSアプリケーションのユーザーインターフェースを構築・管理するフレームワーク

よって、AppKitを使用する場合は、XcodeのSDKの設定をMacOSに合わせる必要があるといえます。

最後に

色々調べる中で、最初はドキュメントに目を通した方が回り道しないこともよくあります。
英語から逃げないようにしていきましょう!(自分への戒めも兼ねて)

参考サイト

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?