Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Fetch data from Plist in Swift?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 2.09k
    Comment on it

    Hi

    Property List  or plist files provide a convenient way to store and access our data. Data can be stored in the form of array as well as Dictionary. It supports various primitive types such as boolean, data, date, number, and string.

    We add list of item in  Plist file so that it can be easily fetched, managed and displayed in our application.


     To fetch array of item from plist  add the following code:

           var myMenuArray: NSArray?
            if let path = Bundle.main.path(forResource: "yourFileName", ofType: "plist"){
                myMenuArray = NSArray(contentsOfFile: path)  
            } 

    If you are working with Dictionary use below lines of code:

            var myDict : NSDictionary?
            if let path = Bundle.main.path(forResource: "yourFileName", ofType: "plist"){
                          myDict = NSDictionary(contentsOfFile: path)
                      }
    

     

    Thanks

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: