How do I set the ACL of a PFObject in Swift?
Asked Answered
H

4

5

I'm using the Parse iOS SDK, and I'm creating objects for a particular class (not "_User"). However, I need to modify the ACL of these objects so that anyone can read or write it. Currently, Parse sets the ACL of newly created objects to Public Read and Creator Write.

In short, I'm not sure how to set the ACL of a Parse object to public read/write in Swift.

Herrenvolk answered 9/7, 2015 at 10:41 Comment(0)
Z
8

It's been updated, now it should be done like this:

let acl = PFACL()
acl.publicReadAccess = true
acl.publicWriteAccess = true
yourObject.ACL = acl
Zymogenic answered 22/1, 2016 at 14:59 Comment(1)
i put this in my viewcontoller but no luck do you have any idea what im doing wrong?Danu
L
4
let acl = PFACL()
acl.setPublicReadAccess(true)
acl.setPublicWriteAccess(true)
yourObject.ACL = acl

UPDATE:

You can set write permissions to a larger group of users using "roles":

acl.setWriteAccess(true, forRoleWithName:"everyone")

You will have to create the role first.

Lunseth answered 9/7, 2015 at 10:50 Comment(2)
"PFACL has no member 'setPublicReadAccess'"Unless
setPublicReadAccess is in PFACL, also shown in the documentation here: parse.com/docs/ios/guide#security-object-level-access-control. However, it does not seem to be listed under the api documentation anymore.Lunseth
S
4

If you want your ACL settings apply for all objects you create, you can:

  1. Open AppDelegate.swift
  2. In didFinishLaunchingWithOptions method

    • You could see PFACL() is set like this:

      let defaultACL = PFACL();
      
      // If you would like all objects to be private by default, remove this line.
      defaultACL.setPublicReadAccess(true)
      
  3. Here, just add:

     defaultACL.setPublicWriteAccess(true)
    
Stayathome answered 3/3, 2016 at 8:6 Comment(1)
Thx for solution. Just want to add that the latest version has syntax defaultACL.publicWriteAccess = trueHomophonous
D
4

As of Parse iOS SDK 1.14.3:

let acl = PFACL()
acl.getPublicReadAccess = true
acl.getPublicWriteAccess = true
object.acl = acl
Deepsea answered 17/3, 2017 at 16:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.