-
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* WIP: Adding FileManager * WIP * update * Added File saves. Need to fix URLMocker. * Fix metadata and tags for S3 adapter. * Reorganized some of the responses * Support uploading local files * Finished initial saved, starting on downloads. * Add delete file * Make batch deletes look like regular deletes instead of using result enum * Added save from cloud file * fix warnings * Add more documentation * remove file * Fix Swift backwards compatability * Patch URL mocker for ParseFile tests * Fix tearDown error * Remove bard URL/ParseError test * Add async tests * Only allow file streams through save * Add ParseFileManagerTests * Update progress signatures * Add more tests. Update documentation * Additional test * Extend async wait times since some CI servers are slower than others. * Changes before adding tests * Add deep-save test * Add Playgrounds examples and fix bugs * Bug fix: fetching stored files from Parse Server. - Improved testing for embedded ParseObjects and ParseFiles - Improved ParseFile playground * Set callbackQueue for URLSessionDelegate. It still isn't being fired, but should callback to the correct queue in the future. * Removed extra arg in API.Command. - Fixed a bug that overwrites local ACL with nil after a save on a ParseObject - Cleaned up comments and code * Progress updates works (removed WIP warnings). - Update playgrounds for ParseFile - Update documentation * Fix delete error response for ParseObjects (these work a little differently since a no response is considered successful). * remove .DS_Store * Still fixing/testing delete of batch ParseObject
- Loading branch information
Showing
41 changed files
with
3,972 additions
and
785 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ docs/ | |
xcuserdata/ | ||
|
||
## Other | ||
.DS_Store | ||
*.moved-aside | ||
*.xccheckout | ||
*.xcscmblueprint | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// swift-tools-version:5.1 | ||
// swift-tools-version:5.0 | ||
|
||
import PackageDescription | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
154 changes: 154 additions & 0 deletions
154
ParseSwift.playground/Pages/9 - Files.xcplaygroundpage/Contents.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
//: [Previous](@previous) | ||
|
||
import PlaygroundSupport | ||
import Foundation | ||
import ParseSwift | ||
PlaygroundPage.current.needsIndefiniteExecution = true | ||
|
||
initializeParse() | ||
|
||
//: Create your own ValueTyped ParseObject | ||
struct GameScore: ParseObject { | ||
//: Those are required for Object | ||
var objectId: String? | ||
var createdAt: Date? | ||
var updatedAt: Date? | ||
var ACL: ParseACL? | ||
|
||
//: Your own properties | ||
var score: Int = 0 | ||
var profilePicture: ParseFile? | ||
var myData: ParseFile? | ||
|
||
//custom initializer | ||
init(score: Int) { | ||
self.score = score | ||
} | ||
|
||
init(objectId: String?) { | ||
self.objectId = objectId | ||
} | ||
} | ||
|
||
//: Define initial GameScore | ||
var score = GameScore(score: 52) | ||
|
||
//: Set the link online for the file | ||
let linkToFile = URL(string: "https://parseplatform.org/img/logo.svg")! | ||
|
||
//: Create a new ParseFile for your picture | ||
let profilePic = ParseFile(name: "profile.svg", cloudURL: linkToFile) | ||
|
||
//: Set the picture as part of your ParseObject | ||
score.profilePicture = profilePic | ||
|
||
/*: Save asynchronously (preferred way) - Performs work on background | ||
queue and returns to designated on designated callbackQueue. | ||
If no callbackQueue is specified it returns to main queue. | ||
*/ | ||
score.save { result in | ||
switch result { | ||
case .success(let savedScore): | ||
assert(savedScore.objectId != nil) | ||
assert(savedScore.createdAt != nil) | ||
assert(savedScore.updatedAt != nil) | ||
assert(savedScore.ACL == nil) | ||
assert(savedScore.score == 52) | ||
assert(savedScore.profilePicture != nil) | ||
|
||
print("Your profile picture has been successfully saved") | ||
|
||
//: To get the contents updated ParseFile, you need to fetch your GameScore | ||
savedScore.fetch { result in | ||
switch result { | ||
case .success(let fetchedScore): | ||
guard let picture = fetchedScore.profilePicture, | ||
let url = fetchedScore.profilePicture?.url else { | ||
return | ||
} | ||
print("The new name of your saved profilePicture is: \(picture.name)") | ||
print("The profilePicture is saved to your Parse Server at: \(url)") | ||
print("The full details of your profilePicture ParseFile are: \(picture)") | ||
|
||
//: If you need to download your profilePicture | ||
picture.fetch { result in | ||
switch result { | ||
case .success(let fetchedFile): | ||
print("The file is now saved on your device at: \(fetchedFile.localURL)") | ||
print("The full details of your profilePicture ParseFile are: \(fetchedFile)") | ||
case .failure(let error): | ||
assertionFailure("Error fetching: \(error)") | ||
} | ||
} | ||
|
||
case .failure(let error): | ||
assertionFailure("Error fetching: \(error)") | ||
} | ||
} | ||
case .failure(let error): | ||
assertionFailure("Error saving: \(error)") | ||
} | ||
} | ||
|
||
/*: 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)") | ||
} | ||
|
||
/*: Files can also be saved from files located on your device by using: | ||
let localFile = ParseFile(name: "hello.txt", localURL: URL) | ||
*/ | ||
//: [Next](@next) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.