MapKit: How to retrieve apartment number from the return value of MKLocalSearchResponse - objective-c

I searched thoroughly online but couldn't find any discussion about this:
The MKLocalSearchResponse object returned from a MapKit search is a collection of MKMapItem, which has the information of search results, e.g. City, state, country.
A single MKMapItem looks like this(from Xcode quick look of the object):
"Name: ADVANCED SOLUTIONS ADDICTION MANAGEMENT CurrentLocation: 0 Place: <GEOPlace: 0x9b2db90> {
address = {
formattedAddressLine = (
\"205 W Crestway Ave\",
\"Unit 200\",
\"Derby, KS 67037-1850\",
\"United States\"
);
structuredAddress = {
administrativeArea = Kansas;
administrativeAreaCode = KS;
country = \"United States\";
countryCode = US;
dependentLocality = (
Derby,
Rockford
);
fullThoroughfare = \"205 W Crestway Ave\";
geoId = (
);
locality = Derby;
postCode = 67037;
postCodeExtension = 1850;
postCodeFull = \"67037-1850\";
subAdministrativeArea = Sedgwick;
subLocality = Rockford;
subPremise = (
{
name = 200;
type = 0;
}
);
subThoroughfare = 205;
thoroughfare = \"W Crestway Ave\";
};
};
}"
I was able to retrieve all the information I needed, except the Apartment number. It's contained in the "subPremise" part, which I don't know how to retrieve.
You may suggest me to retrieve it from the "formattedAddressLines", which I have access to, but for some results, that property is empty, so I cannot rely on it.
I've also tried the "addressDictionary" property, it has all the necessary information except apartment number, which is very unthoughtful to me.

mapItem.placemark.subThoroughfare. Note that it may be empty

Related

SAP Business One - Add BP (DI Error: (-5002)

I am trying to add new addresses into a BP. If there is an address registered in the BP everything works, but now if it is new addresses return the error -5002 - Error updating BP: [OCRD.State2], 'the linked value' SP 'does not exist'
I test with SAP Business 10 (10.00.140) FP 2011
if (oBP.GetByKey(CardCode))
{
oBP.Addresses.SetCurrentLine(oBP.Addresses.Count - 1);
if (!string.IsNullOrEmpty(oBP.Addresses.AddressName))
{
oBP.Addresses.Add();
}
UF = json.data.endereco_uf;
if (UF.Length > 2)
{
UF = "";
}
oBP.Addresses.SetCurrentLine(oBP.Addresses.Count - 1);
oBP.Addresses.AddressName = "Novo 1";
oBP.Addresses.AddressType = BoAddressType.bo_ShipTo;
oBP.Addresses.Street = json.data.endereco_logradouro;
oBP.Addresses.Block = json.data.endereco_bairro;
oBP.Addresses.ZipCode = json.data.endereco_cep;
oBP.Addresses.City = json.data.endereco_municipio;
oBP.Addresses.State = UF;
oBP.Addresses.County = county;
oBP.Addresses.StreetNo = json.data.endereco_numero;
oBP.Addresses.BuildingFloorRoom = json.data.endereco_complemento;
oBP.Addresses.Add();
oBP.Addresses.SetCurrentLine(oBP.Addresses.Count - 1);
oBP.Addresses.AddressName = "Novo 2";
oBP.Addresses.AddressType = BoAddressType.bo_BillTo;
oBP.Addresses.Street = json.data.endereco_logradouro;
oBP.Addresses.Block = json.data.endereco_bairro;
oBP.Addresses.ZipCode = json.data.endereco_cep;
oBP.Addresses.City = json.data.endereco_municipio;
oBP.Addresses.State = UF;
oBP.Addresses.County = county;
oBP.Addresses.StreetNo = json.data.endereco_numero;
oBP.Addresses.BuildingFloorRoom = json.data.endereco_complemento;
oBP.Addresses.Add();
int iRetVal = oBP.Update();
if (iRetVal != 0)
{
Program.oApplication.StatusBar.SetText("Error updating BP: " + Program.oCompany.GetLastErrorDescription(), BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Error);
return false;
}
SAP helped me to solve this issue. The answer follows.
I tried to reproduce this issue in the DemoUK (GB Localization) database and was able to reproduce as well.
After the investigation, it was found that you cannot link a state which does not exist for the specific country.
In your case, the system throws the error because the data is validated based on the following query:
SELECT* FROM OCST WHERE "Code" = 'SP' and "Country" = ''
Similarly, if I will try to set the State as 'Arizona' and Country as 'United Kingdom', it will give me the same error because the correct 'Country' value should be 'USA'.
Therefore, in order to resolve this issue, you need to opt out one of the following:
Set the Country property also in the DI Code (State should belong to the Country which you are trying to set):
oBP.Addresses.Country = "GB"
Remove the State property from the DI Code:
oBP.Addresses.State = "SP"

Reach Child Key Without Knowing Parent's Key Objective-C

I have this data returned from Firebase. In my app, I have a search part in which users can search other users by their nicknames. But I'm retrieving all users and I needed to pass all users to find a wanted nickname. As you can see I'm saving users with their uids which I don't store.
So I need to reach the nickname key without knowing the parent key.
7zsRWD4QraQVJiONdqKLhsn5xI73 = {
followed = (
7zsRWD4QraQVJiONdqKLhsn5xI73,
7zsRWD4QraQVJiONdqKLhsn5xI73,
7zsRWD4QraQVJiONdqKLhsn5xI73,
vexD00nIPsb6MHfuw2w8Wod9fNF3
);
icon = "man.png";
itiraf = (
{
description = Kgkgkkgk;
itirafId = 20191121144558916686058;
title = Mcnckckg;
},
);
nickName = Oykuycj;
};
oLajRgtaRIZktecSXzo4HcZlU252 = {
followed = (
oLajRgtaRIZktecSXzo4HcZlU252,
oLajRgtaRIZktecSXzo4HcZlU252,
oLajRgtaRIZktecSXzo4HcZlU252,
oLajRgtaRIZktecSXzo4HcZlU252
);
icon = "man-4.png";
in = 1;
itiraf = (
{
description = "M\U0131mu";
itirafId = 2019112813101124788975;
title = Kmkm;
}
);
nickName = 5678999;
};
I found the solution by using a for-each loop. I'm saving my data to userDic which is a NSDictionary. Here's my code search key is the wanted nickname and key taking all user ids one by one. So I can reach nicknames without knowing uids.
for (NSString* key in userDic) {
NSString *nick = [userDic[key] objectForKey:#"nickName"];
if([nick isEqualToString:searchKey]){
NSLog(#"user found");
break;
}
}

NSDictionary seems to have multiple values for one key, how do I access the individual values?

I am using ADAL to authenticate to Azure AD, it returns an dictionary with claims, one of the keys is the groups that a user is a member of,
The full dictionary looks like this
2017-06-05 17:40:58.712 NWMobileTill[46676:3282242] userInfoStore Item all {
alg = none;
amr = (
pwd
);
aud = "042a00fc-b832-411f-xxxxxxxx";
exp = xxxxxxx;
groups = (
"xxx-9725-43f6-a502-xxxxx",
"38c5b3af-xxx-4b38-b180-xxxx"
);
iat = xxx;
ipaddr = "xx";
iss = "https://xxxxxxx/xxx-d61d-xxx-a949-0cb72eff23be/";
name = "POS Test";
nbf = xxx;
oid = "c44f91f2-xx-40bb-9624-xxx";
platf = 2;
sub = "xxxxx";
tid = "b5154a9e-xxx-4d55-a949-xxx";
typ = JWT;
"unique_name" = "nwpos#xxxxxx";
upn = "nwpos#xxxx";
ver = "1.0";
}
when I access they values in the NSDIctionary using the objectForKey as below
NSDictionary *jongel = [result.tokenCacheStoreItem.userInformation.allClaims objectForKey:#"groups"];
I get multiple entries like this,
2017-06-05 17:40:58.712 NWMobileTill[46676:3282242] Groups are (
"xx-9725-43f6-a502-xx",
"xx-d0dc-4b38-xx-17555db6f626"
)
I am confused that I can get multiple values, how do I access each individual value? I happen to assign this to an NSDictionary but I don't know if that is right. How can I get to those individual entries?
The groups is an array, so when you do the [objectForKey...] call it returns the data as expected. I would assign the returned object to an NSArray as it should always be returned as from that data model as an array, even if it only contains one element.
If you're more curious you can add a breakpoint in and examine it in a debugger, the [objectForKey...] method does some interesting behaviour around type conversions and sometimes the results may surprise you.

Concise way of updating a nested value inside a record in Elm (0.18)

I am looking for a concise way of updating a nested value inside a record in Elm (0.18).
Given the following example:
person = { name = "Steven", address = { country = "Spain", city = "Barcelona" } }
I can update person.name to "Steve" using the following expression:
{ person | name = "Steve" }
However, I am looking for a way to update a nested value. For instance, I would like to update person.address.city to "Madrid". I tried the following:
{ person | address.city = "Madrid" }
{ person | address = { address | city = "Madrid" } }
{ person | address = { person.address | city = "Madrid" } }
The compiler rejects all these variations. The shortest valid option I see is:
let personAddress = person.address in { person | address = { personAddress | city = "Madrid" } }
This seems to be a bit too much code just to update a nested value, Do you know if there is a better/shorter way of achieving that?
Your last example with the let/in syntax is as concise as is possible in Elm 0.18 without resorting to additional packages.
That being said, in functional languages, you will often find the concept of Lenses useful for updating nested records. There is an Elm package at arturopala/elm-monocle which provide the ability to construct and execute lenses for more concisely getting and setting nested record values.
Using that package, you could build up lenses that would let you do concise things like this:
personWithUpdatedCity = personCity.set "Madrid" person
getCityOfPerson = personCity.get person
The downside is that you have to write all the lens wiring code yourself. In Haskell, this wiring can be done by the compiler. In Elm, we don't have that luxury.
The Elm code needed for the above lenses would be this:
addressCityLens : Lens Address String
addressCityLens =
Lens .city (\cn a -> { a | city = cn })
personAddressLens : Lens Person Address
personAddressLens =
Lens .address (\a p -> { p | address = a })
personCity : Lens Person String
personCity =
compose personAddressLens addressCityLens
As you can see, it's tedious and much more code than you may expect to set a nested value. Due to that tedium, you may want to stick to the let/in example for the time being, unless your code uses nested sets all over the place.
There is an older discussion on the topic of making setting value easier in Elm here, but it hasn't been active for some time.
If I need to do this sort of update a lot, I build a helper
updateAddress : ( Address -> Address ) -> Model -> Model
updateAddress fn m =
{m | address = fn m.address }
and use it, e.g.
updateAddress (\a -> { a | city = Madrid }) model
You can make a function that receives a Person (which is a type alias for { name: String, address: { city: String, country: String }) and a Stringand returns the updated record, like this:
updateCityAdress : Person -> String -> Person
updateCityAddress person newCity =
{ name: person.name, address = { country: person.address.country, city = newCity }
> updateCityAddress person "Madrid"
> { name = "Steven", address = { country = "Spain", city = "Madrid" } }

Linq to Entities convert one entity to similar

I have an Entity model with entities of Person and LogPerson. they are identical except that LogPerson has 2 additional fields (LogPersonID, CreateDate). How can I cast a LogPerson into a Person so that the VB.NET code that follows my Linq code doesn't have to try to work with both possible types?
For example:
dim p as person
If useLog then
p = From a In LogPerson Where ID = x
Else
p = From a In Person Where ID = x
End If
textbox1.text = p.firstname
There aren't any ways out-of-the box. The easiest way without third party tools/libraries is to use the Select method and map the properties manually, like so:
IEnumerable<Person> people = ...;
IEnumerable<LogPerson> logPeople = people.Select(p => new LogPerson {
Name = p.Name,
Age = p.Age,
...
});
Of course, this is tedious, so if you have a large number of fields or a number of places you have to perform this kind of operation, you might want to look into an auto mapping library, such as AutoMapper.
I am WRITING THE SOLUTION IN C#....
person p;
if(uselog)
{
var per = from pobj in LogPerson
where pobj.ID= x
select new person{
firstname = pobj.firstname,
lastname = pobj.lastname,
};
}else
{
var per = from pobj in Person
where pobj.ID= x
select new person{
firstname = pobj.firstname,
lastname = pobj.lastname,
};
}
p = per.first();
}
textbox1.text = p.firstname