Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Oct 06 2020 08:06

    3lvis on master

    Update demos (compare)

  • Oct 06 2020 05:11

    3lvis on master

    Bump version number (compare)

  • Oct 06 2020 05:01

    3lvis on 8.2.1

    (compare)

  • Oct 06 2020 05:00

    3lvis on master

    Update DATAStack.podspec (compare)

  • Oct 06 2020 05:00

    3lvis on master

    Update DATAStack.podspec (compare)

  • Oct 06 2020 04:59

    3lvis on master

    Fix warnings regarding unused d… (compare)

  • Oct 06 2020 04:56

    3lvis on master

    Update project (compare)

  • Oct 06 2020 04:49

    3lvis on 8.2.0

    (compare)

  • Oct 06 2020 04:48

    3lvis on master

    Update DATAStack.podspec (compare)

  • Oct 06 2020 04:41

    3lvis on 8.1.0

    (compare)

  • Oct 06 2020 04:41

    3lvis on 8.1.0

    (compare)

  • Oct 06 2020 04:40

    3lvis on master

    Revert "Revert "Return things t… (compare)

  • Oct 06 2020 04:40

    3lvis on master

    Revert "Return things to be Obj… (compare)

  • Oct 06 2020 04:39

    3lvis on master

    Return things to be ObjC compat… (compare)

  • Oct 06 2020 04:14

    3lvis on 8.1.0

    (compare)

  • Oct 06 2020 04:14

    3lvis on 8.1.0

    (compare)

  • Oct 06 2020 04:13

    3lvis on master

    Update DATAStack.podspec (compare)

  • Oct 06 2020 04:13

    3lvis on master

    Delete .swift-version (compare)

  • Oct 06 2020 04:11

    3lvis on 8.1.0

    (compare)

  • Oct 06 2020 04:10

    3lvis on master

    Update DATAStack.podspec (compare)

Elvis Nuñez
@3lvis
Welcome! We're here to help, remember to be friendly. Have a great day :)
Trey McMeans
@treymcmeans_twitter
let fetchRequest = NSFetchRequest<AnnotationUpload>(entityName: "AnnotationUpload")
self.dataStack.performInNewBackgroundContext { backgrondContext in
do {
let isComplete = NSPredicate(format: "completed == %@", NSNumber(booleanLiteral: false))
fetchRequest.predicate = isComplete
let fetchedResults = try backgrondContext.fetch(fetchRequest)
for result in fetchedResults {
print(result)
var parameters = [
"token" : self.webToken,
"mimeType" : "application/vdn.adobe.xfdf"
]
let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
let submitString = String(format:Constants.urls.usa.test.uploadXFDFFile,self.selectedParentGroup.id!)
let submitUrl = URL(string: submitString)
let finalString = documentsPath + "/" + result.filePath!
let localFilePathUrl = URL(fileURLWithPath: finalString)
do {
let fileData = try Data(contentsOf: localFilePathUrl)
parameters["filename"] = localFilePathUrl.lastPathComponent
Alamofire.upload(multipartFormData:{ multipartFormData in
                        multipartFormData.append(fileData, withName: "xfdffile", fileName:"xfdf", mimeType: "application/vnd.adobe.xfdf")

                        for (key, value) in parameters {
                            multipartFormData.append((value as AnyObject).data(using: String.Encoding.utf8.rawValue)!, withName: key)
                        }
                    },
                         usingThreshold:UInt64.init(),
                         to:submitUrl!,
                         method:.post,
                         headers:["x-access-token": self.webToken],
                         encodingCompletion: { encodingResult in
                            switch encodingResult {
                            case .success(let upload, _, _):
                                upload.responseJSON { response in
                                    NetworkLog(message: response.debugDescription)
                                    backgrondContext.delete(result)
                                }
                            case .failure(let encodingError):
                                ELog(message: encodingError.localizedDescription)
                            }
                    })
                } catch {
                    ELog(message: error.localizedDescription)
                    backgrondContext.delete(result)
                }
            }
        } catch {ELog(message: error.localizedDescription)}
        self.saveBackgroundContext(withContext: backgrondContext)
    }
}

func saveBackgroundContext(withContext:NSManagedObjectContext)  {
    do {
        try withContext.save()
    } catch {ELog(message: error.localizedDescription)}
}
Hey Elvis. Here is the code we discussed earlier. I wasn't sure about doing this in a for loop, so that may be the cause. But, we've seen this in other parts of our code and it still does not merge from the background context
Elvis Nuñez
@3lvis
@treymcmeans_twitter might be somewhat related to SyncDB/Sync#372
it works on the main context =/
I think I know why your code isn’t working
could you try saving right after deleting?
Also, the Alamofire block has a different queue than the one where the Core Data object uses so that might cause threading issues
Elvis Nuñez
@3lvis

I usually try to separate networking from persistency to avoid issues.

So first collect the necesary knowledge to complete the networking request, let’s say the final path, so you’ll have an array of final path and IDs. Once your networking request finishes, you’ll go back to Core Data and delete all the changes that succeded in one go.

Trey McMeans
@treymcmeans_twitter
Yep. That was it. I moved some functions around and all is working. Even our other issue is solved now. Thanks @3lvis
Thanks for you work on Sync and everything else
Elvis Nuñez
@3lvis
<3 You’re welcome
Bart Jochems
@batjo
Hi @3lvis, I was checking some more on this issue: #74. I see that there's a writerContext, but the mainContextdoesn't seem to be a child of the writerContext. Can you maybe explain a bit more what the writerContext does? And could you elaborate a bit more on this comment: "Sounds like something that we are already doing. Might be worth to take a look if this is possible with the current setup." So on one hand you say something like this is already done but on the other hand you said take a look if it's possible with the current setup
Elvis Nuñez
@3lvis
@batjo I've found a bunch of bugs related to parent/child contexts so I went for the good old approach of merging contexts based in notifications. What this allows as well is to provide the synchronous in unit tested enviroments that simplify writing tests since you don't need XCTestExpectation.
Traditional.png
The biggest difference is of course when you save a temporary background context, without the writer context after the merge to main context is done, then everything saves to the persisten store coordinator in the main thread, this can freeze your UI, sending values to your Fetched Results Controller on the other side is quite performant.
That's why for DataStack I added a set up where I separated the saving to the persistent store and the sending of the values to fetched results controller by introducing a writer context.
Async.png
The actual implementation seems a bit complex because of the usage of notifications, you can achieve something similar using parent/child contexts but you lose some of the control.
Elvis Nuñez
@3lvis
Sorry for taking painfully too long in replying, for some reason I didn't get the Gitter notification.
Bart Jochems
@batjo

Hi @3lvis thank you for explaining the situation and why you have chosen for this direction. The reason I'm looking for a childContext is because with the current setup it's hard to make temporary changes to objects. In issue #74 you gave 2 solutions for this, one by waiting till the transaction is confirmed (since I want offline support this isn’t an option) and the second solution by copying all relationships. That second solution could work in my case but it feels like fighting against the CoreData framework which has already a good solution for this problem: childContexts. In WWDC 2012 session 214 they say that childContext are a perfect solution for these kind of situations.

For example if you have a note taking application, users can edit or create notes. When he’s creating or editing a note, you want to use a “scratch” NSManagedObjectContext, which is a child of the parent context. This way it’s very easy to discard changes (i.e. if the user decides to cancel his edits) or save the changes by saving the child context. Here I don’t have to write any extra code for copying relationships or convert the object to JSON for example.

I agree there were some bugs related to childContext in early versions of iOS (I think it was mainly 5-6) but in the recent iOS releases it seems to be pretty stable. Would you be open to add support for childContexts? I could help with a PR

Elvis Nuñez
@3lvis
@batjo for sure! Sound like a good way of cleaning up and removing the disposablePersistentStoreCoordinator and newDisposableMainContext
since it seems like they would behave similarly