Start a new topic
Answered

Storing UIImage in Kinvey Backend Using Swift 2

Hi!

Swift newbie here and I've been having a problem for hours that's absolutely doing my head in. I have the code below, and I'm trying to store a UIImage in the Kinvey backend. I've followed instructions from other users who had a similar problem, but nothing's working for me. 


import Foundation

class Test:  NSObject {


    var userID: String?

    var entityId: String?

    var picture: UIImage?

    var metadata: KCSMetadata?

   

   


   

    internal override func hostToKinveyPropertyMapping() -> [NSObject : AnyObject]! {

        return [

            "entityId" : KCSEntityKeyId,

            "userID" : "userID",

            "picture":"picture",

            "metadata": KCSEntityKeyMetadata


        ]

    }

   

    internal class override func kinveyPropertyToCollectionMapping() -> [NSObject : AnyObject]! {

        return [

            "picture" :*not allowing me to select KCSFileStoreCollectionName*

        ]

    }

   


   

}


The problem is, I am trying to store the value 'KCSFileStoreCollectionName' in the dictionary returned by kinveyPropertyToCollectionMapping(), but 'KCSFileStoreCollectionName' is coming up as an 'unresolved identifier' in Xcode. I've had a look at the Kinvey KCSFileStore.h file, and I can clearly see 'KCSFileStoreCollectionName' has been declared as a global variable. 


@interface KCSCollection (KCSFileStore)


/** Constant to represent the File metadata collection */

FOUNDATION_EXPORT NSString* const KCSFileStoreCollectionName;


/** Helper method to access the file store metadata. Objects will be `KCSFile` type. */

+ (instancetype) fileMetadataCollection;

@end


However, for some reason Xcode isn't picking it up. I downloaded the Relational-Data example from here, and also tried to set the 'KCSFileStoreCollectionName' property, but still having the same issue. Please any help with this would be appreciated!


Best Answer
Toby,

I have sent this to the development team to look at.

Meanwhile, as a workaround, can you try using “_blob” instead of KCSFileStoreCollectionName? Let me know if it works for you.

internal class override func kinveyPropertyToCollectionMapping() -> [NSObject : AnyObject]! {
        return [
            "picture” :”_blob"
        ]
    }


Thanks,
Pranav
Kinvey Support

 


1 person has this question
1 Comment

Answer
Toby,

I have sent this to the development team to look at.

Meanwhile, as a workaround, can you try using “_blob” instead of KCSFileStoreCollectionName? Let me know if it works for you.

internal class override func kinveyPropertyToCollectionMapping() -> [NSObject : AnyObject]! {
        return [
            "picture” :”_blob"
        ]
    }


Thanks,
Pranav
Kinvey Support

 

Login or Signup to post a comment