NSFetchedResultsController sectionIndexTitles property - core-data

I've implemented an NSFetchedResultsController correctly so that it splits up my fetched data by sections. When I try print out its property sectionIndexTitles I just get "0", but if I iterate over its sections and print out the section names it prints out each section's name:
dump(fetchedResultsController.sectionIndexTitles)
// prints out "0"
var names = [String]()
for val in (fetchedResultsController.sections)! {
names.append(val.name)
}
dump(names)
// prints out: - "03/31/2017"
- "04/01/2017"
- "04/02/2017"
I thought the sectionIndexTitles returns an array of all the sections' names, is that incorrect?

Related

Multivalued Fields in XPages

I have 3 fields with multivalue. I need this field values to be shown line by line in ViewPanel. But I do not know how to do it. For example
FIELD1 Values: Bursa;Adana;Konya (String)
FIELD2 Values: 14;15;16 (Numeric)
FIELD3 Values: 201,55 ; 155,85 ; 69,96 (Numeric)
What I need to see in a viewPanel that FIELD1 values should be main category then I need see It's value in below. I have created a view but Every value is shown as string seperated vie comma(","). I have no idea how to do it. Please dinf the screenshot below.
VIEW PANEL with Categorized MultiValue Column
->Bursa
14 201,55
->Adana
15 155,85
->Konya
16 69,96
Short answer: you don’t use a ViewPanel
Long answer: use a repeat control with the View as data source. Then you have access to each viewEntry and construct multiple HTML lines inside the body of the repeat. You might entertain a second repeat control inside. I would use either a JSON object or an instance of a Java class to rearrange the viewcolumn objects into something easier to iterate.
function columnsToArray(viewEntry) {
var result = [];
// loop through the values
// to build something like
// var linearem = {label1: val1, label2: var2}
result.push(linearem);
// end loop
return result;
}
Pseudo code only
Repeat will work, as suggested by Stephan. You can make things a bit easier to prepare your data in the view column value:
#Implode( #Text( field ); "<br>")
and make sure the value is treated as HTML by htmlFilter property of the column https://www.ibm.com/support/knowledgecenter/en/SSVRGU_9.0.1/user/wpd_controls_pref_htmlfilter.html.

Xpages: Getting a sessionScope Array in CSJS

I am working on an application that uses Xpages and KendoUI. In one particular page I have a tool bar with a button with "Add Record". The button opens a window and the user will select one from a piece of data and that will create a new record.
The list of data are employee names and I must compute them. I do so in a sessionScope [could be viewScope] array in the beforePageLoad, like so:
<xp:this.beforePageLoad>
<![CDATA[#{javascript:viewScope.myArray = [];
viewScope.myArray.push("1st Val");
viewScope.myArray.push("2nd Val");
viewScope.myArray.push("3rd Val");}]]>
</xp:this.beforePageLoad>
The dropdown needs data in the following format:
var data = [
{ text: "Black", value: "1" },
{ text: "Orange", value: "2" },
{ text: "Grey", value: "3" }
];
For the life of me I cannot get the data into that format. It looks like a javascript object to me.
How do I get the array in the viewScope into the format I need?
var o = {};
o = "#{javascript:viewScope.get('myArray');";
All SSJS Array objects added to any of the scopes are converted to java.util.Vector (how to update a value in array scoped variable?) which can not be stringified with the standard toJson function. This can be circumvented by creating an intermediate object to store the array in:
viewScope.myData={myArray:[]};
viewScope.myData.myArray.push( { text : 'Mark' , value : '1' } );
viewScope.myData.myArray.push( { text : 'Bryan' , value : '2' } );
Also, I doubt your line of code returns the right data without any explicit JSON conversion. I would write it as:
var myArray = #{javascript:return toJson(viewScope.myData.myArray);};
When you set your client side js variable called o it's a string because the value is between "".
So just remove the double quotes and you'll get it as object.
o=#{javascript:viewScope.get('myArray')};
But be aware you might get an js client side error if the viewscope value is not a valid client side JS object !
You can also set the variable o to a string as you did in your example and use the eval clientside method to evaluate the string as an object.
o=eval("#{javascript:viewScope.get('myArray')}");
P.S. In your example there is a } missing is at the end of your SSJS code when you set your "o" variable.. ;-)

How to change a single words colour in a String in Swift

So as some context, I have a dictionary which holds some custom error messages, based on the error code returned by Parse. You can see one below:
var parseErrorDict: [Int:String] = [
203: "This email address \(emailTextField.text) is already registered."
]
What I would like, is the email address that will be populated to be a different colour or to be in Bold. Is this possible?
Fairly new to Swift so please explain or help clearly :) Thanks in advance.
You want to use an attributed string to edit different parts of the string. You would first break down the string into three parts in your case, the start, middle and end. Then you can add attributes to these three parts, e.g. make the middle part (email address) red, then you can append the three parts back together again:
// The first part of the string should be mutable as parts will be appended to it
var attributedString = NSMutableAttributedString(string: "This email address ")
// Here we specify the attribute that is will be applied to the middle part
var attributes = [NSForegroundColorAttributeName: UIColor.redColor()]
var attributedStringEmail = NSAttributedString(string: "someone#somewhere.com", attributes: attributes)
// The end part
var attributedStringEnd = NSAttributedString(string: " is already registered.")
// Combine the three parts
attributedString.appendAttributedString(attributedStringEmail)
attributedString.appendAttributedString(attributedStringEnd)
// Give the label its text
label.attributedText = attributedString

Groovy - Collection only returns a single value

I've got a small code snippet that loops through a node and grabs all its properties.
I can get this to work if I set one variable to grab the properties values (except it has a weird [] surrounding it). But I don't want redundant code so I'm trying to set multiple properties inside the loop, except all that returns is a single value, it's not looping around all the nodes.
WORKING
String selectNodeLabel = null
selectNodeLabel = JcrUtils.getChildNodes("links").collect{
it.getProperty("label").getString()
}
SINGLE VALUE
String selectNodeLabel = null
String selectNodeMeta = null
String selectNodeFooter= null
String topicNode = null
topicNode = JcrUtils.getChildNodes("links").collect{
selectNodeLabel = it.getProperty("label").getString()
selectNodeMeta = it.getProperty("meta").getString()
selectNodeFooter = it.getProperty("footer").getString()
}
Thanks for any help!
Try:
def nodeList = JcrUtils.getChildNodes("links").collect{
[ selectNodeLabel : it.getProperty("label").getString()
selectNodeMeta : it.getProperty("meta").getString()
selectNodeFooter : it.getProperty("footer").getString() ]
}
Then, nodeList will be a list of Maps, so you could do:
println nodeList*.selectNodeLabel
To print all the selectNodeLabel values for example.
To explain the problems with your code... Collect creates a list of the elements returned by the closure. What your SINGLE VALUE code is doing is overwriting the values in the selectNode... variables, and then setting topicNode to the value returned from the closure for each element in JcrUtils.getChildNodes("links").
For this case, topicNode will contain a List of it.getProperty("footer").getString() (as it is the last line in the Closure

Remove duplicates from NSMutableDictionary within NSMutableArray

I have NSMutableArray i.e books which contains objects. These object are NSMutableDictionay, each object is a key value pair of 3 things i.e. id, name, username. Let there is a case that i have 3 objects having values !
- object1 = id->1, name->Hilal, username->hilalbaig ;
- object2 = id->2, name->Ali, username->alibaig ;
- object3 = id->3, name->Jalal, username->hilalbaig ;
all these object(NSMutableDictionay) are in array(NSMutableArray).
Now my question is that i want to remove duplicates from it as object1 and object2 are duplicates because both have username -> hilalbaig
Using Linq to ObjectiveC you can remove the duplicates as follows:
NSMutableArray* source = // your array of dictionaries
NSArray* uniqueItems = [source distinct:^id(id dictionary) {
return [dictionary objectForKey:#"username"];
}];
A distinct method returns distinct items from an array. The key-selector block allows you to determine how equality is evaluated. In the above example you can see that two dictionaries are considered equal if they have the same 'username'.

Resources