caiyue1993 / IceCream

Sync Realm Database with CloudKit
MIT License
1.94k stars 245 forks source link

filePath issue of CreamAsset #217

Open owenzhao opened 4 years ago

owenzhao commented 4 years ago

In CreamAsset's create methods, it allows to save file to places other than the default place. with public static func create(objectID: String, propName: String, url: URL, shouldOverwrite: Bool = true) -> CreamAsset?.

However, the filePath: URL property is incorrect.

/// Where the asset locates in the file system
public var filePath: URL {
    return CreamAsset.creamAssetDefaultURL().appendingPathComponent(uniqueFileName)
}

It always indicates that assets are saved in the default place. However, this may not be true. For example, if someone uses shared group container, which is common when developing Extensions like Share Extension and Today Extension, the saving place will not be the default place.

I have just made a small patch for this. Just changing the computed filePath to lazy property and assign the value when a url is given explicitly.