If I logged in with social account To fetch record using getproperty(category), I am getting the error - NsArray element failed to match the swift Array Element type.
*Category is the related to other table
*There won’t be any issue if I logged in with manually registered user.
Did you login with easyLoginFacebook or with loginWithFacebookSDK?
Could you give us some your code?
I used “backendless.userService.easyLoginWithFacebookFieldsMapping” to Login with Facebook
Please check the below code
class UserAndCategoriesMapping : BackendlessEntity {
var categoryID : Int = 0
}
func getUserSelectedCategories(user : BackendlessUser, callback : GetUserSelectedCategoriesCompletionBlock){
if(user.getProperty("categories") is NSNull){
print("getProperty(categories) is nil")
callback(categories: [], error: nil)
return
}
let userAndCategoriesMappingArray = user.getProperty("categories") as! [UserAndCategoriesMapping] /* here we can get array count but if i try to get the value will crash
po userAndCategoriesMappingArray.count
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000}
span.s1 {font-variant-ligatures: no-common-ligatures}
2
po userAndCategoriesMappingArray[0]
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000}
span.s1 {font-variant-ligatures: no-common-ligatures}
fatal error: NSArray element failed to match the Swift Array Element type */
var whereClause = ""
var index = 0
for userAndCategoriesMapping : UserAndCategoriesMapping in userAndCategoriesMappingArray{
print(userAndCategoriesMapping.categoryID)
whereClause = whereClause.stringByAppendingString("categoryId = \(userAndCategoriesMapping.categoryID)")
index += 1
if(index < userAndCategoriesMappingArray.count){
whereClause = whereClause.stringByAppendingString(" OR ")
}
}
if(index > 0){
let dataQuery = BackendlessDataQuery()
dataQuery.whereClause = whereClause
backendless.data.of(Category.ofClass()).find(dataQuery, response: { (backendlessCollection) in
let categories = CategoriesMapping.init(backendlessCollection: backendlessCollection)
callback(categories: categories.categoriesArray, error: nil)
}) { (fault) in
print(fault)
callback(categories: nil, error: nil)
}
}else{
callback(categories: [], error: nil)
}
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #4f8187}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; min-height: 13.0px}
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000}
p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #d12f1b}
span.s1 {font-variant-ligatures: no-common-ligatures; color: #000000}
span.s2 {font-variant-ligatures: no-common-ligatures; color: #ba2da2}
span.s3 {font-variant-ligatures: no-common-ligatures}
span.s4 {font-variant-ligatures: no-common-ligatures; color: #31595d}
span.s5 {font-variant-ligatures: no-common-ligatures; color: #d12f1b}
span.s6 {font-variant-ligatures: no-common-ligatures; color: #703daa}
span.s7 {font-variant-ligatures: no-common-ligatures; color: #3e1e81}
span.s8 {font-variant-ligatures: no-common-ligatures; color: #4f8187}
span.s9 {font-variant-ligatures: no-common-ligatures; color: #272ad8}
}
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; min-height: 13.0px}
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008400}
span.s1 {font-variant-ligatures: no-common-ligatures; color: #ba2da2}
span.s2 {font-variant-ligatures: no-common-ligatures}
span.s3 {font-variant-ligatures: no-common-ligatures; color: #4f8187}
span.s4 {font-variant-ligatures: no-common-ligatures; color: #703daa}
span.s5 {font-variant-ligatures: no-common-ligatures; color: #272ad8}
span.s6 {font-variant-ligatures: no-common-ligatures; color: #000000}
Hi Fevicks,
Please prepare a minimal application example, which would reproduce the error. It will help us greatly to locate the problem faster.