Related
I am trying to get the weight for every bone using a gltf json file but i dont know how
here is the json file i am trying to get the weight from:
{
"accessors": [
{
"bufferView": 0,
"componentType": 5126,
"count": 317,
"max": [
10.570027351379395,
15.918471336364746,
6.125584125518799
],
"min": [
-2.611180305480957,
-1.9711413383483887,
-7.055622577667236
],
"type": "VEC3"
},
{
"bufferView": 1,
"componentType": 5126,
"count": 317,
"type": "VEC3"
},
{
"bufferView": 2,
"componentType": 5126,
"count": 317,
"type": "VEC2"
},
{
"bufferView": 3,
"componentType": 5121,
"count": 317,
"type": "VEC4"
},
{
"bufferView": 4,
"componentType": 5126,
"count": 317,
"type": "VEC4"
},
{
"bufferView": 5,
"componentType": 5123,
"count": 768,
"type": "SCALAR"
},
{
"bufferView": 6,
"componentType": 5126,
"count": 5,
"type": "MAT4"
}
],
"asset": {
"generator": "Khronos glTF Blender I/O v1.5.17",
"version": "2.0"
},
"bufferViews": [
{
"buffer": 0,
"byteLength": 3804,
"byteOffset": 0
},
{
"buffer": 0,
"byteLength": 3804,
"byteOffset": 3804
},
{
"buffer": 0,
"byteLength": 2536,
"byteOffset": 7608
},
{
"buffer": 0,
"byteLength": 1268,
"byteOffset": 10144
},
{
"buffer": 0,
"byteLength": 5072,
"byteOffset": 11412
},
{
"buffer": 0,
"byteLength": 1536,
"byteOffset": 16484
},
{
"buffer": 0,
"byteLength": 320,
"byteOffset": 18020
}
],
"buffers": [
{
"byteLength": 18340,
"uri": "manoe.bin"
}
],
"images": [
{
"mimeType": "image/png",
"name": "Material_002_baseColor",
"uri": "Material_002_baseColor.png"
}
],
"materials": [
{
"doubleSided": true,
"name": "Material.001",
"pbrMetallicRoughness": {
"baseColorTexture": {
"index": 0
},
"metallicFactor": 0,
"roughnessFactor": 0.4000000059604645
}
}
],
"meshes": [
{
"name": "Cone.001",
"primitives": [
{
"attributes": {
"JOINTS_0": 3,
"NORMAL": 1,
"POSITION": 0,
"TEXCOORD_0": 2,
"WEIGHTS_0": 4
},
"indices": 5,
"material": 0
}
]
}
],
"nodes": [
{
"name": "Bone.004",
"rotation": [
0.17750653624534607,
-2.8648443617385055e-8,
-0.9102426171302795,
0.37409862875938416
],
"scale": [
1.000000238418579,
1,
1
],
"translation": [
-4.411018750261064e-8,
0.8281745314598083,
1.4894996525072202e-7
]
},
{
"children": [
0
],
"name": "Bone.002",
"rotation": [
0.2184765785932541,
-0.2617807984352112,
-0.7560504078865051,
0.558682918548584
],
"scale": [
1.0000003576278687,
1,
1
],
"translation": [
6.093483762015239e-8,
0.8281747698783875,
-1.283853023892334e-9
]
},
{
"name": "Bone.003",
"rotation": [
-0.4916436970233917,
7.804754176277129e-8,
-0.14189021289348602,
0.8591586947441101
],
"scale": [
1,
1.0000001192092896,
0.9999999403953552
],
"translation": [
-2.4224684125329077e-7,
0.8281750679016113,
-2.68131650216219e-9
]
},
{
"children": [
1,
2
],
"name": "Bone.001",
"rotation": [
-0.11594496667385101,
0.08448944985866547,
-0.5036448836326599,
0.8519155383110046
],
"scale": [
1.000000238418579,
0.9999995827674866,
1
],
"translation": [
-1.357730283757519e-8,
1.0000007152557373,
-3.471412068391244e-14
]
},
{
"children": [
3
],
"name": "Bone",
"rotation": [
2.3709270635663415e-7,
2.8494374859633353e-8,
6.9593789722201e-15,
1
],
"scale": null,
"translation": null
},
{
"mesh": 0,
"name": "Cone.001",
"skin": 0
},
{
"children": [
5,
4
],
"name": "ArmatureBase",
"scale": [
5.400000095367432,
5.400000095367432,
5.400000095367432
]
}
],
"samplers": [
{
"magFilter": 9729,
"minFilter": 9987
}
],
"scene": 0,
"scenes": [
{
"name": "Scene",
"nodes": [
6
]
}
],
"skins": [
{
"inverseBindMatrices": 6,
"joints": [
4,
3,
1,
0,
2
],
"name": "ArmatureBase"
}
],
"textures": [
{
"sampler": 0,
"source": 0
}
]
}
The glTF overview card summarizes it nicely:
Every vertex can be associated with up to 4 joints, each with a given weight.
These are encoded in the components of the JOINTS_0 and WEIGHTS_0 accessors. In your case those are accessors 3 and 4 and bufferviews 3 and 4 with a component type of byte and float, respectively.
One more indirection into the bufferViews component here tells you where in the binary file to look.
I have this grammar:
let lexer = moo.compile({
comment: { match: /[\/\/.*?$|][^\n]+/, value: (s:string) => s.slice(1).trim() },
newline: { match: /[\n]+/, lineBreaks: true }
});
%}
#lexer lexer
main ->
element
| main %newline element
element -> comment
comment -> %comment
Now when I feed nearley the following input: //\n//\n//\n//\n// I get this result:
[
[
[
[
[
[
[
[
{
"type": "comment",
"value": "/",
"text": "//",
"offset": 0,
"lineBreaks": 0,
"line": 1,
"col": 1
}
]
]
],
{
"type": "newline",
"value": "\n",
"text": "\n",
"offset": 2,
"lineBreaks": 1,
"line": 1,
"col": 3
},
[
[
{
"type": "comment",
"value": "/",
"text": "//",
"offset": 3,
"lineBreaks": 0,
"line": 2,
"col": 1
}
]
]
],
{
"type": "newline",
"value": "\n",
"text": "\n",
"offset": 5,
"lineBreaks": 1,
"line": 2,
"col": 3
},
[
[
{
"type": "comment",
"value": "/",
"text": "//",
"offset": 6,
"lineBreaks": 0,
"line": 3,
"col": 1
}
]
]
],
{
"type": "newline",
"value": "\n",
"text": "\n",
"offset": 8,
"lineBreaks": 1,
"line": 3,
"col": 3
},
[
[
{
"type": "comment",
"value": "/",
"text": "//",
"offset": 9,
"lineBreaks": 0,
"line": 4,
"col": 1
}
]
]
],
{
"type": "newline",
"value": "\n",
"text": "\n",
"offset": 11,
"lineBreaks": 1,
"line": 4,
"col": 3
},
[
[
{
"type": "comment",
"value": "/",
"text": "//",
"offset": 12,
"lineBreaks": 0,
"line": 5,
"col": 1
}
]
]
]
]
I dont quite understand why the resulting array is so deeply nested and if theres a way to just have it flat for each elements. Like comments on the same semantic level should be part of one array and not nested.
Okay, so it turns out you have to pass a post-processor to each rule if you don't want them nested in arrays.
For instance like this:
main ->
element {% d => ({ type: "main_element", data: d[0]}) %}
| main %newline element {% d => ({ type: "main_element", data: d[2], main_data: d[0]}) %}
element -> %comment
{% d => ({ type: "element", data: d[0]}) %}
This will result in a flat structure as expected:
[
{
"type": "main_element",
"data": {
"type": "element",
"data": {
"type": "comment",
"value": "/",
"text": "//",
"offset": 12,
"lineBreaks": 0,
"line": 5,
"col": 1
}
},
"main_data": {
"type": "main_element",
"data": {
"type": "element",
"data": {
"type": "comment",
"value": "/",
"text": "//",
"offset": 9,
"lineBreaks": 0,
"line": 4,
"col": 1
}
},
"main_data": {
"type": "main_element",
"data": {
"type": "element",
"data": {
"type": "comment",
"value": "/",
"text": "//",
"offset": 6,
"lineBreaks": 0,
"line": 3,
"col": 1
}
},
"main_data": {
"type": "main_element",
"data": {
"type": "element",
"data": {
"type": "comment",
"value": "/",
"text": "//",
"offset": 3,
"lineBreaks": 0,
"line": 2,
"col": 1
}
},
"main_data": {
"type": "main_element",
"data": {
"type": "element",
"data": {
"type": "comment",
"value": "/",
"text": "//",
"offset": 0,
"lineBreaks": 0,
"line": 1,
"col": 1
}
}
}
}
}
}
}
]
Plot bands in highchart export server is not working properly. I want the output same as shown in jsfiddle below.
I want the color plot band to show on y axis with width 20.
This is expected output: https://jsfiddle.net/vc6r8y3n/
Attached image is actual output when we use high-chart export server.
but when I tried same JavaScript json object on
http://export.highcharts.com/
its giving me image with plot band color spread on whole chart. its not considering width for 'y' or 'x' axis in export server. I gave attached image of export chart.
Why highchart behaving differently in both the cases.
Highchart JSON is same as in JSfiddle.
Actual image.
Expected is what it display in Jsfiddle. https://jsfiddle.net/vc6r8y3n/
{
"chart": {
"height": 350,
"width": 600,
"style": {
"fontFamily": "\"Arial\", sans-serif",
"fontSize": "16px"
},
"backgroundColor": "transparent"
},
"title": {
"text": null
},
"credits": {
"enabled": false
},
"legend": {
"align": "center",
"layout": "horizontal",
"verticalAlign": "bottom",
"symbolHeight": 5,
"symbolWidth": 5,
"symbolRadius": 0,
"itemDistance": 10,
"itemStyle": {
"fontSize": "5px",
"fontWeight": "bold",
"fontFamily": "\"Arial\", sans-serif"
},
"borderWidth": 0,
"padding": 0,
"margin": 5
},
"xAxis": {
"categories": [
"Sep-2020",
"Oct-2020",
"Nov-2020",
"Dec-2020",
"Jan-2021",
"Feb-2021"
],
"labels": {
"style": {
"fontSize": "4px",
"fontFamily": "\"Arial\", sans-serif",
"color": "#000"
},
"y": 5
},
"gridLineColor": "transparent",
"gridLineWidth": 0,
"minorGridLineWidth": 0,
"lineColor": "#9A9A9A",
"zIndex": 9999999
},
"yAxis": [
{
"title": {
"text": ""
},
"min": 0,
"max": 100,
"tickInterval": 20,
"plotBands": [
{
"color": "rgb(204,0,0)",
"from": 0,
"to": 30.99,
"zIndex": 3
},
{
"color": "rgb(226,113,113)",
"from": 31,
"to": 44.99,
"zIndex": 3
},
{
"color": "rgb(247,209,34)",
"from": 45,
"to": 54.99,
"zIndex": 3
},
{
"color": "rgb(136,207,136)",
"from": 55,
"to": 68.99,
"zIndex": 3
},
{
"color": "rgb(68,180,68)",
"from": 69,
"to": 87.99,
"zIndex": 3
},
{
"color": "rgb(0,153,0)",
"from": 88,
"to": 100,
"zIndex": 3
}
],
"width": 20
}
],
"plotOptions": {
"column": {
"dataLabels": {
"enabled": true
}
}
},
"series": [
{
"name": "Line1",
"type": "column",
"data": [
{
"y": 61,
"color": "#5b9bd5"
},
{
"y": 41,
"color": "#5b9bd5"
},
{
"y": 21,
"color": "#5b9bd5"
},
{
"y": 81,
"color": "#5b9bd5"
},
{
"y": 31,
"color": "#5b9bd5"
},
{
"y": 71,
"color": "#5b9bd5"
}
],
"color": "#5b9bd5",
"showInLegend": true
},
{
"name": "Line 2",
"type": "column",
"data": [
null,
null,
null,
null,
null,
1
],
"color": "#00B050"
},
{
"name": "Line 3",
"type": "spline",
"data": [
null,
{
"y": 45
},
{
"y": 38
},
{
"y": 32
},
{
"y": 40
},
{
"y": 48
}
],
"color": "#9A0229"
}
]
}
enter image description here
I am new to Neo4j and want it to connect with Nest.js,I am using neo4j Version 3.5.12 and
following the tutorial.I connect Nest.js and Neo4j by using Graphql but we cannot get the result and show some JSON type and also I try without using Graphql but the GET and POST were not working.
This my controller
import { Controller, Get } from '#nestjs/common';
import {Neo4jService} from './neo4j.service';
#Controller('neo4j')
export class Neo4jController {
constructor (private readonly retriveNodes: Neo4jService){}
#Get()
async findAll() {
console.log('retriving nodes as per given query in findAll() method. ');
//return'Welcome To All';
return this.retriveNodes.findAll();
}
}
Service
import { Injectable, Inject } from '#nestjs/common';
import * as v1 from 'neo4j-driver';
#Injectable()
export class Neo4jService {
constructor(#Inject("Neo4j") private readonly neo4j: v1.Driver) {}
async findAll(): Promise<any> {
return this.neo4j.session().run('MATCH (n:Movie) RETURN n LIMIT 5');
}
}
Using this I get the result in JSON form.
OUTPUT
{
"records": [
{
"keys": [
"n"
],
"length": 1,
"_fields": [
{
"identity": {
"low": 0,
"high": 0
},
"labels": [
"Movie"
],
"properties": {
"title": "The Martix",
"year": {
"low": 1999,
"high": 0
},
"id": "82999192-ae57-406e-8c19-d7753d0d5748"
}
}
],
"_fieldLookup": {
"n": 0
}
},
{
"keys": [
"n"
],
"length": 1,
"_fields": [
{
"identity": {
"low": 1,
"high": 0
},
"labels": [
"Movie"
],
"properties": {
"title": "A Few Good Men",
"year": {
"low": 1992,
"high": 0
},
"id": "c52c721c-c410-45a2-8d2e-824caa51847a"
}
}
],
"_fieldLookup": {
"n": 0
}
},
{
"keys": [
"n"
],
"length": 1,
"_fields": [
{
"identity": {
"low": 2,
"high": 0
},
"labels": [
"Movie"
],
"properties": {
"title": "Top Gun",
"year": {
"low": 1986,
"high": 0
},
"id": "d121663a-597f-4963-8acc-c68021bee860"
}
}
],
"_fieldLookup": {
"n": 0
}
},
{
"keys": [
"n"
],
"length": 1,
"_fields": [
{
"identity": {
"low": 17,
"high": 0
},
"labels": [
"Movie"
],
"properties": {
"title": "The Martix",
"year": {
"low": 1999,
"high": 0
},
"id": "453941ca-c309-419b-8cad-41d150e06b2a"
}
}
],
"_fieldLookup": {
"n": 0
}
},
{
"keys": [
"n"
],
"length": 1,
"_fields": [
{
"identity": {
"low": 18,
"high": 0
},
"labels": [
"Movie"
],
"properties": {
"title": "A Few Good Men",
"year": {
"low": 1992,
"high": 0
},
"id": "79fc529c-bfd1-4f7d-9bae-7f00b6d7d540"
}
}
],
"_fieldLookup": {
"n": 0
}
}
],
"summary": {
"query": {
"text": "MATCH (n:Movie) RETURN n LIMIT 5",
"parameters": {
}
},
"queryType": "r",
"counters": {
"_stats": {
"nodesCreated": 0,
"nodesDeleted": 0,
"relationshipsCreated": 0,
"relationshipsDeleted": 0,
"propertiesSet": 0,
"labelsAdded": 0,
"labelsRemoved": 0,
"indexesAdded": 0,
"indexesRemoved": 0,
"constraintsAdded": 0,
"constraintsRemoved": 0
},
"_systemUpdates": 0
},
"updateStatistics": {
"_stats": {
"nodesCreated": 0,
"nodesDeleted": 0,
"relationshipsCreated": 0,
"relationshipsDeleted": 0,
"propertiesSet": 0,
"labelsAdded": 0,
"labelsRemoved": 0,
"indexesAdded": 0,
"indexesRemoved": 0,
"constraintsAdded": 0,
"constraintsRemoved": 0
},
"_systemUpdates": 0
},
"plan": false,
"profile": false,
"notifications": [
],
"server": {
"address": "localhost:7687",
"version": "Neo4j/3.5.12"
},
"resultConsumedAfter": {
"low": 191,
"high": 0
},
"resultAvailableAfter": {
"low": 437,
"high": 0
},
"database": {
"name": null
}
}
}
I want both .run and .then but in here only .run is showing .No sugection is showing i want field,properties and id in above code.
I'm trying to remove the Optional text on my UILabel when I run the app. However, I already tried many ways and the Optional persists.
It's important to say that I got these values from JSON, so I created a Struct to decode all this Data. The property ibu is the only one that has Optional written, but if I remove the ? I got an error on JSONDecoder that say's:
Swift.DecodingError.Context(codingPath: [_JSONKey(stringValue: "Index
23", intValue: 23), CodingKeys(stringValue: "ibu", intValue: nil)],
debugDescription: "Expected Double value but found null instead.",
underlyingError: nil))
How do I fix that?
App Picture:
Model Folder:
struct Cerveja:Decodable{
let name:String
let image_url:String
let description:String
let tagline:String
let abv:Double
let ibu:Double? //This one that I got the "Optional" written in the UILabel
//If I remove the "?" I got the error below
}
View Folder - Details Screen:
var item:Cerveja?
override func viewDidLoad() {
super.viewDidLoad()
labelName.text = item?.name
labelDescricao.text = item?.description
labelAmargor.text = "\(String(describing: item!.ibu))"
labelTeorAlc.text = "\(item!.abv)"
let resource = ImageResource(downloadURL: URL(string: "\(item?.image_url ?? "")")!, cacheKey: item?.image_url)
imageDetail.kf.setImage(with: resource)
}
Networking Folder:
func getApiData(completion: #escaping ([Cerveja]) -> ()){
guard let urlString = URL(string: "https://api.punkapi.com/v2/beers") else {
print("URL Error")
return
}
Alamofire.request(urlString).responseJSON { response in
if response.data == response.data{
do{
let decoder = try JSONDecoder().decode([Cerveja].self, from: response.data!)
completion(decoder)
}catch{
print(error)
}
}else{print("API Response is Empty")}
}
}
JSON:
[
{
"id": 1,
"name": "Buzz",
"tagline": "A Real Bitter Experience.",
"first_brewed": "09\/2007",
"description": "A light, crisp and bitter IPA brewed with English and American hops. A small batch brewed only once.",
"image_url": "https:\/\/images.punkapi.com\/v2\/keg.png",
"abv": 4.5,
"ibu": 60,
"target_fg": 1010,
"target_og": 1044,
"ebc": 20,
"srm": 10,
"ph": 4.4,
"attenuation_level": 75,
"volume": {
"value": 20,
"unit": "liters"
},
"boil_volume": {
"value": 25,
"unit": "liters"
},
"method": {
"mash_temp": [
{
"temp": {
"value": 64,
"unit": "celsius"
},
"duration": 75
}
],
"fermentation": {
"temp": {
"value": 19,
"unit": "celsius"
}
},
"twist": null
},
"ingredients": {
"malt": [
{
"name": "Maris Otter Extra Pale",
"amount": {
"value": 3.3,
"unit": "kilograms"
}
},
{
"name": "Caramalt",
"amount": {
"value": 0.2,
"unit": "kilograms"
}
},
{
"name": "Munich",
"amount": {
"value": 0.4,
"unit": "kilograms"
}
}
],
"hops": [
{
"name": "Fuggles",
"amount": {
"value": 25,
"unit": "grams"
},
"add": "start",
"attribute": "bitter"
},
{
"name": "First Gold",
"amount": {
"value": 25,
"unit": "grams"
},
"add": "start",
"attribute": "bitter"
},
{
"name": "Fuggles",
"amount": {
"value": 37.5,
"unit": "grams"
},
"add": "middle",
"attribute": "flavour"
},
{
"name": "First Gold",
"amount": {
"value": 37.5,
"unit": "grams"
},
"add": "middle",
"attribute": "flavour"
},
{
"name": "Cascade",
"amount": {
"value": 37.5,
"unit": "grams"
},
"add": "end",
"attribute": "flavour"
}
],
"yeast": "Wyeast 1056 - American Ale\u2122"
},
"food_pairing": [
"Spicy chicken tikka masala",
"Grilled chicken quesadilla",
"Caramel toffee cake"
],
"brewers_tips": "The earthy and floral aromas from the hops can be overpowering. Drop a little Cascade in at the end of the boil to lift the profile with a bit of citrus.",
"contributed_by": "Sam Mason <samjbmason>"
},
{
"id": 2,
"name": "Trashy Blonde",
"tagline": "You Know You Shouldn't",
"first_brewed": "04\/2008",
"description": "A titillating, neurotic, peroxide punk of a Pale Ale. Combining attitude, style, substance, and a little bit of low self esteem for good measure; what would your mother say? The seductive lure of the sassy passion fruit hop proves too much to resist. All that is even before we get onto the fact that there are no additives, preservatives, pasteurization or strings attached. All wrapped up with the customary BrewDog bite and imaginative twist.",
"image_url": "https:\/\/images.punkapi.com\/v2\/2.png",
"abv": 4.1,
"ibu": 41.5,
"target_fg": 1010,
"target_og": 1041.7,
"ebc": 15,
"srm": 15,
"ph": 4.4,
"attenuation_level": 76,
"volume": {
"value": 20,
"unit": "liters"
},
"boil_volume": {
"value": 25,
"unit": "liters"
},
"method": {
"mash_temp": [
{
"temp": {
"value": 69,
"unit": "celsius"
},
"duration": null
}
],
"fermentation": {
"temp": {
"value": 18,
"unit": "celsius"
}
},
"twist": null
},
"ingredients": {
"malt": [
{
"name": "Maris Otter Extra Pale",
"amount": {
"value": 3.25,
"unit": "kilograms"
}
},
{
"name": "Caramalt",
"amount": {
"value": 0.2,
"unit": "kilograms"
}
},
{
"name": "Munich",
"amount": {
"value": 0.4,
"unit": "kilograms"
}
}
],
"hops": [
{
"name": "Amarillo",
"amount": {
"value": 13.8,
"unit": "grams"
},
"add": "start",
"attribute": "bitter"
},
{
"name": "Simcoe",
"amount": {
"value": 13.8,
"unit": "grams"
},
"add": "start",
"attribute": "bitter"
},
{
"name": "Amarillo",
"amount": {
"value": 26.3,
"unit": "grams"
},
"add": "end",
"attribute": "flavour"
},
{
"name": "Motueka",
"amount": {
"value": 18.8,
"unit": "grams"
},
"add": "end",
"attribute": "flavour"
}
],
"yeast": "Wyeast 1056 - American Ale\u2122"
},
"food_pairing": [
"Fresh crab with lemon",
"Garlic butter dipping sauce",
"Goats cheese salad",
"Creamy lemon bar doused in powdered sugar"
],
"brewers_tips": "Be careful not to collect too much wort from the mash. Once the sugars are all washed out there are some very unpleasant grainy tasting compounds that can be extracted into the wort.",
"contributed_by": "Sam Mason <samjbmason>"
},
{
"id": 3,
"name": "Berliner Weisse With Yuzu - B-Sides",
"tagline": "Japanese Citrus Berliner Weisse.",
"first_brewed": "11\/2015",
"description": "Japanese citrus fruit intensifies the sour nature of this German classic.",
"image_url": "https:\/\/images.punkapi.com\/v2\/keg.png",
"abv": 4.2,
"ibu": 8,
"target_fg": 1007,
"target_og": 1040,
"ebc": 8,
"srm": 4,
"ph": 3.2,
"attenuation_level": 83,
"volume": {
"value": 20,
"unit": "liters"
},
"boil_volume": {
"value": 25,
"unit": "liters"
},
"method": {
"mash_temp": [
{
"temp": {
"value": 60,
"unit": "celsius"
},
"duration": 10
},
{
"temp": {
"value": 65,
"unit": "celsius"
},
"duration": 30
},
{
"temp": {
"value": 72,
"unit": "celsius"
},
"duration": 10
},
{
"temp": {
"value": 78,
"unit": "celsius"
},
"duration": 5
}
],
"fermentation": {
"temp": {
"value": 21,
"unit": "celsius"
}
},
"twist": "Soured naturally using the kettle souring technique, Yuzu fruit: 50g at middle, Yuzu juice: 200ml at FV"
},
"ingredients": {
"malt": [
{
"name": "Propino Pale Malt",
"amount": {
"value": 1.63,
"unit": "kilograms"
}
},
{
"name": "Wheat Malt",
"amount": {
"value": 1.63,
"unit": "kilograms"
}
},
{
"name": "Propino Pale Malt for kettle 0.03kg souring",
"amount": {
"value": 0.03,
"unit": "kilograms"
}
},
{
"name": "Acidulated Malt for kettle souring",
"amount": {
"value": 0.03,
"unit": "kilograms"
}
}
],
"hops": [
{
"name": "Bramling Cross",
"amount": {
"value": 10,
"unit": "grams"
},
"add": "middle",
"attribute": "bitter"
}
],
"yeast": "Wyeast 1056 - American Ale\u2122"
}
Use optional binding to avoid this problem
Use
if let ibu = item?.ibu {
labelAmargor.text = "\(String(describing: ibu))"
}
Instead of
labelAmargor.text = "\(String(describing: item!.ibu))"
I would recommend Nil-Coalescing Operator ( ?? ). You can find detailed info here
class Test {
var ibu: Double?
}
var tt: Test? = Test()
tt?.ibu = 3.14
print(String(describing: tt?.ibu)) // Optional("3.14")
print(tt?.ibu ?? 0) // 3.14
tt?.ibu = nil
print(String(describing: tt?.ibu)) // nil
print(tt?.ibu ?? 0) // 0