この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。
GDPerformanceView-Swiftはステータスバーの上にFPS、CPU使用率、アプリのバージョン、OSのバージョンを簡単に表示することができます。下の画像はFPSとCPU使用率を表示した画面になります。
導入も数行コードを書くだけでOKで、ステータスバーの上なので邪魔になりません(時計は見れなくなりますが・・・)。ライセンスはMITです。
dani-gavrilov/GDPerformanceView-Swift
検証環境
今回は下記環境で試しています。
Xcode | 8.2.1 |
---|---|
Swift | 3.0.2 |
CocoaPods | 1.0.0 |
準備
導入
CocoaPodsで追加します。
use_frameworks!
target "ターゲット名"
pod 'GDPerformanceView-Swift'
end
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |configuration|
configuration.build_settings['SWIFT_VERSION'] = "3.0"
end
end
end
実装
GDPerformanceView_Swiftをインポートして、GDPerformanceMonitor.sharedInstance.startMonitoring()を呼び出せばOKです。
AppDelegate.swift
import UIKit
import GDPerformanceView_Swift
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
GDPerformanceMonitor.sharedInstance.startMonitoring()
return true
}
〜 後略 〜
デザインの変更
見た目の変更をするには、
GDPerformanceMonitor.sharedInstance.startMonitoring()
の部分を以下のように変更します。
GDPerformanceMonitor.sharedInstance.startMonitoring { (textLabel) in
// 背景色
textLabel?.backgroundColor = .white
// 文字色
textLabel?.textColor = .gray
// 線の色
textLabel?.layer.borderColor = UIColor.white.cgColor
// 角丸度
textLabel?.layer.cornerRadius = 0
}
textLabelの各種プロパティを変更することで見た目を変更することができます。
表示項目の変更
アプリのバージョンとOSのバージョンは任意で消すことができます。
アプリのバージョンを消す場合
アプリのバージョンを消す場合は下記コードを追加します。
GDPerformanceMonitor.sharedInstance.appVersionHidden = true
OSのバージョンを消す場合
OSのバージョンを消す場合は下記コードを追加します。
GDPerformanceMonitor.sharedInstance.deviceVersionHidden = true
表示を消したい場合
任意のタイミングで、
GDPerformanceMonitor.sharedInstance.stopMonitoring()
を呼び出せば消えました。
さいごに
導入も簡単で、デバッグ時に活躍しそうだと思いました。
下記のように#if DEBUG
#endif
で囲えばデバッグ時のみ表示されて良い感じだと思われます。
#if DEBUG
GDPerformanceMonitor.sharedInstance.startMonitoring()
#endif