draemonash2のメモ書き
brew update
brew upgrade
sudo gem install -n /usr/local/bin cocoapods -v 1.8.4
pod setup
Pods初期化
cd ~/Documents/codes/swift/app/hab-chain # move project directory
pod init
target 'app_name' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for hab-chain
+ pod 'SwiftyDropbox'
end
Pod インストール
pod install
pod update
Info.plistファイル編集(
<dict>
+ <key>LSApplicationQueriesSchemes</key>
+ <array>
+ <string>dbapi-8-emm</string>
+ <string>dbapi-2</string>
+ </array>
<key>CFBundleURLTypes</key>
<array>
<dict>
+ <key>CFBundleURLSchemes</key>
+ <array>
+ <string>db-<apps_key></string>
+ </array>
+ <key>CFBundleURLName</key>
+ <string></string>
</dict>
</array>
</dict>
</plist>
例外処理
do {
try メソッド呼び出し
} catch {
// エラー処理
}
?
!
)するif let ~
やguard iet ~
を使用する
if let ~
: アンラップできたときguard iet ~
: アンラップできなかったときvar body: somo View
のsomeは推論のための就職子。(viewプロトコルに関連したデータ型という意味)as
image as UIImage
as?
image as? UIImage
_
について
quantity
や price
等のラベルを指定して呼び出す。例1)ラベル名あり
//メソッド定義
func calcSum(quantity qt: Int, price pc: Int) -> Int {
return qt * pc
}
//メソッド呼び出し処理
calcSum(quantity: 2, price: 300)
例2)ラベル名なし
//メソッド定義
func debugMessage(_ message: String) {
print("\(message)")
}
//メソッド呼び出し処理
debugMessage("エラー")
例)
// リクエストURLからダウンロード
let (_ , response) = try await URLSession.shared.data(from: req_url)
// データ取得が完了したら、次のコードを実行
if (response as? HTTPURLResponse)?.statusCode == 200 {
print("2.データの取得できた")
}
isPhotolibrary = true
の後ろに isShowSheet = true
を追加するself.parent.captureImage = unwrapImage
の後ろに self.parent.isShowSheet = false
を追加するisShowAction = true
の追加は不要では?
XcodeSwift20211106/2_4/MyOkashi/src/MyOkashi/OkashiData.swift
日付処理+連想配列
func Test2() -> String
{
var dicStatus:Dictionary<Date, Int> = [:]
let today = Date()
let yesterday = Calendar.current.date(byAdding: .day,value: -1, to: Date())!
let yesterday_1 = Calendar.current.date(byAdding: .day,value: -2, to: Date())!
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = DateFormatter.dateFormat(fromTemplate: "yyyyMMdd", options: 0, locale: Locale(identifier: "ja_JP"))
dicStatus.updateValue(1, forKey: today)
dicStatus.updateValue(2, forKey: yesterday)
for (key,value) in dicStatus {
print("\(dateFormatter.string(from: key)) : \(value)")
}
print("\(dicStatus[today]!)")
print("\(dicStatus[yesterday]!)")
//print("\(dicStatus[yesterday_1]!)")
print("\(dicStatus.keys.contains(today))")
print("\(dicStatus.keys.contains(yesterday))")
print("\(dicStatus.keys.contains(yesterday_1))")
return "1"
}