[英]Is parameter name able to become return type in swift 4?
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呢?
謝謝!
如果我理解正確,那么您正在問如何將sInstance
用作值,即使它只是標簽?
如前所述這里 (函數聲明- >參數名稱部分),該sInstance
實際上是一個參數名稱,而不是標簽。
parameter_name: parameter_type
argument_label parameter_name: parameter_type
_ parameter_name: parameter_type
所以雖然這是正確的
try super.createDestinationInstances(forSource: sInstance, in: mapping, manager: manager)
這是錯誤的:
try super.createDestinationInstances(forSource: forSource, in: in, manager: manager)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.