'AnyObject' Doesn't have a Member "contactUID" Even thought Intelitype Says it Does? - ios

Another ameture hour Swift Programming Question.
I have been returning values for an object from an array of object "Any Object" "Results". The intellitype says I have an object in the array with a value "ContactUID" however when I try to use ContactUID I get an error saying 'AnyObject' Doesn't contain member 'contactUID'.
The Array called HBCContactList successfully returns, FirstName, LastName and all the other items listed on the screen in the code. However it Will not return the Value 'ContactUID'.
The Model has got the right item. However unlike all the others... ContactUID is a INT64 instead of a string... I have added some screenshots to assit with the process of explaining. Sorry it sounds complicated but I expect I am missing something stupid.

Autocomplete on iOS isn't always accurate, often it will just list all possible selectors / methods.
The root of your problem here is that even though you know HCCContactList holds only HBCDirectoryModel objects, the compiler doesn't as MOContext.executeFetchRequest(freq, error: nil) returns an Array which declares it contains AnyObject's ([AnyObject] / Array<AnyObject>). In order to refer to any of these objects as an HBCDirectoryModel you'll need to conduct a cast to this type.
The easiest way to do this is is to declare your HCCContactList as being an array of HBCDirectoryModel's instead of AnyObject's, and then casting the result of calling MOContext.executeFetchRequest() to this same type.
You can do this as follows
var HCCContactList: Array<HBCDirectoryModel> = []
HCCContactList = MOContext.executeFetchRequest(freq, error: nil) as Array<HBCDirectoryModel>
Or using the shorter syntax
var HCCContactList:[HBCDirectoryModel] = []
HCCContactList = MOContext.executeFetchRequest(freq, error: nil) as [HBCDirectoryModel]

Related

Microsoft Graph: Unable to filter by binary singleValueExtendedProperty

I'm trying to retrieve an event from the grapi api based on a binary extended property that I already have a value for. I have retrieved this value from the same api so I know that an event with this value exists. I also know that the property id is correct since I used this with .Expand() to get the value.
var value = "BAAAAIIA4AB0xbcQGoLgCAAAAAAwMvfBFvzUAQAAAAAAAAAAEAAAAEZ53uCfQ51AhtRf+FNQjOk=";
var cleanGlobalObjectIdPropertyId = "Binary {6ed8da90-450b-101b-98da-00aa003f1305} Id 0x23";
var events = await client.Users["myuser#example.com"].Events.Request()
.Filter($"singleValueExtendedProperties/Any(ep: ep/id eq '{cleanGlobalObjectIdPropertyId}' and ep/value eq '{value}')")
.GetAsync();
This is the error i get:
Microsoft.Graph.ServiceException : Code: ErrorInvalidUrlQueryFilter
Message: The filter expression for $filter does not match to a single extended property and a value restriction.
I have used the same filter syntax with an extended property of type string and that works fine, so I think the fact that this is a binary property is relevant to the problem.
I also faced to this problem. But I try to search for /messages against mapi property SearchKey.
I was thinking to use something like:
https://graph.microsoft.com/v1.0/me/messages?$filter=singleValueExtendedProperties%2FAny(ep%3A%20ep%2Fid%20eq%20'Binary%200x300B'%20and%20ep%2Fvalue%20eq%20'yxum+DwfxUy13C4qs5R6ig==')
According to https://docs.oasis-open.org/odata/odata/v4.0/errata03/os/complete/part2-url-conventions/odata-v4.0-errata03-os-part2-url-conventions-complete.html#_Toc453752358
"The six comparison operators can be used with all primitive values except Edm.Binary, Edm.Stream, and the Edm.Geo types."
So I assume that binary should be casted or decoded from base64 somehow, or it's impossible at all.
UPDATE:
So I finally figure it out.
Let's say I got the value of singleValueExtendedProperty as:
{
"id": "Binary 0x300b",
"value": "yxum+DwfxUy13C4qs5R6ig=="
}
And I wanted to find message by value of this property. The problem here is that '+' should be encoded if exists. Also value should be casted to Edm.Binary. Correct query looks like this:
https://graph.microsoft.com/v1.0/me/messages?$filter=singleValueExtendedProperties%2FAny(ep%3A%20ep%2Fid%20eq%20'Binary%200x300B'%20and%20cast(%20ep%2Fvalue,Edm.Binary)%20eq%20binary'yxum%2BDwfxUy13C4qs5R6ig==')

Cannot assign value of type 'Dictionary<String?, String?>.Keys' to type 'String'

Here I have a database, which I want to easily use for my table view. However, I can't reach the properties, because I don't know how to assign from a dictionary to a string. It tells me:
Cannot assign value of type 'Dictionary.Keys' to
type 'String'
import Foundation
struct Test {
var title: String
var tagPreview: Tagpreview
}
struct Tagpreview {
var tag: [String?:String?]
}
var cases = [
Test(title: "title1", tagPreview: Tagpreview(tag: ["tag1": "preview1"])),
Test(title: "title2", tagPreview: Tagpreview(tag: ["tag2": nil])),
Test(title: "title3", tagPreview: Tagpreview(tag: [nil: nil])),
Test(title: "title4", tagPreview: Tagpreview(tag: ["tag4": "preview4", "tag5": nil]))
]
I want to use the keys and the values from the dictionary in the second struct to populate the text labels later in a cell:
cell.titleLabel?.text = cases[indexPath.row].tag.preview.keys //ERROR
cell.textLabel?.text = cases[indexPath.row].tag.preview.values//ERROR
There is something about dictionaries that I can't find anywhere as well as a comprehensive solution for this issue.
Now, if you know another way how to populate them easily, I'd much appreciate that! Thank you a lot in advance and have a good day!
The error you are receiving is due to Dictionary.keys returning a collection of the Type you selected as key. In your case the call cases[indexPath.row].tag.preview.keys returns a Collection of String? (similar to [String?])
Now if you wish to access a specific value from this collection, you should be able to do so like this:
let someText = cases[indexPath.row].tagPreview.tag.keys.map{ $0 }[someIndex]
Note that the use of map(). It merely converts the Strings collection to an Array of Strings, whose index is Int, thus making it easier to access the individual elements (otherwise you'd need abit more general/cumbersome iteration API of Collection).
Just side comment, it seems a bit difficult to extract data and map it directly to the view, if you intend to use such mapping many places it may pay out to have some intermediate data types which are easier to use when presenting; it really depends on your preference and the overall problem.

RxSwift : BehaviorRelay in place of Variable usage

I'm new to RxSwift and reading about subjects, I tried Variable Subject. Which in turns giving Warning in console
ℹ️ [DEPRECATED] `Variable` is planned for future deprecation. Please consider `BehaviorRelay` as a replacement. Read more at: https://git.io/vNqvx
Earlier I have declared Variable like this
var searchItems = Variable<[MyClass]>([])
So i have done basic array operations from it's property called value as it was get set property like
1. self.searchItems.value.removeAll()
2. self.searchItems.value.append(items)
3. self.searchItems.value = items
Now After getting warning i changed it to BehaviorRelay like
var searchItems = BehaviorRelay<[MyClass]>(value: [])
So I got error that value is get property only.
I googled alot but can't get suitable explanations for Array operations.
I only got a code self.searchItems.accept(items) which i really don't know what it exactly do add fresh items or append.
I needed how all 4 operations will be performed when using BehaviorRelay?
1) Remove all
var array = self.searchItems.value
array.removeAll()
self.searchItems.accept(array)
2) Append item
self.searchItems.value.accept(searchItems + [items])
3) Value = ...
self.searchItems.value.accept(items)
Use accept.
var value = searchItems.value
value.removeAll()
searchItems.accept(value)
etc...

Initialize two dimensional object array returns fatal error

I want to create a 2d array of teams. Therefore, I can reach with like Teams[0][i] or Teams[1][0]. First print returns correct value but second one returns fatal index out of range.
self.teams = [self.first_array , self.second_array]
print(self.teams[0][0].name)
print(self.teams[1][0].name)
Try doing:
self.teams = [self.first_array , self.first_array]
If this works, then there's something wrong with self.second_array specifically. Your syntax looks fine except we can't see the rest of the code, particularly where you're initializing self and its properties.

Multidimensional Arrays Ambiguous Reference to Members

The following code used to work, but now when I try and use the code I'm getting an error stating, "Ambiguous reference to member 'append'". Any ideas?
var allInfo: Array = [[String]]()
let Dogs : Array = ["Border Collie","Doberman", "German Shepherd"]
let Cats : Array = ["Top Cat","Tom"]
allInfo.append(Dogs)
allInfo.append(Cats)
I've changed the name of the allInfo variable to myPets to see if it that was the problem and updated to Xcode 7.1.1 but still getting the following error. Although it works in playground. Very frustrating.
Thanks for all the support. I got this working by explicitly adding the type of each array as follows:
let Dogs : Array<String> = ["Border Collie","Dobermann", "German Shepherd"]
And I had to remove the : Array from my multidimensional arrays like so:
var myPets = [[String]]()
I don't know if this is an Xcode bug but hopefully my answer may help others in our community.
You most likely have a different definition of either the allInfo variable or the elements you are adding. Make sure you do not have duplicates of those.

Resources