@@ -298,7 +298,6 @@ extension ParseACL {
298298 */
299299 public static func defaultACL( ) throws -> Self {
300300
301- let currentUser = BaseParseUser . current
302301 let aclController : DefaultACL ?
303302
304303 #if !os(Linux)
@@ -311,11 +310,11 @@ extension ParseACL {
311310 if !aclController!. useCurrentUser {
312311 return aclController!. defaultACL
313312 } else {
314- guard let userObjectId = currentUser ? . objectId else {
313+ guard let userObjectId = BaseParseUser . current ? . objectId else {
315314 return aclController!. defaultACL
316315 }
317316
318- guard let lastCurrentUserObjectId = aclController!. lastCurrentUser ? . objectId ,
317+ guard let lastCurrentUserObjectId = aclController!. lastCurrentUserObjectId ,
319318 userObjectId == lastCurrentUserObjectId else {
320319 return try setDefaultACL ( ParseACL ( ) , withAccessForCurrentUser: true )
321320 }
@@ -328,10 +327,21 @@ extension ParseACL {
328327 }
329328
330329 /**
331- Sets a default ACL that will be applied to all instances of `ParseObject` when they are created.
330+ Sets a default ACL that can later be used by `ParseObjects`.
331+
332+ To apply the default ACL to all instances of a respective `ParseObject` when they are created,
333+ you will need to add `ACL = try? ParseACL.defaultACL()`. You can also at it when
334+ conforming to `ParseObject`:
335+
336+ struct MyParseObject: ParseObject {
337+
338+ var objectId: String?
339+ var createdAt: Date?
340+ var updatedAt: Date?
341+ var ACL: ParseACL? = try? ParseACL.defaultACL()
342+ }
332343
333- - parameter acl: The ACL to use as a template for all instances of `ParseObject` created
334- after this method has been called.
344+ - parameter acl: The ACL to use as a template for instances of `ParseObject`.
335345
336346 This value will be copied and used as a template for the creation of new ACLs, so changes to the
337347 instance after this method has been called will not be reflected in new instance of `ParseObject`.
@@ -346,39 +356,42 @@ extension ParseACL {
346356 */
347357 public static func setDefaultACL( _ acl: ParseACL , withAccessForCurrentUser: Bool ) throws -> ParseACL {
348358
349- let currentUser = BaseParseUser . current
359+ guard let currentUser = BaseParseUser . current,
360+ let currentUserObjectId = currentUser. objectId else {
361+ throw ParseError ( code: . missingObjectId, message: " Can't set defaultACL with no current user " )
362+ }
350363
351364 let modifiedACL : ParseACL ?
352365 if withAccessForCurrentUser {
353- modifiedACL = setDefaultAccess ( acl)
366+ modifiedACL = setDefaultAccess ( acl, user : currentUser )
354367 } else {
355368 modifiedACL = acl
356369 }
357370
358371 let aclController : DefaultACL !
359372 if modifiedACL != nil {
360373 aclController = DefaultACL ( defaultACL: modifiedACL!,
361- lastCurrentUser: currentUser, useCurrentUser: withAccessForCurrentUser)
374+ lastCurrentUserObjectId: currentUserObjectId,
375+ useCurrentUser: withAccessForCurrentUser)
362376 } else {
363377 aclController =
364- DefaultACL ( defaultACL: acl, lastCurrentUser: currentUser, useCurrentUser: withAccessForCurrentUser)
378+ DefaultACL ( defaultACL: acl,
379+ lastCurrentUserObjectId: currentUserObjectId,
380+ useCurrentUser: withAccessForCurrentUser)
365381 }
366382
367383 #if !os(Linux)
368- try ? KeychainStore . shared. set ( aclController, for: ParseStorage . Keys. defaultACL)
384+ try KeychainStore . shared. set ( aclController, for: ParseStorage . Keys. defaultACL)
369385 #else
370- try ? ParseStorage . shared. set ( aclController, for: ParseStorage . Keys. defaultACL)
386+ try ParseStorage . shared. set ( aclController, for: ParseStorage . Keys. defaultACL)
371387 #endif
372388 return aclController. defaultACL
373389 }
374390
375- private static func setDefaultAccess( _ acl: ParseACL ) -> ParseACL ? {
376- guard let currentUser = BaseParseUser . current else {
377- return nil
378- }
391+ private static func setDefaultAccess< T> ( _ acl: ParseACL , user: T ) -> ParseACL ? where T: ParseUser {
379392 var modifiedACL = acl
380- modifiedACL. setReadAccess ( user: currentUser , value: true )
381- modifiedACL. setWriteAccess ( user: currentUser , value: true )
393+ modifiedACL. setReadAccess ( user: user , value: true )
394+ modifiedACL. setWriteAccess ( user: user , value: true )
382395
383396 return modifiedACL
384397 }
@@ -432,6 +445,6 @@ extension ParseACL: CustomDebugStringConvertible {
432445
433446struct DefaultACL : Codable {
434447 var defaultACL : ParseACL
435- var lastCurrentUser : BaseParseUser ?
448+ var lastCurrentUserObjectId : String ?
436449 var useCurrentUser : Bool
437450}
0 commit comments