I think there’s something strange with popFirst. It doesn’t show up in 
the autocomplete in Xcode, but it compiles, and popLast doesn’t throw the same 
error. removeFirst doesn’t either, though it’s unsafe. Weird.



Jon


> On Sep 13, 2017, at 9:47 PM, Zhao Xin via swift-users <[email protected]> 
> wrote:
> 
> I begin to think it is related to how you `popFirst()` implemented. Check it 
> or post it here.
> 
> Zhao Xin
> 
> On Thu, Sep 14, 2017 at 9:36 AM, Roderick Mann <[email protected] 
> <mailto:[email protected]>> wrote:
> Yeah, that's not it. I made the change you suggested, I get the same error.
> 
> > On Sep 13, 2017, at 18:11 , Zhao Xin <[email protected] 
> > <mailto:[email protected]>> wrote:
> >
> > Change `self` to `ModelFetcher`. You are calling a class static property, 
> > not a class instance property.
> >
> > Zhao Xin
> >
> > On Thu, Sep 14, 2017 at 8:37 AM, Rick Mann via swift-users 
> > <[email protected] <mailto:[email protected]>> wrote:
> > Moving to Swift 4, I'm running into an issue for which I can't seem to find 
> > an answer in google:
> >
> > "Cannot use mutating member on immutable value: 'self' is immutable"
> >
> > The code looks like:
> >
> > class
> > ModelFetcher : NSObject, URLSessionDelegate
> > {
> >     ...
> >     static  let     managerDispatchQueue                    =   
> > DispatchQueue(label: "Model Download Manager Queue")
> >     static  var     pendingFetchers                         =   
> > [ModelFetcher]()
> >     static  var     currentFetcher:         ModelFetcher?
> >
> >     class
> >     func
> >     startNextFetcher()
> >     {
> >         self.managerDispatchQueue.async
> >         {
> >             guard
> >                 self.currentFetcher == nil,
> >                 let mf = self.pendingFetchers.popFirst()
> >                          ~~~~ ^                             error: cannot 
> > use mutating member on immutable value: 'self' is immutable
> >             else
> >             {
> >                 return
> >             }
> >
> >             self.currentFetcher = mf
> >             mf.start()
> >         }
> >     }
> >     ...
> > }
> >
> > This code compiled fine in Xcode 8, or in Xcode 9/Swift 3.2 as a monolithic 
> > app (the error shows up when this code is factored into a framework). Other 
> > mutating references to self seem to compile okay (e.g. "self.currentFetcher 
> > = nil" or "self.pendingFetchers.remove(at: idx)"). Not sure what's special 
> > about this one.
> >
> >
> > --
> > Rick Mann
> > [email protected] <mailto:[email protected]>
> >
> >
> > _______________________________________________
> > swift-users mailing list
> > [email protected] <mailto:[email protected]>
> > https://lists.swift.org/mailman/listinfo/swift-users 
> > <https://lists.swift.org/mailman/listinfo/swift-users>
> >
> 
> 
> --
> Rick Mann
> [email protected] <mailto:[email protected]>
> 
> 
> 
> _______________________________________________
> swift-users mailing list
> [email protected]
> https://lists.swift.org/mailman/listinfo/swift-users

_______________________________________________
swift-users mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-users

Reply via email to