Created
November 26, 2016 05:34
-
-
Save bright23/d292cc88ca5ef6f9e78bc6316ba22766 to your computer and use it in GitHub Desktop.
DeviceConst.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// AppConst.swift | |
// AdBlockSample | |
// | |
// Created by bright on 2016/11/26. | |
// Copyright © 2016年 bright. All rights reserved. | |
// | |
import Foundation | |
import UIKit | |
final class DeviceConst { | |
let osName = "iOS" | |
// NOTE: コストの高い変数(定数)は、lazy をつけてクラスの初期化コストを抑えた方が良さそう(遅延評価) | |
// 但し、このは場合は大した処理でもないのでほとんど変わらないと思いますが。。。 | |
lazy var osVersion = UIDevice.current.systemVersion | |
lazy var appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "" | |
lazy var appName = Bundle.main.infoDictionary?["CFBundleName"] as? String ?? "" | |
lazy var appId = Bundle.main.infoDictionary?["CFBundleIdentifier"] as? String ?? "" | |
// 定数といいつつvarじゃないかとツッコまれそうですが、lazy let は書けないので苦し紛れに。。。 | |
// NOTE: クラスインスタンスの作成を避けたい場合 | |
static let hoge = "bar" | |
// NOTE: どう書くかは好みだと思いますが、一行で書きづらいものや、 | |
// 自身の定数を組み合わせて返却するものとかは、計算型プロパティとか使うと良いんじゃないかなと個人的に思う。 | |
var spec: String { | |
return self.osName + self.osVersion + self.appVersion | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks http://qiita.com/sasaron397/items/60a365fd94adc97c827d