Hi there!I meet the following code in IOS swift development class.
class UpdateToAttributedStringsPolicy: NSEntityMigrationPolicy {
override func createDestinationInstances(forSource sInstance: NSManagedObject, in mapping: NSEntityMapping, manager: NSMigrationManager) throws {
// Call super
try super.createDestinationInstances(forSource: sInstance, in: mapping, manager: manager)
// Get the (updated) destination Note instance we're modifying
guard let destination = manager.destinationInstances(forEntityMappingName: mapping.name, sourceInstances: [sInstance]).first else { return }
// Use the (original) source Note instance, and instantiate a new
// NSAttributedString using the original string
if let text = sInstance.value(forKey: "text") as? String {
destination.setValue(NSAttributedString(string: text), forKey: "attributedText")
}
}
}
このコード行で
override func createDestinationInstances(forSource sInstance: NSManagedObject, in mapping: NSEntityMapping, manager: NSMigrationManager) throws
sInstanceとmanagerは、関数createDestinationInstancesのパラメーター名ですが、
try super.createDestinationInstances(forSource: sInstance, in: mapping, manager: manager)
彼らは戻り名になりますが、これはどのように機能しますか?そして、なぜここでsuperを呼び出すのですか?それはsuper.initを意味しますか?
ありがとう!
回答 1 件
関連記事
- TypeScriptの関数の戻り値の型でパラメーターの値をプロパティ名として使用するにはどうすればよいですか?
- 関数からの戻り値をすばやく
- SwiftUIは、再利用可能なビューのパラメーターとしてSwiftコードを渡します
- Swiftでreturn関数としてカスタムタイプを使用するにはどうすればよいですか?
- パスパラメータをキャプチャして応答して返す動的ワイヤモック
- ノード測定の実行時間:パラメータとして別の関数に渡された非同期からの戻り値
- Swiftのfuncからvoidfuncを返す
- bパラメータでこの新しい構造へのポインタを返しますか?
- Swiftの関数パラメーターを使用してジェネリック関数へのこの呼び出しを明確にするにはどうすればよいですか?
関連した質問
- SwiftUIでアラートを作成する
- ネストされたforループ内のこのsqliteクエリが複数の結果を返さないのはなぜですか?
- Xcode 12(Swift 53)以降、ネストされたコレクションビューはセルの選択に応答しません
- 座標に向かう方向を見つける
- リアルタイムのテキスト認識のためにAppleのビジョンフレームワークを使用する方法を知っている人はいますか?
- SwiftUIlistRowBackgroundが機能していないようです
- RxSwift)1つの観測可能な2回のサブスクライブが機能しない
- TableView SwiftでネストされたJSON配列を解析する方法は?
- ファイルが「存在しない」ため、SwiftMoveItemが失敗する
- オブジェクト内のオブジェクトでCodableエンコードを使用する方法
私があなたを正しく理解していれば、あなたはどのように
sInstance
を使用できるかを尋ねています 単なるラベルであっても値として?ここで述べたように(関数宣言-> パラメーター名セクション)、
sInstance
実際にはラベルではなくパラメータ名です。これは正しいですが
これは間違っています: