How can I show and hide labels? - swift

I have 4 labels (dayString1, dayString2, dayString3 and dayString4) in which they will put a numerical value and what I need to do is that if the content of dayString1 is less than 60 than the dayString2 appears, and if the sum of dayString1 + dayString2 is less than 60 the dayString3 appears and so on; My logic was this, but it gives error:
(Ambiguous reference to operator function '<')
func chooseDays() {
self.dayString = dayTextField.text!
self.dayString2 = dayTextField2.text!
self.dayString3 = dayTextField3.text!
self.dayString4 = dayTextField4.text!
if dayString < 60 {
self.dateTextField2.isHidden = false
self.dayTextField2.isHidden = false
self.dateTextField3.isHidden = true
self.dayTextField3.isHidden = true
self.dateTextField4.isHidden = true
self.dayTextField4.isHidden = true
SearchConstraint.constant = 72
if dayString + dayString2 < 60 {
self.dateTextField2.isHidden = false
self.dayTextField2.isHidden = false
self.dateTextField3.isHidden = false
self.dayTextField3.isHidden = false
self.dateTextField4.isHidden = true
self.dayTextField4.isHidden = true
SearchConstraint.constant = 112
if dayString + dayString2 + dayString3 < 60 {
self.dateTextField2.isHidden = false
self.dayTextField2.isHidden = false
self.dateTextField3.isHidden = false
self.dayTextField3.isHidden = false
self.dateTextField4.isHidden = false
self.dayTextField4.isHidden = false
SearchConstraint.constant = 152
}
}
}
return
}

You need to type caste string to integer before performing any comparison with another integer like this:
if Int(dayString) < 60 {
Also do nil coalescing technique to handle unwrapping of texts from textfields:
self.dayString = dayTextField.text ?? "0"
self.dayString2 = dayTextField2.text ?? "0"
self.dayString3 = dayTextField3.text ?? "0"
self.dayString4 = dayTextField4.text ?? "0"

Related

I am not able to load this chart in whirglobeMap throght MBTile from which given below

for path in paths{
if let tileSource = MaplyMBTileSource(mbTiles: Constant.path.hiPath() + "/" + path){
print("Tittle layer ",tileSource)
// set up the layer
let layer = MaplyQuadImageTilesLayer(coordSystem: tileSource.coordSys, tileSource: tileSource)
layer!.handleEdges = true
layer!.coverPoles = true
layer!.requireElev = false
layer!.waitLoad = false
layer!.drawPriority = kMaplyImageLayerDrawPriorityDefault+60
layer!.singleLevelLoading = false
globeMap.add(layer!)
selectedChartLayer.append(layer!)
}
MBTile Link:- https://drive.google.com/file/d/12rupa4ZPykmFMNuaqcz9Aa1vWfoJniBH/view?usp=sharing

GTLRSheets_Color not holding value

I am trying to set a value for "background color" as seen below but when I print the value after setting it, it simply shows nil? This makes absolutely no sense. Please help, I have exhausted all resources already.
Thank you.
let request = GTLRSheets_Request.init()
request.repeatCell = GTLRSheets_RepeatCellRequest.init()
let colbox = GTLRSheets_GridRange.init()
colbox.startRowIndex = rowstart
colbox.endRowIndex = rowend
colbox.startColumnIndex = columnstart
colbox.endColumnIndex = columnend
request.repeatCell?.range = colbox
let color = GTLRSheets_Color.init()
color.blue = 60
color.red = 47
color.green = 77
request.repeatCell?.cell?.userEnteredFormat?.backgroundColor = color
request.repeatCell?.cell?.userEnteredFormat?.textFormat?.bold = true
request.repeatCell?.cell?.userEnteredFormat?.horizontalAlignment = "CENTER"
request.repeatCell?.fields = "userEnteredFormat(backgroundColor,textFormat,horizontalAlignment)"
print(request.repeatCell?.cell?.userEnteredFormat?.backgroundColor)
let batchUpdate = GTLRSheets_BatchUpdateSpreadsheetRequest.init()
batchUpdate.requests = [request]
let createQuery = GTLRSheetsQuery_SpreadsheetsBatchUpdate.query(withObject: batchUpdate, spreadsheetId: spreadsheetId)
service.executeQuery(createQuery) { (ticket, result, NSError) in
}
Issue:
You should initialize cell and userEnteredFormat.
Solution:
cell refers to an instance of GTLRSheets_CellData, and should be initialized the following way:
request.repeatCell?.cell = GTLRSheets_CellData.init()
userEnteredFormat refers to an instance of GTLRSheets_CellFormat:
request.repeatCell?.cell?.userEnteredFormat = GTLRSheets_CellFormat.init()
Reference:
GTLRSheets_CellData
GTLRSheets_CellFormat
Swift: Initialization

How can I enable decimals in my chart in Swift?

I am using Charts to create my own charts but I am struggling to see the values of my table with decimals instead of just integers.
My chart init is like below, but I cannot find the way to format the points to show the decimal parts since they are doubles. I have tried to set targetChartView.xAxis.decimals and targetChartView.leftAxis.decimals without result.
How can I enable the decimal notation?
init(withGraphView aGraphView: LineChartView, noDataText aNoDataTextString: String, minValue aMinValue: Double, maxValue aMaxValue: Double, numberOfDataSets aDataSetCount: Int, dataSetNames aDataSetNameList: [String], dataSetColors aColorSet: [UIColor], andMaxVisibleEntries maxEntries: Int = 10) {
originalMaxValue = aMaxValue
originalMinValue = aMinValue
dateFormatter = DateFormatter()
targetChartView = aGraphView
lineChartData = LineChartData()
maximumVisiblePoints = maxEntries
timestamps = [Date]()
for i in 0..<aDataSetCount {
let firstEntry = ChartDataEntry(x: 0, y: 0)
var entries = [ChartDataEntry]()
entries.append(firstEntry)
let aDataSet = LineChartDataSet(values: entries, label: aDataSetNameList[i])
aDataSet.setColor(aColorSet[i])
aDataSet.lineWidth = 3
aDataSet.lineCapType = .round
aDataSet.drawCircleHoleEnabled = false
aDataSet.circleRadius = 2
aDataSet.axisDependency = .left
aDataSet.highlightEnabled = true
lineChartData.addDataSet(aDataSet)
}
targetChartView.data = lineChartData
targetChartView.noDataText = aNoDataTextString
targetChartView.chartDescription?.text = ""
targetChartView.rightAxis.drawLabelsEnabled = false
targetChartView.xAxis.drawGridLinesEnabled = false
targetChartView.xAxis.labelPosition = .bottom
targetChartView.leftAxis.drawGridLinesEnabled = false
targetChartView.dragEnabled = true
targetChartView.xAxis.granularityEnabled = true
targetChartView.xAxis.granularity = 1
targetChartView.xAxis.decimals = 0
targetChartView.leftAxis.granularityEnabled = true
targetChartView.leftAxis.granularity = 1
targetChartView.leftAxis.decimals = 0
targetChartView.xAxis.axisMinimum = Double(0)
targetChartView.xAxis.axisMaximum = Double(maximumVisiblePoints)
targetChartView.leftAxis.axisMinimum = aMinValue
targetChartView.leftAxis.axisMaximum = aMaxValue
targetChartView.setScaleEnabled(false)
super.init()
targetChartView.xAxis.valueFormatter = self
targetChartView.delegate = self
// This gesture recognizer will track begin and end of touch/swipe.
// When user presses the graph we don't want it to be moving when new data is received even when the most recent value is visible.
let clickRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(didLongPress))
clickRecognizer.minimumPressDuration = 0
clickRecognizer.delegate = self
targetChartView.addGestureRecognizer(clickRecognizer)
}
The decimals property is used only if you are using the default formatter. However, I see that you are also setting
targetChartView.xAxis.valueFormatter = self
That means your class is implementing IAxisValueFormatter and its stringForValue(:axis:) method. The value in decimals (which should be nonzero) is then ignored because you have a custom formatter.
You can either remove the assignment and then your decimals should be displayed or, you will have to format your decimals correctly in stringForValue(:axis:).
You have not added this part of your implementation but the problem is probably there.
I see there is also some magic in the AxisRenderer that will probably remove decimals if the interval between values is bigger than 1. Therefore using a custom formatter for both axes is probably the best solution.
As I mentioned to #Sulthan, the issue was not in the chart itself but how the data set (aDataSet) had to be formatted, so adding the snippet below enabled three decimals on my data in the graph
init(withGraphView aGraphView: LineChartView, noDataText aNoDataTextString: String, minValue aMinValue: Double, maxValue aMaxValue: Double, numberOfDataSets aDataSetCount: Int, dataSetNames aDataSetNameList: [String], dataSetColors aColorSet: [UIColor], andMaxVisibleEntries maxEntries: Int = 10) {
originalMaxValue = aMaxValue
originalMinValue = aMinValue
dateFormatter = DateFormatter()
targetChartView = aGraphView
lineChartData = LineChartData()
maximumVisiblePoints = maxEntries
timestamps = [Date]()
//Setting 3 decimals for the number that are going to be displayed
let formatter = NumberFormatter()//ADD THIS
formatter.numberStyle = .decimal//ADD THIS
formatter.maximumFractionDigits = 3//ADD THIS
formatter.minimumFractionDigits = 3//ADD THIS
for i in 0..<aDataSetCount {
let firstEntry = ChartDataEntry(x: 0, y: 0)
var entries = [ChartDataEntry]()
entries.append(firstEntry)
let aDataSet = LineChartDataSet(values: entries, label: aDataSetNameList[i])
aDataSet.setColor(aColorSet[i])
aDataSet.lineWidth = 3
aDataSet.lineCapType = .round
aDataSet.drawCircleHoleEnabled = false
aDataSet.circleRadius = 2
aDataSet.axisDependency = .left
aDataSet.highlightEnabled = true
lineChartData.addDataSet(aDataSet)
//Use formater that allows showing decimals
lineChartData.setValueFormatter(DefaultValueFormatter(formatter: formatter))//ADD THIS
}
...}

display the value of bool in swift

I would like to print the result of the bool value
When I do it I have "true" instead the amount.
I know it probably sounds really stupid but I'm just getting started with swift
var monthsWeek:Int?
var hoursWageHours:Double = 14.47
let months4WeeksHours:Double = 156.00
let months5WeeksHours:Double = 195.00
var normalpay:Double = 0
let months5weeks:Bool = true
let months4weeks:Bool = true
if months5weeks {
normalpay = hoursWageHours * months5WeeksHours
if months4weeks {
normalpay = hoursWageHours * months4WeeksHours
}
}
or woud that make more sence even if didnt print the result still
var monthsWeek:Int?
var hoursWageHours:Double = 14.47
let months4WeeksHours:Double = 156.00
let months5WeeksHours:Double = 195.00
var normalpay:Double = 0
if monthsWeek == 195 {
normalpay = hoursWageHours * months5WeeksHours
if monthsWeek == 4 {
normalpay = hoursWageHours * months4WeeksHours
}
}
monthsWeek = 4
I came here looking for an actual print of a bool. It turns out you can do this:
var a_bool = false
print("a_bool is ")
println(a_bool)
And you can do this with ints:
var a_int = 42
println("This is an int " + String(a_int))
You can't do this with bools though. However you can do:
println("This is a bool " + String(stringInterpolationSegment: a_bool))
This is the closet I can come up with for something like this:
println("a_bool is ", a_bool) // does not work
println("a_bool is " + a_bool) // also does not work
Later on, I learned you can use \(variable) embedding like this:
println("This is an int \(a_int)")
A boolean variable can take only 2 values (true or false).
So it is logical that when you print it you have true or false.

Crystal Reports Leaving out parameter

I have a crystal report that I am modifying the record selection formula. I have a parameter "Inventory_Class" that can have 3 values 0, 1 or 2. If set to 1 I want my DB field "NON_Controllable" that is binary field to select all False records, if the parameter is set to 2 then I want all True records but if the incoming parameter is set to 0 then I don't want to filter on the DB field "NON_Controllable" at all. I can get formula to work when parameter is set to 1 and 2 selecting Non_Controllable false and true records but when the parameter is set to 0 my report returns no records when it should be returning all records.
{Inventory_Catalog.PROP_NO} = {?PROPERTY} and
{Inventory_Cat_Header.INVEN_TYPE_CD} = {?TYPE} and
{Inventory_Cat_Header.OPER_BUS_SEG_CD} = {?OPER_BUS_SEG} and
{Inventory_Catalog.SURP} = {?SURP} and
{Inventory_Catalog.COND_CD} = {?CONDITION} and
{Inventory_Cat_Header.INVEN_ID} = {?INVEN_ID} and
{Inventory_Catalog.SER_NO} = {?SERIAL} and
{Inventory_Cat_Header.BUS_UNIT_CD} = {?BUS_UNIT_CD} and
IF ({?INVENTORY_CLASS} = 1) THEN
{Inventory_Cat_Header.NON_CONTROLLABLE} = FALSE
ELSE IF ({?INVENTORY_CLASS} = 2) THEN
{Inventory_Cat_Header.NON_CONTROLLABLE} = TRUE
ELSE IF ({?INVENTORY_CLASS} = 0) THEN
NOT {Inventory_Cat_Header.NON_CONTROLLABLE}
How can I modify this formula to work?
you can try passing the parameters for each conditions instead.
IF
({?INVENTORY_CLASS} = 1) THEN
{Inventory_Cat_Header.NON_CONTROLLABLE} = FALSE and
{Inventory_Catalog.PROP_NO} = {?PROPERTY} and
{Inventory_Cat_Header.INVEN_TYPE_CD} = {?TYPE} and
{Inventory_Cat_Header.OPER_BUS_SEG_CD} = {?OPER_BUS_SEG} and
{Inventory_Catalog.SURP} = {?SURP} and
{Inventory_Catalog.COND_CD} = {?CONDITION} and
{Inventory_Cat_Header.INVEN_ID} = {?INVEN_ID} and
{Inventory_Catalog.SER_NO} = {?SERIAL} and
{Inventory_Cat_Header.BUS_UNIT_CD} = {?BUS_UNIT_CD}
ELSE IF
({?INVENTORY_CLASS} = 2) THEN
{Inventory_Cat_Header.NON_CONTROLLABLE} = TRUE and
{Inventory_Catalog.PROP_NO} = {?PROPERTY} and
{Inventory_Cat_Header.INVEN_TYPE_CD} = {?TYPE} and
{Inventory_Cat_Header.OPER_BUS_SEG_CD} = {?OPER_BUS_SEG} and
{Inventory_Catalog.SURP} = {?SURP} and
{Inventory_Catalog.COND_CD} = {?CONDITION} and
{Inventory_Cat_Header.INVEN_ID} = {?INVEN_ID} and
{Inventory_Catalog.SER_NO} = {?SERIAL} and
{Inventory_Cat_Header.BUS_UNIT_CD} = {?BUS_UNIT_CD}
else
{Inventory_Catalog.PROP_NO} = {?PROPERTY} and
{Inventory_Cat_Header.INVEN_TYPE_CD} = {?TYPE} and
{Inventory_Cat_Header.OPER_BUS_SEG_CD} = {?OPER_BUS_SEG} and
{Inventory_Catalog.SURP} = {?SURP} and
{Inventory_Catalog.COND_CD} = {?CONDITION} and
{Inventory_Cat_Header.INVEN_ID} = {?INVEN_ID} and
{Inventory_Catalog.SER_NO} = {?SERIAL} and
{Inventory_Cat_Header.BUS_UNIT_CD} = {?BUS_UNIT_CD}