[swift4] warning: realm.add, substring

swift

swiftで書かれたソースを3 => 4にしたときにwarningが出ていたので解決策を確認しました。

realmに渡す引数が非推奨になっている

'add(_:update:)' is deprecated: Pass .error, .modified or .all rather than a boolean. .error is equivalent to false and .all is equivalent to true.

true, falseで渡していた引数がenumになるようです。

realm.add(hoge, update: true) => realm.add(hoge, update: .all)
false => .error , true => .all

Need to upgrade to depend on RealmSwift 3.17 rather than still 3.14 · Issue #128 · RxSwiftCommunity/RxRealm
Getting warnings for public func add<O: Object>(update: Bool = false, onError: ((O?, Error) -> Void)? = nil) -> AnyObserver Warning: 'add(_:upda...

stringのsubstringが非推奨になっている

substringで書いていたところの書き方が変わるようです。

`substring(from:)' is deprecated: Please use String slicing subscript with a 'partial range from' operator.

hoge.substring(from: hoge.index(hoge.startIndex, offsetBy: 1))
=> hoge[hoge.index(hoge.startIndex, offsetBy: 1)…])

文字列の位置を指すのにString.Indexとかあるんですね…

Swift Stringの切り出し、文字列操作について(Swift4のsubstring周りの挙動変更対応, Swift5対応バージョン, Swift5.3対応バージョン) - Qiita
2020-10-09 追記 自分でも書いてて忘れたのでメモします。 var text = "Hello, playground" let from = text.index(text.startIndex, offsetB...

コメント

タイトルとURLをコピーしました