ඇතුළත් කිරීම ඒ Swift 5.1 හි Keyword එක ඇතුළත් කර ඇත. Swift 5.6 හි keyword ඉදිරිපත් කර ඇත.අද, මෙම keywords ක්රියාකාරිත්වයේ ප්රමාණයන් තුළ භාවිතා කළ හැකි අතර, වර්ගය සකස් කිරීමට පෙර, පහත පරිදි: some any protocol P {} struct S: P {} // 'any P' is an explicit existential type. let p: any P = S() // 'some P' is an opaque type. let p: some P = S() func f(_ p: any P) {} func f(_ p: some P) {} Swift 5 දී keyword can be used to explicitly denote an existential type. Starting from Swift 6, existential types are required to be explicitly spelled with the Keyword එක any any අනාවැකි ආකාරය ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල සදාකාලික වර්ගයක් ප්රොටෝලයට අනුකූල වන ඕනෑම වටිනාකමක් ගබඩා කළ හැකි අතර, වටිනාකමේ වර්ගය දෛනිකව වෙනස් විය හැකි අතර, සදාකාලික වර්ගයක් භාවිතා කරන කේතය සදාකාලික වර්ගයක් භාවිතා කරන කේතය දෛනිකව මතකය බෙදාහැරීම අවශ් ය වේ. Understanding the Some Keyword අතුරුදහන් ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල ප්රතිඵල: some protocol P {} struct S1 : P {} func f() -> some P { return S1() } The key takeaway here is that a function that produces a type සංකීර්ණ, සංකීර්ණ, සංකීර්ණ වර්ගයේ වටිනාකමක් ආපසු ලබා දෙයි ක්රියාකාරිය විවිධ අනුකූලතා වර්ග ආපසු ලබා දීමට උත්සාහ කරන්නේ නම්, එය පරිවර්තන වරදක් ඇති වනු ඇත, ආකර්ෂණීය සාමාන්ය ස්ථාපිතයා බොහෝ වර්ග විසින් සපුරාලිය නොහැකි නිසා. P P struct F1: P {} struct F2: P {} // error: Function declares an opaque return type, but the return // statements in its body do not have matching underlying types. func f(_ value: Bool) -> some P { if value { return F1() } else { return F2() } } Let’s consider the benefits that opaque types offer over protocol return types. Opaque result types can be used with PATs. The main limitation of using protocols is that protocols with associated types cannot be used as actual types. This means that the following code doesn’t compile: func collection() -> Collection { return ["1", "2", "3"] } As for opaque types, they are merely generic placeholders that can be used in such scenarios: // protocol Collection<Element> : Sequence func collection() -> some Collection { return ["1", "2", "3"] } Opaque result types have identity. Because opaque types guarantee that only one type will be returned, the compiler knows that a function must return the same type on several calls: func method() -> some Equatable { return "method" } let x = method() let y = method() print(x == y) // true Opaque result types compose with generic placeholders. Contrary to conventional protocol-typed values, opaque result types integrate effectively with standard generic placeholders. For instance: protocol P { var message: String { get } } struct M: P { var message: String } func makeM() -> some P { return M(message: "message") } func bar<T: P, U: P>(_ p1: T, _ p2: U) -> Bool { return p1.message == p2.message } let m1 = makeM() let m2 = makeM() print(bar(m1, m2)) However, it doesn’t work if make returns different types based on protocol . M() P protocol P { var message: String { get } } struct M: P { var message: String } struct T: P { var message: String } // error: function declares an opaque return type 'some P', but the return statements in its body do not have matching underlying types func makeM() -> some P { if .random() { return M(message: "M message") } else { return T(message: "T message") } } ඕනෑම Keyword තේරුම් ගැනීම ඊළඟ උදාහරණයක් ලෙස බලමු.අපිට මෙම ගිවිසුම සහ මෙම ගිවිසුමේ සැබෑ ක් රියාත්මක කිරීම් දෙකක්. Drawable protocol Drawable { func draw() } struct Line: Drawable { let x1: Int let y1: Int let x2: Int let y2: Int func draw() { print("Draw Line") } } struct Point: Drawable { let x: Int let y: Int func draw() { print("Point") } } අපිට තියෙන්නේ ද් රව් ය දෙකක්, සහ , accordingly. Let’s create a variable and store a මාතෘකාව : Line Point Drawable var p1: any Drawable = Line(x1: 0, y1: 0, x2: 5, y2: 5) // 'any Drawable' is an explicit existential type p1.draw() // print "Draw Line" p1 = Point(x: 0, y: 0) p1.draw() // print "Point" අපි runtime තුළ විවිධ යෙදුම් අතර මාරු කළ හැක.අපි තවත් උදාහරණයක් සලකා බලමු: let array: [any Drawable] = [ Line(x1: 0, y1: 0, x2: 5, y2: 5), Line(x1: 0, y1: 0, x2: 5, y2: 5), Point(x: 0, y: 0) ] අපි දන්නා පරිදි, ස්ථාවර කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාලීන කාල print(MemoryLayout<Line>.size) // 32 print(MemoryLayout<Point>.size) // 16 එය කළ හැකි නිසා මෙම යථාර්තය යථාර්තය යථාර්තය යථාර්තය යථාර්තය යථාර්තය යථාර්තය යථාර්තය යථාර්තය යථාර්තය යථාර්තය යථාර්තය යථාර්තය යථාර්තය යථාර්තය යථාර්තය යථාර්තය යථාර්තය යථාර්තය යථාර්තය යථාර්තය යථාර්තය යථාර්තය යථාර්තය යථාර්තය යථාර්තය යථාර්තය යථාර්තය යථාර්තය යථාර්තය යථාර්තය යථාර්තය යථාර්තය යථාර්තය යථාර්තය යථාර්තය යථාර්තය යථාර්තය යථාර්තය යථාර් any The existential container takes 5 machine words (in a x64-bit system, 5 * 8 = 40): Value buffer is a space for the instance VWT is a pointer to Value Witness Table PWT is a pointer to the Protocol Witness Table ප්රොටෝලට් අගය කේතය තුළ භාවිතා කරන විට, පරිවර්තනයකයා අපි සදාකාලික අංගයක් ලෙස හැඳින්වෙන පෙට්ටියක් නිර්මාණය කරයි. එක් අගය සඳහා එක් පෙට්ටියක්. ඔවුන් ප්රොටෝලට් වර්ගයට අනුකූල වන ඕනෑම අගය ගබඩා කළ හැකි අතර, සදාකාලික අගය වර්ගය සදාකාලිකව වෙනස් විය හැක, සදාකාලික අංකය 3 යන්ත්ර වචන වල බෆර් එකට ගැලපීමට ප්රමාණවත් නොවේ නම්, සදාකාලික අංගය සංසන්දනය කිරීම අවශ්ය වේ. ගබඩාව බෙදාහැරීම සහ ප්රවේශ ගණනය කිරීම අමතරව, සෑම විටම සදාකාලික container භාවිතය සලකා බැලිය යුතුය සලකා බැලිය යුතුය සලකා බැලිය යුතුය සලකා බැලිය යුතුය.In addition to heap allocation and reference counting, every use of an existential container involves pointer indirection and dynamic dispatch, which cannot be optimized. 3 යන්ත්ර වචනයකට ගැලපෙන විට අගය ඇතුළත් කිරීම සඳහා වචන තුනක් භාවිතා කරනු ලැබේ, හෝ අගය 3 යන්ත්ර වචනයකට වඩා වැඩි නම්, ARC කළමනාකරණය කර ඇති පෙට්ටියක් නිර්මාණය කරනු ලැබේ. එවිට අගය පෙට්ටියට පිටපත් කරනු ලැබේ, එවිට ARC කළමනාකරණය කර ඇති පෙට්ටියට දර්ශකයක් පෙට්ටියේ පළමු වචනයට පිටපත් කරනු ලැබේ. ඉතිරි වචන දෙකක් භාවිතා නො වේ. Protocol Witness Table යනු සෑම ප්රොටොක්ටොක්ටොක් එකකටම තත්විකව සකස් කරන ලදී.If the type of a value, let’s say, is something like any other type. , there will be two entries, one for each protocol. As long as we have the Protocol Witness Table (PWT) that describes the type’s adherence to the protocol, we can create an existential container, pass it around, and use it for dynamic dispatch. P & Q So, we have an existential container, and we have a protocol witness table. However, we don’t know where this value should be stored in the existential container — whether it’s stored directly in the container or if we only have a reference to the value in the heap. To answer these questions, we turn to an auxiliary table called the Value Witness Table (VWT). This table contains function pointers for , , , . Every type has such a table, and it takes on the responsibility of creating an instance of the type, deciding where the value should be stored — in the stack or in the heap, etc. allocate copy destruct deallocate දැන්, අපට ස්ථාවර ප්රමාණ ප්රමාණ ප්රමාණ ප්රමාණ ප්රශ්නය විසඳා, හා මෙම ප්රමාණ ප්රවාහන ක්රමයක් ඇත. හොඳයි, අවම වශයෙන්, අපි ප්රොටෝලයේ සඳහන් කරන පරිදි ප්රොටෝලයේ තබා ඇති වටිනාකම සඳහා අවශ්ය සාමාජිකයන් මත ප්රවේශ කිරීමට හැකි වනු ඇත (initializers, properties — whether stored or computed, functions, and subscripts). කෙසේ වෙතත්, සෑම ගැලපෙන වර්ගයකටම මෙම සාමාජිකයන් වෙනස් ආකාරයකින් ක්රියාත්මක කළ හැකිය. උදාහරණයක් ලෙස, සමහර අය එය සෘජුවම සකස් කිරීමෙන් ක්රමයක් අවශ්යතාවය සපුරාලිය හැකි අතර, වෙනත් අය, උදාහරණයක් වශයෙන්, පන්තියකට අනුව, ක්රමයක් සුපර් පන්තියෙන් උරුම කර ගැනීමෙන් එය සපුරාලිය හැකිය. Handling all this diversity is the primary purpose of the Protocol Witness Table (PWT). There is precisely one such table for each protocol conformance. It contains a set of function pointers that point to the implementation of the protocol’s requirements. මෙම කාර්යයන් විවිධ ස්ථානවල පිහිටා ගත හැක, නමුත් PWT ස්ථානය එය අනුකූල වන ප්රොටොක්ටෝලයට පමණක් වන අතර, මෙම ප්රතිඵලයක් ලෙස, Caller container PWT පරීක්ෂා කළ හැකි, ප්රොටොක්ටෝලයේ ක්රියාකාරීත්වය ස්ථාපනය කිරීමට එය භාවිතා කළ හැකි, හා ඔවුන් ආරාධනා කළ හැකිය. පරිගණක සහ ක්රියාකාරී කාලය පෙර තීරණය කළ නොහැක, කොපමණ ප්රමාණවත් මතකය සකස් කළ යුතු වනු ඇත සැබැවින්ම පරිගණක හා ක්රියාකාරී ඉටු කරනු ලබන සැබැවින්ම ඔක්කොම ප්රමාණවත් බව දැන ගැනීම වැදගත් වේ. පරිගණක සහ ක්රියාකාරී කාලය පෙර තීරණය කළ නොහැක, කොපමණ ප්රමාණවත් මතකය සකස් කළ යුතු වනු ඇත සැබැවින්ම පරිගණක හා ක්රියාකාරී ඉටු කරනු ලබන සැබැවින්ම ඔක්කොම ප්රමාණවත් බව දැන ගැනීම වැදගත් වේ. සමුදාය අපි සලකා බැලුවා අතර වෙනස and එක පැත්තකින්, එය අපගේ පොදු කේතයේ සංකේතය සහ කියවීමේ හැකියාව පුළුල් කර ඇති අතර, අනෙක් අතට, එය අපගේ පොදු කේතය වඩාත් ඵලදායීව නිර්මාණය කිරීමට නව මාර්ග හඳුන්වා දුන්නේය. some any කියවන්න ස්තුතියි