how to declare a dictionary inside two arrays - swift

How can I declare a multi array outside its function so i can use it outside its function? I know how to do a regular array and a regular dictionary, but not both.
IhelpersCoordinates = [
[
"Latitude":IhelpersLatitude,
"Longitude": IhelpersLongitude,
"userId": IhelpersUid
]
]
The code above is in the viewDidLoad. I'm trying to use it in the user did update function. I know with a regular array i have to set the array outside of the function (example- var IhelpersCordinates = []). I'm trying to figure out how i would do the same with the array above.

As I understand your problem correctly you can declare a dictionary inside array use [[String:Double]].
class YourClass {
var IhelpersCoordinates : [[String:Double]] = [
[
"Latitude": 53.02,
"Longitude": 19.04,
"userId": 123
],
[
"Latitude": 51.02,
"Longitude": 20.04,
"userId": 124
],
]
func exampleFunc(){
print(IhelpersCoordinates[0]["Latitude"]) // this will print 53.02
print(IhelpersCoordinates.count) // this will print 2, because it's 2 elements array of dictionaries.
}
}
Edited base on comment
If you want to declare an dictionary inside an array inside an array try this code :
class YourClass {
var IhelpersCoordinates : Array<Array<[String:Double]>> = [
[
[
"Latitude": 53.02,
"Longitude": 19.04,
"userId": 123
],
],
[
[
"Latitude": 53.02,
"Longitude": 19.04,
"userId": 123
],
],
]
func exampleFunc(){
print(IhelpersCoordinates[0][0]["Latitude"])
print(IhelpersCoordinates.count)
}
}
EDIT 2
class YourClass {
public var IhelpersCoordinates = Array<Array<[String:Double]>>()
func calculate() {
var element = [
[
"Latitude": 53.02,
"Longitude": 19.04,
"userId": 123
]
]
var element1 = [
[
"Latitude": 54.02,
"Longitude": 19.04,
"userId": 122
]
]
self.IhelpersCoordinates.append(element)
self.IhelpersCoordinates.append(element1)
}
func printValues() {
print(self.IhelpersCoordinates.count)
}
}
Hope it help you

Related

Read JSON in ADF

In Azure Data Factory, I need to be able to process a JSON response. I don't want to hardcode the array position in case they change, so something like this is out of the question:
#activity('Place Details').output.result.components[2].name
How can I get the name 123 where types = number given a JSON array like below:
"result": {
"components": [
{
"name": "ABC",
"types": [
"alphabet"
]
},
{
"name": "123",
"types": [
"number"
]
}
]
}
One example using the OPENJSON method:
DECLARE #json NVARCHAR(MAX) = '{
"result": {
"components": [
{
"name": "ABC",
"types": [
"alphabet"
]
},
{
"name": "123",
"types": [
"number"
]
}
]
}
}'
;WITH cte AS (
SELECT
JSON_VALUE( o.[value], '$.name' ) [name],
JSON_VALUE( o.[value], '$.types[0]' ) [types]
FROM OPENJSON( #json, '$.result.components' ) o
)
SELECT [name]
FROM cte
WHERE types = 'number'
I will have a look at other methods.

PTV Developer Routing API OpeningInterval is not applied

Im trying to calculate a route from Berlin to Rome using the Routing API with an openingInterval specified for the waypoint in Rome.
The openingInterval is not used, instead I’m getting a route violation for the openingInterval.
My request:
https://api.myptv.com/routing/v1/routes?options[trafficMode]=AVERAGE&options[startTime]=2022-01-25T13:00:00&results=VIOLATION_EVENTS,SCHEDULE_EVENTS
Body:
{
"waypoints": [
{
"offRoad": {
"latitude": 52.461790,
"longitude": 13.324184
}
},
{
"offRoad": {
"latitude": 41.889511,
"longitude": 12.381591,
"openingIntervals": [
{
"start": "2022-01-25T10:00:00",
"end": "2022-01-25T20:00:00"
}
]
}
}
]
}
I get the following response:
{
"distance": 1508861,
"travelTime": 68832,
"violated": true,
"events": [
{
"latitude": 52.461790044,
"longitude": 13.324184073,
"startsAt": "2022-01-25T13:00:00+01:00",
"distanceFromStart": 0,
"travelTimeFromStart": 0,
"countryCode": "DE",
"utcOffset": 60,
"schedule": {
"duration": 0,
"scheduleTypes": [
"SERVICE"
]
}
},
{
"latitude": 41.889511025,
"longitude": 12.381590967,
"startsAt": "2022-01-26T08:07:12+01:00",
"distanceFromStart": 1508861,
"travelTimeFromStart": 68832,
"countryCode": "IT",
"utcOffset": 60,
"violation": {
"type": "SCHEDULE",
"scheduleViolationTypes": [
"OPENING_INTERVAL"
]
},
"schedule": {
"duration": 0,
"scheduleTypes": [
"SERVICE"
]
}
}
]
}
The routing should arrive at around 7am in Rome and have to wait there for the openingInterval, but instead the route finishes without waiting.
What am I doing wrong?
While all waypoints are always open per default as soon as you set openingIntervals the waypoint will only be open during these intervals and closed otherwise.
In your case you are arriving on the next day since your route is quite long, while your openingInterval is specified for the same day.
If you don’t know if you will arrive on the same day you started the route, I suggest adding the openingInterval for the next day as well, like this:
{
"waypoints": [
{
"offRoad": {
"latitude": 52.461790,
"longitude": 13.324184
}
},
{
"offRoad": {
"latitude": 41.889511,
"longitude": 12.381591,
"openingIntervals": [
{
"start": "2021-01-25T10:00:00",
"end": "2021-01-25T20:00:00"
},
{
"start": "2021-01-26T10:00:00",
"end": "2021-01-26T20:00:00"
}
]
}
}
]
}

Filtering by Gender on targeting_spec

How to set the gender in Facebook Marketing API targetting spec?
I've tried setting the gender but i'm getting gender is not a valid target spec field error.
targeting_spec = {"geo_locations":
{
"location_types": ["recent"],
"custom_locations": [
{
"latitude": 14.5764,
"longitude": 121.0851,
"radius": 17
}
]
},
"age_min": 18,
"age_max": 35,
"gender": "male", // Setting gender, doesn't work
"flexible_spec": [
{
"interests": [
{"id": "6002998074973", "name": "BTS"}
]
},
{
"interests": [
{"id": "6005882720291", "name": "Data Science"}
]
}
]
}
Found it! It should be genders.
The values are:
gender: [0] # All
gender: [1] # Men
gender: [2] # Women
From https://developers.facebook.com/docs/marketing-api/buying-api/targeting/:
genders: array
1=male
2=female.
Defaults to all.
For example:
targeting: {
genders: [1]
...

Contextual type 'Any' cannot be used with dictionary literal

I'm getting that error, I'm new to swift and I would like to create a json out of the ARKit
let jsonObject: [String: Any] = [
"imageName": imageName,
"timeStamp": currentFrame.timestamp,
"cameraPos": dictFromVector3(positionFromTransform(currentFrame.camera.transform)),
"cameraEulerAngle": dictFromVector3(currentFrame.camera.eulerAngles),
"cameraTransform": arrayFromTransform(currentFrame.camera.transform),
"cameraIntrinsics": arrayFromTransform(currentFrame.camera.intrinsics),
"imageResolution": [
"width": currentFrame.camera.imageResolution.width,
"height": currentFrame.camera.imageResolution.height
],
"lightEstimate": currentFrame.lightEstimate?.ambientIntensity,
"ARPointCloud": [
"count": currentFrame.rawFeaturePoints?.count,
"points": arrayFromPointCloud(currentFrame.rawFeaturePoints)
]
]

How to Parse json data having array in IONIC hybrid appliaction

I am beginner in hybrid Ionic App Development. I want to implement RESTful web service in my project.
My json Data is:
{
"records": [
{
"Name": "Alfreds Futterkiste",
"City": "Berlin",
"Country": "Germany"
},
{
"Name": "Ana Trujillo Emparedados y helados",
"City": "México D.F.",
"Country": "Mexico"
},
{
"Name": "Antonio Moreno Taquería",
"City": "México D.F.",
"Country": "Mexico"
}]
}
Here i want to Parse this Data in Listview in ionic. I don't no how to parse data with array.Please suggest the solution or tutorials to get result.I want to show all Names in Listview.
I am using this api link: http://api.geonames.org/earthquakesJSON?north=44.1&south=-9.9&east=-22.4&west=55.2&username=bertt
thanks in advance.
Here you no need to parse the JSON data, it is already in object format.
You can use like this
var myData = {
"records": [
{
"Name": "Alfreds Futterkiste",
"City": "Berlin",
"Country": "Germany"
},
{
"Name": "Ana Trujillo Emparedados y helados",
"City": "México D.F.",
"Country": "Mexico"
},
{
"Name": "Antonio Moreno Taquería",
"City": "México D.F.",
"Country": "Mexico"
}]
}
var record1 = myData.records[0];
var record2 = myData.records[1];
var record3 = myData.records[2];
console.log(record1)
console.log(record2)
console.log(record3)
console.log("Record 1 Data:")
console.log('\t'+"Name: "+record1.Name)
console.log('\t'+"City: "+record1.City)
console.log('\t'+"Country: "+record1.Country)
console.log("Record 2 Data:")
console.log('\t'+"Name: "+record2.Name)
console.log('\t'+"City: "+record2.City)
console.log('\t'+"Country: "+record2.Country)
console.log("Record 3 Data:")
console.log('\t'+"Name: "+record3.Name)
console.log('\t'+"City: "+record3.City)
console.log('\t'+"Country: "+record3.Country)