Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 395
user2481787 Avatar asked Jul 09 '15 10:07

user2481787


3 Answers

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

let acl = PFACL()
acl.publicReadAccess = true
acl.publicWriteAccess = true
yourObject.ACL = acl
like image 195
William GP Avatar answered Nov 04 '22 13:11

William GP


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.

like image 35
kRiZ Avatar answered Nov 04 '22 14:11

kRiZ


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)
    
like image 4
quents Avatar answered Nov 04 '22 14:11

quents