Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add File support #40

Merged
merged 37 commits into from
Dec 30, 2020
Merged

Add File support #40

merged 37 commits into from
Dec 30, 2020

Conversation

cbaker6
Copy link
Contributor

@cbaker6 cbaker6 commented Dec 25, 2020

Adds full support for files. Close #31

  • Added test cases
  • Saving ParseFile's as child objects
  • File upload/download cancellation (works): Some comments on stack overflow mention this doesn't work because a completion handlers and delegates can't be used at the same time for URLSession, but it's working in this PR.
  • Playground examples
  • Documentation
  • Switched delete for object batches so they look like regular deletes (removed result enum for ParseError?)
  • Placed all server responses in one file Responses.swift
  • Bumped the waiting times for async tests from 10 seconds to 20 seconds due to slow CI. Some of the servers for the CI run slow on multithreaded tests and exceed the 10 seconds causing tests to fail.
  • Bug fix: there was an issue of the local ACL being overwritten with nil during a save of a new ParseObject

@cbaker6 cbaker6 marked this pull request as draft December 25, 2020 05:17
@vdkdamian
Copy link
Contributor

I see the documentation is finished, where can I find it?

@cbaker6
Copy link
Contributor Author

cbaker6 commented Dec 25, 2020

I see the documentation is finished, where can I find it?

The documentation is here: http://parseplatform.org/Parse-Swift/api/

The docs for “ParseFile” won’t populate until this PR is merged. If you want to see it now, you can look through the mark up in the code.

@codecov
Copy link

codecov bot commented Dec 26, 2020

Codecov Report

Merging #40 (46c2dba) into main (739db44) will increase coverage by 2.82%.
The diff coverage is 82.20%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #40      +/-   ##
==========================================
+ Coverage   72.87%   75.69%   +2.82%     
==========================================
  Files          30       32       +2     
  Lines        2127     2724     +597     
==========================================
+ Hits         1550     2062     +512     
- Misses        577      662      +85     
Impacted Files Coverage Δ
...seSwift/Object Protocols/Protocols/Fetchable.swift 0.00% <ø> (ø)
...arseSwift/Object Protocols/Protocols/Savable.swift 0.00% <ø> (ø)
Sources/ParseSwift/API/URLSession+extensions.swift 60.86% <62.79%> (-39.14%) ⬇️
Sources/ParseSwift/API/API+Commands.swift 69.81% <73.76%> (+6.50%) ⬆️
Sources/ParseSwift/API/Responses.swift 68.08% <83.33%> (+13.91%) ⬆️
Sources/ParseSwift/Parse Types/ParseFile.swift 87.22% <87.22%> (ø)
...rces/ParseSwift/Object Protocols/ParseObject.swift 78.09% <87.69%> (+0.84%) ⬆️
...ources/ParseSwift/Object Protocols/ParseUser.swift 80.80% <87.87%> (+0.63%) ⬆️
Sources/ParseSwift/Storage/ParseFileManager.swift 88.88% <88.88%> (ø)
Sources/ParseSwift/API/API.swift 97.22% <92.00%> (-2.78%) ⬇️
... and 11 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 739db44...46c2dba. Read the comment docs.

@cbaker6 cbaker6 marked this pull request as ready for review December 28, 2020 05:40
@cbaker6
Copy link
Contributor Author

cbaker6 commented Dec 28, 2020

@TomWFox can you look over the added documentation? Particularly in ParseFile.swift. I also added a how-to-use "Files" in playgrounds which can probably read better also.

@pranjalsatija can you review?

My apologies in advance for the big PR, it took a lot to get ParseFile together.

- Improved testing for embedded ParseObjects and ParseFiles
- Improved ParseFile playground
… but should callback to the correct queue in the future.
- Fixed a bug that overwrites local ACL with nil after a save on a ParseObject
- Cleaned up comments and code
- Update playgrounds for ParseFile
- Update documentation
…rently since a no response is considered successful).
@cbaker6 cbaker6 merged commit 3f1c897 into main Dec 30, 2020
@cbaker6 cbaker6 deleted the fileSupport branch December 30, 2020 20:41
@vdkdamian
Copy link
Contributor

How can I get the data of a file? In objective c it was like this:

PFFileObject *dataFile = queriedFile[projectName];
[dataFile getDataInBackgroundWithBlock:^(NSData * _Nullable data, NSError * _Nullable error) {
}];

It looks like it's different with Swift.

@cbaker6
Copy link
Contributor Author

cbaker6 commented Jan 2, 2021

The playground pages have examples of how to do some of the general things:

/*: Files can also be saved from data. Below is how to do it synchrously, but async is similar to above
Create a new ParseFile for your data
*/
let sampleData = "Hello World".data(using: .utf8)!
let helloFile = ParseFile(name: "hello.txt", data: sampleData)
//: Define another GameScore
var score2 = GameScore(score: 105)
score2.myData = helloFile
//: Save synchronously (not preferred - all operations on main queue)
do {
let savedScore = try score2.save()
print("Your hello file has been successfully saved")
//: To get the contents updated ParseFile, you need to fetch your GameScore
let fetchedScore = try savedScore.fetch()
if var myData = fetchedScore.myData {
guard let url = myData.url else {
fatalError("Error: file should have url.")
}
print("The new name of your saved data is: \(myData.name)")
print("The file is saved to your Parse Server at: \(url)")
print("The full details of your data file are: \(myData)")
//: If you need to download your profilePicture
let fetchedFile = try myData.fetch()
if fetchedFile.localURL != nil {
print("The file is now saved at: \(fetchedFile.localURL!)")
print("The full details of your data ParseFile are: \(fetchedFile)")
/*: If you want to use the data from the file to display the text file or image, you need to retreive
the data from the file.
*/
guard let dataFromParseFile = try? Data(contentsOf: fetchedFile.localURL!) else {
fatalError("Error: couldn't get data from file.")
}
//: Checking to make sure the data saved on the Parse Server is the same as the original
if dataFromParseFile != sampleData {
assertionFailure("Data isn't the same. Something went wrong.")
}
guard let parseFileString = String(data: dataFromParseFile, encoding: .utf8) else {
fatalError("Error: couldn't create String from data.")
}
print("The data saved on parse is: \"\(parseFileString)\"")
} else {
assertionFailure("Error fetching: there should be a localURL")
}
} else {
assertionFailure("Error fetching: there should be a localURL")
}
} catch {
fatalError("Error saving: \(error)")
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Saving ParseObjects with File properties
2 participants