I am not able to add items to the "places" dictionary? - swift2

Whenever I add items to "places" dictionary, it shows me an error, I basically want my app to add an annotation at the user's click on a map, and want the annotation to have the "thoroughfare" and "subThoroughfare".
And then the annotation text should be updated to a table which is in another viewController.swift file. I want the dictionary to be updated with the place
it asks me to replace the semicolon with a comma.
here's the code for the global variable:
var places = [Dictionary<String,String>()]
now I have used this variable in another viewController.swift file I have put this code under CLGeocode function, while I append the dictionary, it asks me to replace the semicolon with a comma.:
places.append("name":title, "lat":"\(newCoordinate.latitude)", "lon",:"\(newCoordinate.longitude)")
let annotation = MKPointAnnotation()
annotation.coordinate = newCoordinate
annotation.title = title
self.map.addAnnotation(annotation)

places.append(["name":title, "lat":"\(newCoordinate.latitude)", "lon",:"\(newCoordinate.longitude)"])
Use this ^

Try in your code with more safe way: -
var places = [[String: Any]]()
places.append(["name": title ?? "", "lat": newCoordinate.latitude ?? 0.0, "lon": newCoordinate.longitude ?? 0.0])

Related

can't set a property for flex container in segment widgets

I am new to Kony framework. Now i am going through Widget. There i came across Segment widgets using I would create a flex container with some labels and textbox.
My UI design are :
1. I Created a segment and set a flex container with some labels and text box in that segment
2. After that I turn off the flex container visible
3. And I type a code like :
function flex()
{
frmAssign.sgmt1.flex1.isVisible = true;//to show flex as visible but it does not read the property of that flex
}
In simple terms just If I click segment first row flex container isVisible should be true
enter image description here
want to achieve this design in kony
Try change frmAssign.sgmt1.flex1.isVisible = true;
frmAssign.sgmt1.flex1.setVisibility(true);
You cannot access the widget of segment directly.
You have to create a property (eg:isVisible) in Master Data of the segment.
initial Value of this property would be "false",
Then change the value as you per your need.
To change properties in segment data you have change the properties in array which you have set to data of segment.
Basically idea is
if you are using masterdata then you need to read the data change
property values and reassign.
if you are dynamically setting data
then you need to change that array and reassign
// always check for Null for selecteindex
//Note keep your existing properties and just change isVisible to true
var selecteindex= frmAssign.sgmt1.selectedRowIndex;
var segData = frmAssign.sgmt1.data[selecteindex];
segData[selecteindex] =("YourFlexName": {
"text": "CButton1",
"isVisible":true
});
form1.segment1.setDataAt(segData,selecteindex);
The right way to do this is :
var selectedIndex= frmAssign.sgmt1.selectedRowIndex;
var rowData = frmAssign.sgmt1.data[selectedIndex];
rowData["flex1"]["isVisible"] = true;
form1.segment1.setDataAt(rowData, selectedIndex);

Modify reference content of an object in swift

Given a stackView object, I got an array of stackView.arrangedSubviews
which is a get only property. Hence I can't REPLACE one item of it by merely doing
stackView.arrangedSubviews[i] = newSubView
what came to my mind is I want to replace the content of the reference at stackView.arrangedSubviews[i] with the content of newSubView. For instance if this was in C, I would have done something like
*arrangedSubViews[i] = *newSubView
I know there is a way to do what I need by removing arrangedSubViews and utilizing addArrangedSubView but it won't be very efficient.
You can't modify an immutable array, and this is a good thing in many ways.
You can create an extension method to replace the view like this:
#available(iOS 9.0, *)
extension UIStackView {
func replaceView(atIndex index: Int, withView view: UIView) {
let viewToRemove = arrangedSubviews[index]
removeArrangedSubview(viewToRemove)
insertArrangedSubview(view, atIndex: index)
}
}
Then, instead of using stackView.arrangedSubviews[i] = newSubView you can use this code:
stackView.replaceView(atIndex: i, withView: newSubView)
Performance-wise there's no negative impact on doing it this way.

Xamarin: string represantation of object

I'm looking for something similar in Xamarin to iOS -description method which is just string representation of object (called when u type po object in XCode console)
F.e I'm getting a Array or Dictionary and I need to display it in a label
in iOS I'd easilly do:
label.text = object.description;
and it would work for dictionary and arrays:
<__NSArrayI 0x7f8a83ef4b10>(
{
description = "set_loyalty";
event = "";
mutation = 100;
previous = 0;
timestamp = "2016-04-08 09:45:15";
},
{
description = "set_loyalty";
event = "";
mutation = 100;
previous = 100;
timestamp = "2016-04-08 09:45:16";
},
but in Xamarin I weren't able to find easy way to achieve the same.
I've tried:
object.toString();
String.Format("{0}", object);
object.Description;
None of it works like I want (I don't expect it to work :) like I want )
Is there a simple way to achieve this?
If it's an iOS object (inherits from NSObject), you can still use myObect.Description.
If not:
some types overload ToString() to print their properties nicely, but not all
have a look at: https://stackoverflow.com/a/1347630/1489968
or use a serializer of your choice (e.g. JSON.NET). But these will not dump every field / property.

How the elements of scene.children in threeJS can be accessed?

I added some objects to ThreeJS scene (using scene.add(object)). I know the name of object and just want to fetch index of it from scene.children.
I tried to use scene.children.indexOf("objectName") but it returns -1 index. Can anybody suggest what can I do?
Thanks
var object = scene.getObjectByName( "objectName" );
or to recursively search the scene graph
var object = scene.getObjectByName( "objectName", true );
Alternatively, you can search by ID.
var id = scene.getObjectById( 4, true );
three.js r.60
I believe that something that can actually can answer your question is the following code that I use to clean the scene:
while (scene.children.length > 0) {
scene.remove(scene.children[scene.children.length - 1]);
}
this way I don't need to access an element by its name or id. The object are simply fetched from the array with an index, so it's like scene.children[i].
You got an alert text as undefined because you're getting back an object not a value/text. You would need to alert something like scene.getObjectByName( "objectName" ).name or scene.getObjectByName( "objectName" ).id i believe.
The relevant docs: getObjectById, getObjectByName. An important note from getObjectByName:
Note that for most objects the name is an empty string by default. You will have to set it manually to make use of this method.
This could be why you were getting undefined. Also, if you are getting undefined, trying to access .name or .id is going to throw an error. If you were getting an object back you would see something like "[object Object]" in the alert.
Another important note I learned the hard way is that the value you need to pass to getObjectById is object.id, and not object.uuid. Also, object.id is essentially just the index of the object in the children array.
Putting it all together:
// var object = new THREE.Mesh(...) or similar
object.name = 'objectName';
scene.add(object);
var retrievedObject = scene.getObjectById(object.id);
// or
var retrievedObject = scene.getObjectByName('objectName');
alert(retrievedObject.name);

Hover on Jqgrid Column shows a tool-tip

I want to add a custom tooltip on jqgrid column headers.i hover over the column name and i get the tooltip(describes content related to that col)
I don't think there is any built-in way to add custom headers. If you use the headertitles option, it will just use the text as the title attribute.
You'll probably have to set them manually doing something like this:
$("th[role='columnheader']").attr("title", "some description");
You can add that code to one of the callbacks such as gridComplete.
Thanks David for your answer.
we can do one more thing as shown in the code below :
var thd = jQuery("thead:first", grid[0].grid.hDiv)[0];
jQuery("tr.ui-jqgrid-labels th:eq(" + columnnumber + ")", thd).attr("title","This column tells you about people who attended the training but missed the test");
if you want to show custome tooltip for all column you can probably add a loop from first column to last column and have the "text" in an array
var arr=["hello","bla bla","a ","b","c"];
and use this array in the loop

Resources