Newline formatting is not supported in contentDescription property of CSSearchableItemAttributeSet - ios

I am having a CSSearchableItem with CSSearchableItemAttributeSet,
CSSearchableItemAttributeSet* attributes = [[CSSearchableItemAttributeSet alloc]initWithItemContentType:(__bridge NSString *)kUTTypeContact];
attributes.keywords = #[keywords];
attributes.title = #"Contact Details";
attributes.displayName = #"Ram Gandhi";
attributes.emailAddresses = #[email];
attributes.phoneNumbers = #[phoneNumber];
attributes.contentDescription = [NSString stringWithFormat:#"%# \n %#", phoneNumber, email];
attributes.supportsPhoneCall = [NSNumber numberWithBool:YES];
attributes.supportsNavigation = [NSNumber numberWithBool:NO];
attributes.thumbnailData = [self getThumbnailData:contactID];
Everything is working fine but the newline in contentDescription is not working as expected though it is not displayed in the UI.
Also I am not sure about the purpose of using kUTTypeContact here as kUTTypeContent does the job. As far as I searched, there is no detailed documentation about how to use kUTTypeContact in Spotlight search.
Is there any other property that I can use inorder to show the email and phone number in separate lines?

it might be very late answer for you but it can help other. now , while using swift 4 we can add 2 lines "contentDescription" as below ,
var contentDescription = ""
var arrDescription = ["email","phone"]
for (index,strDesc) in arrDescription.enumerated(){
if index == 0{
contentDescription = strDesc
}else{
contentDescription += """
\(strDesc)
"""
}
}
I also have try to add more then two strings, but it display only upto two lines , then it will show ... at the end of second line.
Note: - check that "blank line", before "(strDesc)", it is not by mistake, it must be there to display newline.

Related

Can't get value of NSSingleEntryDictionary

I have an NSDictionary, named "thisList", and I need to get the value of its key "list_collection".
Xcode indicates that the value is a "NSSingleEntryDictionary".
The value itself contains an array with yet another dictionary.
Please take a look at the screenshot:
Now, no matter what I try (objectforKey/valueforKey) or whatever type of object I initialize (NSArray/NsMutableArray/NSDictionary/NSMutableDictionary) I end up with a nil value.
Apparently, I miss some essential knowledge on how to handle this.
My question: how should I initialize an object with the value of the key "list_collection".
Here is a (partial) dump of the json:
Printing description of thisList:
{
archived = 0;
"chapter_part" = "";
"chapter_title" = "";
comment = "";
"cover_id" = "<null>";
"created_at" = "2017-01-06T12:59:04.000+01:00";
"date_created" = "06 January 2017";
deleted = 0;
id = 141384502;
isMyList = 1;
keywords = (
);
"list_collection" = {
lists = (
{
"speech_locale" = EN;
subject = engels;
words = (
{
word = attitude;
},
The to me most logical approach would be:
NSDictionary * myDic = [thisList objectForKey:#"list_collection"];
Note: I didn't explicitly initialize 'myDic' here.
To put things in context, here is my code:
NSString * hlists = [json objectForKey:#"lists"];
NSData* data = [hlists dataUsingEncoding:NSUTF8StringEncoding];
NSArray *wrtsLists = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonParsingError];
Lists = [[NSMutableArray alloc]init];
for (NSDictionary *thisList in wrtsLists){
WordList* theList = [[WordList alloc]init];
theList.title = [thisList valueForKey:#"title"];
[Lists addObject:theList];
NSDictionary *myDic = thisList[#"list_collection"];
>>>>this is where I put a breakpoint. myDic is nil here
}
Thanks for your insights.
You can simply get "list_collection" array from "thisList" using by this code
NSDictionary *myDic = thisList[#"list_collection"];
In the end, I figured out, that it was an Xcode problem.
The Debug area just didn't correctly display the values of my objects.
I restarted Xcode, and things started to work as expected.
I lost several hours of my life on this. But I learned a lot, thanks to your good advises.
Try this hope it helps You
NSDictionary *myDic = [thelist valueForKey:"list_collection"];

AWS Batch request for multi items filtered by array of values

I would like to ask about filterExpression for AWSDynamoDBScanExpression.
Problem:
I want to scan db for all object in one table where one parameter (lets call it uniqueId) is one of the value stored in array (array of required uniqueIds).
For one object - it's easy to do with
AWSDynamoDBScanExpression *scanExpression = [[AWSDynamoDBScanExpression alloc] init];
scanExpression.expressionAttributeNames = #{
#"#P": [NSString stringWithFormat:#"%#", property]
};
scanExpression.filterExpression =#"#P = :val";
scanExpression.expressionAttributeValues = #{
#":val" : #"some uniqueID"
};
so in same logic i want to scan db for multi objects
AWSDynamoDBScanExpression *scanExpression = [[AWSDynamoDBScanExpression alloc] init];
scanExpression.expressionAttributeNames = #{
#"#P": [NSString stringWithFormat:#"%#", property]
};
scanExpression.filterExpression = <WHAT SHOULD BE HERE, WHAT EXPRESSION>;
scanExpression.expressionAttributeValues = #{
#":val" : [#"some unique id 1",
#"some unique id 2",
#"some unique id 3"]
};
Is any way to change scanExpression.filterExpression to achive this?
EDIT 1
No, I'm not sure that scan is the best solution. Actually query is best variant think.
The structure of table
#P = :val1 OR #P = :val2
make sense
EDIT2
This is some update:
AWSDynamoDBQueryExpression *query = [[AWSDynamoDBQueryExpression alloc] init];
NSMutableDictionary *dictionaryAttributes = [[NSMutableDictionary alloc] init];
NSString *expression = #"";
for (int i = 0; i < filteredHashValues.count; i++) {
NSString *variableName = [NSString stringWithFormat:#":val%i", i];
[dictionaryAttributes setValue:filteredHashValues[i] forKey:variableName];
expression = [expression stringByAppendingString:expression.length ? [NSString stringWithFormat:#"OR #P = %# " , variableName] : [NSString stringWithFormat:#"#P = %# " , variableName]];
}
query.indexName = #"uniqueId-index";
query.expressionAttributeNames = #{
#"#P": [NSString stringWithFormat:#"%#", #"uniqueId"]
};
query.filterExpression = expression;
query.expressionAttributeValues = dictionaryAttributes;
AWSDynamoDBObjectMapper *dynamoDBObjectMapper = [AWSDynamoDBObjectMapper defaultDynamoDBObjectMapper];
[[dynamoDBObjectMapper query:className expression:query] continueWithBlock:^id _Nullable(AWSTask * _Nonnull task) {
if (task.result) {
AWSDynamoDBPaginatedOutput *output = task.result;
}
return nil;
}];
But result
Printing description of expression:
#P = :val0 OR #P = :val1 OR #P = :val2 OR #P = :val3
Printing description of dictionaryAttributes:
{
":val0" = "8A93A3EA-9FB9-4396-BBF6-D0BD3CBE6BE5";
":val1" = "08533EBA-D3E5-406C-8CDE-03EECCCA801B";
":val2" = "954AE402-336E-423D-BF03-7E8AED1446FE";
":val3" = "F683BDF8-0507-4218-9927-9F14D470E593"; }
Printing description of task->_error: Error
`Domain=com.amazonaws.AWSDynamoDBErrorDomain Code=0 "(null)"
UserInfo={__type=com.amazon.coral.validate#ValidationException,
message=ExpressionAttributeValues contains invalid value: Supplied
AttributeValue is empty, must contain exactly one of the supported
datatypes for key :awsddbomhashvalueplaceholder}
looks like ExpressionAttributeValues is empty - am i doing all correct?
are you sure that you want to use a scan expression? this really consumes a lot of read capacity and can ruine your dynamodb performances: a scan reads you entire table and only THEN applies the filter and returns the values.
if you provide us with your actual dynamodb table structure we could maybe discuss another solution. For example a solution could be to create a global secondary index (if eventual consistent read is ok for you) or a local secondary index (along with its limitations), with a range key on your value to filter. This would allow you to use queries, which is much nicer and advised as of best practices.
That been said, you can just add conditions to your filter using AND and OR operators, resulting in sth similar to "#P = :val1 OR #P = :val2"
hope that helps

How to get values from nested array/ dictionary iOS 7

I fetch values from dictionary and need to display in UITableView, but everything works fine.
On some spot it stops running and shows thread
-[__NSCFString objectAtIndex:]: unrecognized selector sent to instance 0xbfa7670
The code below, which I used to fetch value..
[NSString stringWithFormat:#"%#",[[pageCat1 valueForKeyPath:#"img3"] objectAtIndex:indexPath.row]]
My values are fetched properly in dictionary but lags to display it?
pageCat (
{
img3 = "http://xxx.in/images/page_cat_img/75x75/4.jpg";
name = "PVC Flexible Wires";
page = (
{
id = {
text = 1;
};
img4 = "http://xxxx.in/images/page_img/75x75/1.jpg";
name = "SINGLE CORE FLEXIBLE WIRES ABOVE 6 SQMM";
},
{
id = {
text = 72;
};
img4 = "http://xxx.in/images/page_img/75x75/72.jpg";
name = "SINGLE CORE FLEXIBLE WIRES BELOW 6 SQMM";
}
);
},
{
img3 = "http://xxx.in/images/page_cat_img/75x75/3.jpg";
name = "Bare Copper Wires";
page = {
id = {
text = 29;
};
img4 = "http://xxx.in/images/page_img/75x75/29.jpg";
name = "Tinned Copper Fuse Wires";
};
},
{
img3 = "http://xxx.in/images/page_cat_img/75x75/48.jpg";
name = "Properties of Wire";
page = {
id = {
text = 85;
};
img4 = "http://xxx.in/images/page_img/75x75/85.jpg";
name = "Wires - Normal, HR - PVC, FR, FRLS & Zero Halogen";
};
}
)
Actually look at the log value, it has array and set of values.. i can't find whether it is in what form..
Can anyone help me to find the solution??
Thanks,
Yazh
it looks like [pageCat1 valueForKeyPath:#"img3"] returns a NSString and not a NSArray like you expect
make sure that it returns a NSArray before applying objectAtIndex:
it seems that pageCat1 is a NSArray so you need to write something like:
NSString *path = pageCat1[0][#"img3"];
...
As the error already tells, [pageCat1 valueForKeyPath:#"img3"] returns a NSString and you are calling objectAtIndex: on it which is not recognized for this class. Obviously, pageCat1 differs from what you expected.
Try NSLog(#"%#", pageCat1); to see what it really looks like.
// Edit
pageCat1 (as seen in your update) is an NSArray that contains items of type NSDictionary. What you really want to do is NSString *imgURL = [[pageCat1 objectAtIndex:indexPath.row] objectForKey:#"img3"];
Explanation:
1. [pageCat1 objectAtIndex:indexPath.row] returns a NSDictionary
2. [__dictionary__ objectForKey:#"img3"] returns the NSString containing your image URL
Actually I used XML data, for that i used third party to parse data. Its all of third party which parsed alternate data as array and other as non-array. Finally I check the array with
isKindOfClass
and convert it into array. Therefore my problem in app solved. :-)
Thanks to all who help me..
Please try this one:
//Assuming json is your main dictionary
NSDictionary *pageCat = [json objectForKey:#"pageCat"];
NSMutableArray *array = [[pageCat valueForKey:#"img3"]mutableCopy];
NSLog(#"Value=%#", [array objectAtIndex:indexPath.row]);

Reading in .CSV individual values

I have a .CSV File below that is already put into a nice format rather than a solid list of values.
How would i be able to read individual values from this list … for example 'Time of 5 & 6" and return the number?
I know how would retrieve this from a normal .csv file that is listed, however not from one that has a weird layout like this one. Any ideas?
Thank
If the column titles (such as "Time 4" and "Time of 5 & 6") are consistent, you could separate each line and then by commas, look for the index of the column title, and then grab the same column in the next line.
I haven't tested this, but I think it should work. Assuming your file is read in as a string:
NSArray *componentsByLine = [myFile componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
int firstIndex = 0;
int secondIndex = 0;
BOOL found = NO;
for(firstIndex = 0; firstIndex < componentsByLine.count; firstIndex++)
{
NSArray *componentsByComma = [[componentsByLine objectAtIndex:firstIndex] componentsSeparatedByString:#","];
for(secondIndex = 0; secondIndex < componentsByComma.count; secondIndex++)
{
if([[componentsByComma objectAtIndex:secondIndex] isEqualToString:#"Time of 5 & 6"])
{
found = YES;
break;
}
}
if(found)
break;
}
float requestedTime = [[[[componentsByLine objectAtIndex:firstIndex+1] componentsSeparatedByString:#","] objectAtIndex:secondIndex] floatValue];

How to retrieve the pretext before an array in iOS Objective C (parse)

Array object at index 0---:
<Merchandise:AW9JgReRyQ:(null)>
{
ACL = "<PFACL: 0x201b2590>\";
CoverPhotos = "<ItemPhotos:L5ln3ZN5rm>\";
item = ugh;
listingprice = 356;
originalprice = "25)";
user = "<PFUser:KdRfesAJA3>";
},
I have implemented my iOS app using Parse.com
In that I have an array of objects (Array of dictionaries)
in those I have print the 1st object of that array..
I have some pre text Merchandise:AW9JgReRyQ:(null before every object / dictionary which is related to object id
i want to get the preText " Merchandise:AW9JgReRyQ:(null) " or atleast "AW9JgReRyQ"
How to do ..>?
Total entire array of all objects is
array-------
(
"<Merchandise:AW9JgReRyQ:(null)>
{\n ACL = \"<PFACL: 0x201b2590>\";\n CoverPhotos = \"<ItemPhotos:L5ln3ZN5rm>\";\n Photos = \"<PFRelation: 0x201bff80>(<00000000>.(null) -> ItemPhotos)\";\n brand = \"Baby Gap\";\n description = \"\\nFight\";\n item = ugh;\n listingprice = 356;\n originalprice = \"25)\";\n user = \"<PFUser:KdRfesAJA3>\";\n}",
"<Merchandise:bMPFijErWI:(null)>
{\n ACL = \"<PFACL: 0x201a2300>\";\n CoverPhotos = \"<ItemPhotos:4pm7vX7q26>\";\n Photos = \"<PFRelation: 0x2019a490>(<00000000>.(null) -> ItemPhotos)\";\n brand = \"3 Pommes\";\n description = Sett;\n item = udder;\n listingprice = 245;\n originalprice = 245;\n user = \"<PFUser:KdRfesAJA3>\";\n}"
)
It seems like you have two options for this. Either parse each one out into a string (definitely the less elegant/way uglier way). Or also it looks more likely that it could be an array of arrays that contain a string and dictionary.
If it ends up being the second option, you could easily just grab the object at index 0 twice to get the preText your looking for. However, if thats no avail..then you can just go for it like so:
//Convert your object into an NSString
NSString *converted = (NSString*)[yourArray objectAtIndex:i];
//Or..your may need to do NSString *converted = [NSString stringWithFormat:#"%#",[yourArray objectAtIndex:0]];
NSArray *firstSplitterArray = [converted componentsSeparatedByString:#"<"];//split by <
NSString *partialSplit = [splitterArray objectAtIndex:0];
NSArray *secondSplitterArray = [partialSplit componentsSeparatedByString:#">"];//split by >
NSString *yourPreText = [secondSplitterArray objectAtIndex:0];//final step
//now yourPreText should equal Merchandise:AW9JgReRyQ:(null)
I wrote this according to your first code snippet. If there is actually a leading quotation mark or something, you'll need to change your indexes. But this gives you the idea. Just do some print statements to verify your arrays at each step and you will be good to go. Not the cleanest, but if your in a pinch this could work.

Resources