escaping closure captures mutating 'self' parameter. firestore () init () { let user =. escaping closure captures mutating 'self' parameter

 
firestore () init () { let user =escaping closure captures mutating 'self' parameter  Swift, actor: Actor-isolated property 'scanning' can not be mutated from a non-isolated context

MyView {value in MyContent() } How do I declare the view to have that?👉 StackOverflow: What's 'Escaping closure captures mutating 'self' parameter' and how to fix itところが、イニシャライザで実装しているようにStateの変更をトリガーにUITextViewのプロパティを変更したいと思っても、Escaping closure captures mutating 'self' parameterというエラーが出てコンパイルできません。The introducing of @escaping or @nonEscaping for optional closures should be easily accepted. com's AI search assistant which allows users to find summarized answers to questions without needing to browse multiple websites. As Joakim alluded to, anonymous arguments are the $0, $1, arguments that are just based on the order of the parameters. 1 (20G224) Additional Detail from JIRA Votes 0 Component/s Compiler Labels Bug Assigne. It registers a sink and saves the cancellable inside the view which makes the subscriber live as long as the view itself does. bytes) } } } } In the ReaderInformations. md","path":"proposals/0001-keywords-as-argument. postStore. import Combine class GameViewModel: ObservableObject { @Published var game : Game @Published var user : User? init (game: Game) { self. md","path":"proposals/0001-keywords-as-argument. Swift. DispatchQueue. func loadData(){ LoadXZYAPI() { [weak self] (data:Any?) in guard let strongSelf = self else { return } strongSelf. In Swift 1. Mutating regular member var get error: "Cannot assign to property: 'self' is immutable" "Cannot use mutating member on immutable value: 'self' is immutable" struct porque: View { @State private var flag = false private var anotherFlag = false mutating func changeMe(_ value: Bool) { self. Supporting the new behavior requires changes to AST lookup, which I'm not sure we can make conditional on whether or not the. There are several other possible errors related to closure captures being able to effectively make structs into reference types (thereby destroying any guarentees that come from being a value-type)Closure cannot implicitly capture a mutating self parameter. e aqui está uma foto do arquivo. bar }}} var foo = Foo (bar: true) let closure = foo. It is written in my Model. md","path":"proposals/0001-keywords-as-argument. The short version. Apple Developer Forums admins can mark replies as Apple Recommended to indicate an approved solution{"payload":{"allShortcutsEnabled":false,"fileTree":{"proposals":{"items":[{"name":"0001-keywords-as-argument-labels. dev. 5 seco. Escaping closures are closures that have the possibility of executing after a function returns. 1 Answer. import Foundation public struct Trigger { public var value = false public mutating func toggle () { value = true let responseDate = Date (). 34. [self] in is implicit, for. md","path":"proposals/0001-keywords-as-argument. . An escaping closure can cause a strong reference cycle if you use self inside the closure. onReceive(_:perform) which can be called on any view. Stack Overflow. When you declare a function that takes a closure as one of its parameters, you can write @escaping before the parameter’s type to indicate that the closure is allowed to escape. Masalah: Saya mendapatkan Escaping closure captures mutating 'self' parameterkesalahan seperti yang ditunjukkan pada kode. I know there are a lot of questions out there that have been answered on how to use @escaping functions in general. class , capture-list , closure , escapingclosure , struct. . md","path":"proposals/0001-keywords-as-argument. option 1 & 2 produce a compile error: "Escaping closure captures mutating 'self' parameter", this is an architectural issue, do not mutate a view state during view render cycle, rather change the view's data model outside of the render cycle and let the re-render of the view reflect that change, that is why - options 3 & 4 are preferred either. The purpose of this would be to have a convenient way to create a Binding in DetailView that was called from a NavigationLink of a List. Learn more about TeamsIn Swift 1. timers. This has been asked and answered before. import Combine class GameViewModel: ObservableObject { @Published var game : Game @Published var user : User? init (game: Game) { self. test = 20 } } }Escaping closure captures mutating 'self' parameter (I really need help!) Dec '21. My question is do I need to use [unowned self] when the. This is what separates a closure (which "closes over" the scope where it was created) and an anonymous function (which does not). e. With RevenueCat Paywalls you can customize native, remotely configurable paywall templates and optimize them with Experiments. Using Swift. October 14, 2021. All i had to do was change the struct declaration to a class declarationSwift 5 : What's 'Escaping closure captures mutating 'self' parameter' and how to fix it (3 answers) Closed 3 years ago . 5 seco. 1 (13A1030d), MacOS 11. id }) { return Binding ( get. I am trying to write closure inside mutating function in struct and changing one property of struct from inside closure. Contentview. The escaping closure is the Button's action parameter, and the mutating function is your startTimer function. We should disallow implicit capture of `inout` parameters; except in `@noescape` closures. latitude and wilderness. {"payload":{"allShortcutsEnabled":false,"fileTree":{"proposals":{"items":[{"name":"0001-keywords-as-argument-labels. The line that begins with let request = throws the following error: Escaping closure captures mutating 'self' parameter. Q&A for work. The value. If n were copied into the closure, this couldn't work. One way that a closure can escape is. There are additional methods that allow you to make requests using Parameters dictionaries and ParameterEncoding. Does anyone know how I can make something like this work? swiftui; Share. _invitationsList = State< [Appointment]?>. If you are making an asynchronous network request you do want the closure to retain self for when the request finishes. onResponse!(characteristic. , if they have closures, follow the default. Escaping and Non-Escaping in Swift 3. dataTask (with. For a small application that I want to implement I’d like to stick with MVVM. main. The setup is fairly easy. Non-Escaping Closures. md","path":"proposals/0001-keywords-as-argument. Based on this and the empty set your descriptiveDate and descriptiveInt don't need to be Binding just a get for a String The line that begins with let request = throws the following error: Escaping closure captures mutating 'self' parameter. e. id > $1. See for a nice article explaining @escaping closures this link. Learn more about TeamsI have a program that has two main classes, Team and Player. In your case you are modifying the value of self. When creating a closure in mutating function of a struct capturing self is not possible: struct Foo { var bar: Bool mutating func createClosure() -> () -> Bool {. Escaping closure captures mutating 'self' parameter. – vrwim. Escaping closure captures 'inout' parameter. firstName = firstName. 当函数结束时,传递的闭包离开函数作用域,并且没有其他的引用指向该闭包。. 1. This is not allowed. 1 Why is Swift @escaping closure not working? 3. game = game } func fetchUser (uid: String) { User. 函数返回. Unfortunately, without seeing the closure, I cannot tell you why the closure is escaping. This is one of the crucial differences between member func declarations and closure declarations: self has different meaning in those. 3. e. A closure is said to escape a function when the closure is passed as an argument to the function, but is called after the function returns. I'm not sure how to approach this problem. 101. Protocol '. Stack Overflow | The World’s Largest Online Community for DevelopersStack Overflow | The World’s Largest Online Community for Developers{"payload":{"allShortcutsEnabled":false,"fileTree":{"proposals":{"items":[{"name":"0001-keywords-as-argument-labels. description } var descriptiveInt :. @virwim i understand mutating but wouldn’t I want non-escapingSwiftUI Escaping closure captures mutating 'self' parameter. anotherFunction(parameter: self. But it always gives me the error: Closure cannot implicitly capture a mutating self parameter. schedule (after: . Or search Stack Overflow for "closure cannot implicitly capture a mutating self parameter" (search with quotes around the message). Jan 6, 2020 at 11:39. I'm having a hard time constructing an example for such a retain cycle on the top of my head, what am I. numberToDisplay += 1 // you can't mutate a struct without mutating function self. readFirebase () }) { Text ("Click. Load 7 more related questions Show fewer related questions Sorted by: Reset to. bool1 = true which is changing the value of self. Basically, it's about memory management (explicit/escaping vs. Your solution throws 3 errors 1. Swift, actor: Actor-isolated property 'scanning' can not be mutated from a non-isolated context. Difficulty trying to use a struct to replace a cluster of stored properties in a class. 0 Swift for loop is creating new objects. funkybro funkybro. md","path":"proposals/0001-keywords-as-argument. Nested function cannot capture inout parameter and escape So it really just looks like a corner case that hasn’t been optimised yet. Swift-evolution thread: [only allow capture of inout parameters in. Oct 16, 2019. This proposal does not yet specify how to control the calling convention of the self parameter for methods. I'm trying to create an extension for Int, that increments its value progressively through time. Apr 9, 2021 at 18:16 @Dante make your closure @escaping and your function mutating, and look up what those do. There is only one copy of the Counter instance and that’s. Tuple, Any, Closure are non-nominal types. 上面代码会报错:“Escaping closure captures mutating 'self' parameter” 逃逸闭包不可修改 的self这个参数。 当self是结构体或枚举实例时,逃逸闭包不能捕获此self。 如果self是一个类的实例,则逃逸闭包能捕获self。 如果只是普通闭包则能捕获所有类型的self。 项目中使用. swift class GetLocations :ObservableObject { @Published var arrLocations = NSArray () func getLocNames (Action:String, Id: String, completion: @escaping (NSArray) -> Void) { //fetch data from server let session = URLSession. In your example getRequest has @escaping closure completionHandler and struct foo tries to modify itself inside this closure implementation. Following code produces Escaping closure captures mutating 'self' parameter error: struct Foo { @State var count = 0 init { Timer. I don't think it has anything to do with the @State property, but with the fact that you are using an @escaping closure. var body: some View { Text ("Some view here") . { // assign function directly instead of via capturing closure viewModel = TimerViewModel(totalTime: 15, finished: timerCallback) } var body: some View { Text("Demo") } private func. Instead you have to capture the parameter by copying it, by. import Foundation public struct Trigger { public var value = false public. That way the SwiftUI runtime will manage the subscription for you, even while your view may be recreated many times. CryptoStack Overflow | The World’s Largest Online Community for DevelopersPrevious ID SR-9743 Radar rdar://problem/56835205 Original Reporter CTMacUser (JIRA User) Type Bug Status Resolved Resolution Cannot Reproduce Attachment: Download Environment macOS Mojave 10. MyView { MyContent() } but what I want is to pass a parameter in the closure, like. sorted (by: { $0. onShow = { self. If you’ve opted in to email or web notifications, you’ll be notified when there’s activity. That object may have otherwise been deallocated. However, I want the view to get hidden automatically after 0. ~~A better way (IMO) would be to create a mutating func to do your firebase call and update the values inside mutating function. I would suggest you to use class instead of struct. I have an escaping closure to login user; init() { userService. Escaping closure captures mutating 'self' parameter, Firebase. md","path":"proposals/0001-keywords-as-argument. Additionally, my issue has to do with the fact that it is not recognizing. global(). addValue ("Basic. Value types that are referenced by escaping closures will have to be moved to the heap. md","path":"proposals/0001-keywords-as-argument. – Ozgur Vatansever Aug 14 at 15:55 Escaping Closures. See c&hellip; I'm refactoring my app to use protocol and value type as much as possible, so I did a lot of experiments to understand how to use them properly. How to fix "error: escaping closure captures mutating 'self' parameter. By non-escaping parameter, it means that the parameter cannot exist outside the scope of the function. In the main content view of my app, I display a list of these homeTeam. Stack Overflow | The World’s Largest Online Community for DevelopersA closure is said to escape a function when the closure is passed as an argument to the function, but is called after the function returns. When you declare a function that takes a closure as one of its parameters, you can write @escaping before the parameter’s type to indicate that the closure is allowed to escape. login { (didError, msg) in } }. Q&A for work. swift. So, you're assigning and empty [Customer] array to @State var customerList. If we are sending some self value into it, that will risk the closure behave differently upon its execution. Dan saya menduga parameter escaping closureis the func startTimerdan yang menyinggung 'self' parameteradalah countDownTime, tetapi saya tidak begitu yakin apa yang terjadi atau mengapa itu salah. But I can't figure out how to properly invoke withoutActuallyEscaping(_: do:). md","path":"proposals/0001-keywords-as-argument. Teams. When the closure is of escaping type, i. A closure is said to escape a function when the closure is passed as an argument to the function, but is called after the function returns. And it's also the only option Swift allows. However, I got the error, Escaping closure captures mutating 'self' parameter, and I understand now that I can't mutate the struct from the asynchronous timer. Prior to Swift 3 (specifically the build that ships with Xcode 8 beta 6), they would default to being escaping – you would have to mark them @noescape in order to prevent them from being stored or captured, which guarantees they won't outlive the duration of the. 将闭包传递给函数. Special property wrappers like @State let you mutate values later on, but you're attempting to set the actual value on the struct by using _activity = State(. Heap and stack should all be completely abstracted for the swift programmer. If this were allowed, then there is the possibility that self may not exist by the time the closure executes. 0, repeats: true) { _ in count += 1} } } But moving timer creation to a function eliminates the error:{"payload":{"allShortcutsEnabled":false,"fileTree":{"proposals":{"items":[{"name":"0001-keywords-as-argument-labels. id }) { return Binding ( get. The simple solution is to update your owning type to a reference once (class). Look at the below code:But now I'm getting a "Escaping closure captures mutating 'self' parameter" – Dante. create () and @escaping notification closure work on different threads. it just capture the copied value, but before the function returns it is not called. Stack Overflow | The World’s Largest Online Community for Developers{"payload":{"allShortcutsEnabled":false,"fileTree":{"proposals":{"items":[{"name":"0001-keywords-as-argument-labels. The compiler knows that you are changing the structure by mutating dataAPI parameter. This is where capture lists come in, which enable us to customize how a given closure captures any of the objects or values that it refers to. answered Dec 22, 2015 at 15:23. When you enter your function, the cani value is duplicated, when you exit the function, the duplicated value, potentially modified, is written back. . toggle). Since the @escaping closure could be called later, that means writing to the position on the. bar }}} var foo = Foo (bar: true) let closure = foo. To make the code clear, testable and just to test how far I can get without logic in ViewModels, I've moved the mutating logic to the Model layer. Learn more about TeamsSwift 5 : What's 'Escaping closure captures mutating 'self' parameter' and how to fix it. {"payload":{"allShortcutsEnabled":false,"fileTree":{"proposals":{"items":[{"name":"0001-keywords-as-argument-labels. I'm trying to subscribe to an observable generated by a combineLatest, after flatMap. md","path":"proposals/0001-keywords-as-argument. Many thanks Error: Escaping closure captures mutating 'self' parameter import Combine import Foundation // Model protocol Fetchable { associatedtype T: Decodable var foo: [T] { get set } } extension Fetchable { internal mutating func fetch( from url: URL ) { let _: AnyCa. Teams. Is there a way to say update the . Stack Overflow | The World’s Largest Online Community for Developers749. When you declare a function that takes a closure as one of its parameters, you can write @escaping before the parameter’s type to indicate that the closure is allowed to escape. Capture self, though… mutating func anotherMethod() { someMethod { [self] in self } }. Escaping closure captures mutating 'self' parameter (SWIFT 5) [duplicate] Ask Question Asked 3 years ago. 2. {"payload":{"allShortcutsEnabled":false,"fileTree":{"proposals":{"items":[{"name":"0001-keywords-as-argument-labels. I'm using ReSwift to fabricate a video player app and I'm trying to get my SwiftUI view to update the AVPlayer URL based on a ReSwift action…An inout argument isn't a reference to a value type – it's simply a shadow copy of that value type, that is written back to the caller's value when the function returns. The simple solution is to update your owning type to a reference once (class). In Swift 3, it’s the other way around: closure parameters are non-escaping by default. longitude of the struct without having to use the wilderness part explicitly? Capturing an inout parameter, including self in a mutating method. As the error said, in the escaping closure, you're capturing and mutating self (actually self. Contribute to apple/swift development by creating an account on GitHub. Escaping closure captures mutating 'self' parameter. md","path":"proposals/0001-keywords-as-argument. You can set initial values inside init, but then they aren't mutable later. If you knew your closure wouldn’t escape the function body, you could mark the parameter with the @noescape attribute. I use this boolean to show a view on a certain state of the view. center, spacing: 20, content: {Text("d")}) this is a instance of struct VStack, and when creating an instance of it, the third parameter takes closure as a parameter. The annotations @noescape and @autoclosure (escaping) are deprecated. Locations. readFirebase () }) { Text ("Click. longitude are the lines I’m focusing on. Try below and let me know if it works: public struct ExampleStruct { let connectQueue = DispatchQueue (label: "connectQueue", attributes: . Learn more here. A closure is said to escape a function when the closure is passed as an argument to the function but is called after the function returns. I am having troubles with running view methods on published property value change. {"payload":{"allShortcutsEnabled":false,"fileTree":{"proposals":{"items":[{"name":"0001-keywords-as-argument-labels. If you intend for it to escape the. I understand that the line items. invitationService. Locations. SPONSORED Build, deploy, and test paywalls to find what helps your app convert the most subscribers. This is not allowed. (Do you have some other reason for wanting to store the timer. paul@hackingwithswift. async { self. The short version. longitude of the struct without having to use the wilderness part explicitly?Capturing an inout parameter, including self in a mutating method. We simply call the _overlaps property's closure property, supplying the other AnyRange instance and a copy of this instance. ⛔. Here. Connect and share knowledge within a single location that is structured and easy to search. Button(action: {self. md","path":"proposals/0001-keywords-as-argument. Use @escaping to indicate that a closure parameter may escape. Escaping closure captures mutating 'self' parameter Error. Swift ui Escaping closure captures mutating 'self' parameter. struct ContentView: View { @State var buttonText = "Initial Button Label" var body: some View { VStack { Text (buttonText) Button (action: { self. I have a StateWrapper struct that conforms to DynamicProperty, allowing it to hold state that a SwiftUI view can access and react to. Q&A for work. import SwiftUI import Combine class HomeViewModel: ObservableObject, Identifiable { @Published var companyName: String = "" private var db = Firestore. it just capture the copied value, but before the function returns it is not called. just as when using. toggle). Compiler gives "closure cannot implicitly capture a mutating self parameter". But to be sure that self exists at the moment when completionHandleris called compiler needs to copy self. And the result of the closure is indirectly used by transform, so it doesn't actually escape. Viewed 5k times. It is why your code is getting the error messgage:" Escaping closure captures mutating 'self' parameter". 0. Escaping closure captures mutating 'self' parameter (SWIFT 5) [duplicate] Ask Question Asked 3 years ago. ' can only be used as a generic constraint because it has Self or associated type⛔️ escaping closure captures mutating 'self' parameter. GameStop Moderna Pfizer Johnson & Johnson AstraZeneca Walgreens Best Buy Novavax SpaceX Tesla. concurrent)//This creates a concurrent Queue var test = 10 mutating func example () { connectQueue. Binding is by definition a two-way connection. The short version. But async tasks in the model are giving me a headache. The reference to self within the closure probably switches to the new mutated instance of the struct when you modify it. global(). – Berik. In this recent thread: An odd error: "Escaping closure captures mutating 'self'" - #10 by Jens, I, (well, actually @Jens), just found out that this code compiles: func test(_ callback: -> Void) { // Compiles, no need for it to be @escaping let x = callback x() } It baffles me because I don't think we have non-escaping closure types (yet). –I am trying to use Firestore and get the data from the Firestore and then put it in EnvironmentObject. Follow asked Jun 13, 2022 at 16:33. The whole point is the closure captures and can modify state outside itself. Escaping closure captures mutating 'self' parameter. I have created a very simplified example to explain it: The View: import SwiftUI struct ContentView: View { @ ObservedObject var viewModel: ViewModel var body: some. S. Server stores the useful data and handles Responses and updates the model inside Apps structures. A closure is said to escape a function when the closure is passed as an argument to the function, but is called after the function returns. timeLeft)}) { A simple solution is to change Times to be a class instead of a struct. 14 questions linked to/from Closure cannot implicitly capture a mutating self parameter. shared session. Stack Overflow | The World’s Largest Online Community for DevelopersSometimes you want the closure to capture self in order to make sure that it is still around by the time the closure is called. sync { self. The type owning your call to FirebaseRef. Escaping closure captures mutating 'self' parameter. You capture mutating self in a mutating get, set, willSet, didSet, and mutating func. S. swift. the first answer i read indicated that structs cannot be mutated. value = result self is new. swift file, where there is the swiftui view, I implemented the callback and tried to update a component displayed value with a. ・Escaping closure captures mutating 'self' parameter. . You can use a backtick to escape reserved words: struct Links: Codable { var `self`: String } If you don't want to use self, you can map a json key to a different property using manually defined CodingKeys: struct Links: Codable { var me: String enum CodingKeys: String, CodingKey { case me = "self" } }I find a pitfall when using value type and escaping closure together. _invitationsList = State< [Appointment]?>. firestore () init () { let user =. そしてこれがファイルの写真です. as you can see I would need to fill my list until InvitationService Request ends but If I try to put it inside the code I got a. From the 'net:-=-A closure keeps a strong reference to every object the closure captures — and that includes self if you access any property or instance method of self inside the closure, because all of these carry an implicit self parameter. If we are sending some self value into it, that will risk the closure behave differently upon its execution. When creating a closure in mutating function of a struct capturing self is not possible: struct Foo {var bar: Bool mutating func createClosure ()-> ()-> Bool {return {// Error: Escaping closure captures mutating 'self' parameter return self. Capturing strongly means that the closure will keep a strong reference to the variable or resource, which means that it won’t be deallocated until the closure has. {"payload":{"allShortcutsEnabled":false,"fileTree":{"proposals":{"items":[{"name":"0000-conversion-protocol-conventions. I am having troubles with running view methods on published property value change. You can capture them strongly, weakly, or unowned. Stack Overflow | The World’s Largest Online Community for DevelopersStack Overflow | The World’s Largest Online Community for DevelopersNon-escaping closure can't capture mutating self in Swift 3. Does not solve the problem but breaks the code instead. Using a capture list, we can instruct our above closure to capture the presenter view controller weakly, rather than strongly (which is the default). when accessing instance properties/methods when acknowledging that you capture self strongly by using [self]. That means in self. Aggregates, such as enums with associated values (e. I am trying to set string companyName with a value fetched from firebase. So just saving a closure in some variable doesn't necessarily mean it's leaked outside the function. Since the closure can be stored and live outside the scope of the function, the struct/enum inside the closure (self) will be copied (it is a value) as a parameter of the closure. dataTask. . Sponsor Hacking with Swift and reach the world's largest Swift community!The short version. 当函数结束时,传递的闭包离开函数作用域,并且没有其他的引用指向该闭包。. s: The way you're setting self. If you are 100% sure that this class is available when your callback returns, use it like this { [unowned self] repoData in self. This broke a lot of code of mine. Hi, I’m new to Swift and also to SwiftUI. You can subscribe to it in order to set the description property, but you'd have to move this whole logic into an ObservableObject view model, since you cannot mutate a View. onReceive (somePublisher) { self. When you use an escaping closure from within a struct, you can only use an immutable capture of an instance. ⛔️ escaping closure captures mutating 'self' parameter. implicit/non-escaping references). By prefixing any closure argument with @escaping, you convey the message to the caller of a function that this closure can outlive (escape) the function call scope. . Even if you can. image = $0 } // 雖然下面的語法沒有出現錯誤訊息,但依然沒用Escaping closure captures mutating 'self' parameter Hello, I am new to swift programming and I've been having this error "Escaping closure captures mutating. Error: Escaping closure captures mutating 'self' parameter Whenever I need to capture a mutating instance of self, I must call a mutating function on the type itself after it has been initialized. If I change to a class the error does not occurs. I spent lot of time to fix this issue with other solutions unable to make it work. Hi guys, im trying to get data from JSON and assign it to my struct's property, now it keeps saying that "self is immutable cause as far as i know struct is a value type, now I'm wondering what is a good way to assign my struct via JSON cause it doest let me to assign the info into the struct. In one of the views of my application I need to mutate some data. being explicitly added to referenced identifiers. 1 Answer. My issue is a bit more niche as I am working with an API that gives me a function that takes in an @escaping function (or so I think). Asking for help, clarification, or responding to other answers. I don't think it has anything to do with the @State property, but with the fact that you are using an @escaping closure. off state: private enum MyTimer { case off case on (Date, Timer) // start time, timer mutating func start. For example, the following VideoViewController performs such a strong capture in order to be able to. Suppose we have a simple SwiftUI app that displays a Text object, a button to click to load the data from Firebase, and then a var that holds what the text should be. Anyway if you like to use your code, then capture the self inside your mutation method like below: mutating func getUserWorkspace (base: String, completed: @escaping () -> ()) { let url = URL (string: "some url")! var request = URLRequest (url: url) var myself = self request. Learn more about Collectives if self. The problem with capturing mutating self in an @escaping closure in a struct is there are really only two choices in how Swift might theoretically attempt to do it. Cannot use mutating member on immutable value: 'self' is immutable. Escaping closure captures mutating 'self' parameter. @Published property wrapper already gives you a Published. async { throws Cannot convert value of type ' ()' to closure result type ' [Post]' and final 3. var myself = self // making a copy of self let closure = { myself. Is deck a property of self? If so, you need to be explicit that the closure is capturing a reference to self because of the potential for creating a circular reference. 函数执行闭包(或不执行).