Is this ALAssetsGroup on iCloud? - ios6

I was trying to figure out if the ALAssetsGroup I had a pointer to was hosted on/copied to iCloud. Not finding the question already asked, I was able to figure it out.
Use valueForProperty on the group object with ALAssetsGroupPropertyType. This returns an NSNumber which is a bitmask of several flags include ALAssetsGroupPhotoStream.

- (BOOL) isICloudAlbum:(ALAssetsGroup*)group {
NSNumber *groupType = [group valueForProperty:ALAssetsGroupPropertyType];
return ([groupType intValue] & ALAssetsGroupPhotoStream) ? YES : NO;
}

Related

how to check if string exist in list of strings in Gatling Scala

How to check if ponkipong is present in activeids using [Gatling] check - [Scala] ?
{
"activeids": [
"ironblossom",
"draw_on",
"ponkipong",
"summer22",
"morphimagus"
]
}
Have tried .check(jmesPath("activeids[?contains(#, 'ponkipong') == `true`]").transform(_.length >= 1).is(true)) but
doesn't work.
Also not sure how to do this using jsonPath.
Though, Kind of a workaround I am currently using is this.
.check(bodyString.saveAs("response_data"))
.check(
checkIf((response: Response, session: Session) => {
val dde = "ponkipong"
val is_dde_active_not_present = if ((Json.parse(session("response_data").as[String].stripMargin) \ "activeids").as[Seq[String]].indexOf(dde) >= 0) false else true
is_dde_active_not_present
}) {
// this check is to make forceful fail if checkIf fails
jsonPath("$.activeids[*]").count.is(-1)
}
)
But, doesn’t look like a solution.
Need help to do it in a proper way.
Nowadays, I tend to use JMESPath whenever possible, as explained here.
In Scala:
jmesPath("contains(activeids, 'ponkipong')").ofType[Boolean].is(true)
In Java (recommended since Gatling 3.7):
jmesPath("contains(activeids, 'ponkipong')").ofBoolean().is(true)

Clang won't complain about [id respondsToSelector:#selector(foo)];

- (void)foo {
id objc = nil;
[objc respondsToSelector:#selector(foo)]; // Works fine
}
And
#protocol DummyProtocol
#end
//...
- (void)foo {
id<DummyProtocol> objc = nil;
[objc respondsToSelector:#selector(foo)]; //Error: No known instance method for selector 'respondsToSelector'
}
I know in this case DummyProtocol doesn't inherit from NSObject, therefor the error occurs. But the first case is kind of tricky, id is essentially a C struct pointer which point to a objc_object struct. It shouldn't suppose to have any ObjC method implementation...
And the dot syntax will generate error in both cases, like
- (void)foo {
id obj = nil;
obj.description; //Error: Property 'description' not found on object of type '__strong id
id<DummyProtocol> objc = nil;
objc.description; //Error: Property 'description' not found on object of type '__strong id<DummyProtocol>'
}
I've check the Clang documentations with not luck. This has been in my head for about 2days, any suggestions will help...
id with [] syntax will accept any selector from any class/protocol of your project at compilation
id<DummyProtocol> will only accept selectors from DummyProtocol
. syntax will only accept selectors from a specific concrete class/protocol (so it will never work with id alone)
Note that description isn't part of your DummyProtocol.

Angular 2 / Typescript - how to check an array of objects to see if a property has the same value?

This question does it in Javascript, but I would have thought in Typescript I could do some kind of map/filter operation to do the same thing.
I have an array of objects called Room. Each Room has a property called Width (which is actually a string, eg '4m', '5m', '6.5m').
I need to check the entire array to see if all the widths are the same.
Based on that question I have this, but I was wondering if TypeScript has something better:
let areWidthsTheSame = true;
this.qp.rooms.forEach(function(room, index, rooms) {
if (rooms[index] != rooms[index+1]) areWidthsTheSame = false;
});
Any ideas?
FYI the linked question has a comment that links to these performance tests, which are interesting in the context of this question:
This can be done in the following way:
const widthArr = rooms.map(r => r.width);
const isSameWidth = widthArr.length === 0 ? true :
widthArr.every(val => val === widthArr[0]);
We first convert the rooms array to an array of widths and then we check if all values in widths arrays are equal.

How to iterate over a list of type Class to edit the properties of its objects in Groovy

I know there are more elaborate ways to achieve this in Java, but Groovy should have a concise way to do the same as per http://groovy.codehaus.org/Looping
Class Currency.groovy
class Currency {
String name
double rate
}
CurrencyController
def select(){
List<Currency> selectedCurrencies = Currency.getAll(params.currencies)
selectedCurrencies.eachWithIndex { obj, i -> obj.rate = update(obj.name)};
[selectedCurrencies:selectedCurrencies]
}
def update(String sym){
return sym
}
The above code throws:
No signature of method: currencychecker.CurrencyController$_$tt__select_closure12.doCall() is applicable for argument types: (currencychecker.Currency)
Thanks to #dmahapatro, the issue was that I was using an iterator variable obj[i], even though obj itself is the iterated object. The rest is correct!
I experimented with selectCurrencies.each as well instead of selectCurrencies.eachWithIndex however the right one in this case is eachWithIndex

ColdFusion 8 ArrayFind Substitute

I have an array that has a structure of ImageID and Custnum.
I need to find a particular ImageID and retrieve the Custnum for it.
I’m using ColdFusion 8 which does not have an ArrayFind command.
How would I do this without looping through each item? Thanks.
Your question may be answered to a point here "Is there a function similar to ArrayFind from ColdFusion 9 in ColdFusion 8?" but I don't see any other way apart from looping.
You can always create and use an UDF but it would have to use looping.
Why exactly you don't want to use looping anyway? Do you have that many elements in the array? Just remember to use cfbreak after finding your element to stop going through the rest of the array.
Given your situation, I don't think arrayFind() would help you much anyhow, as to find something with arrayFind(), you need to know exactly what you're looking for anyhow. And whilst you know your ImageID, you don't know the Custnum associated with it (hence your underlying problem).
There's nothing native in CF which can help you here, but there's a UDF on CFLib - structFindKeyWithValue() which'll do the trick.
It's written for CF9, but is easily backported to CF8. The modified, CF8-friendly version - is in the example below:
<cfscript>
a = [
{ImageID=1, Custnum=1},
{ImageID=2, Custnum=2},
{ImageID=3, Custnum=3},
{ImageID=4, Custnum=4}
];
testStruct = {a=a};
result = structFindKeyWithValue(testStruct, "ImageID", 2, "ONE");
function structFindKeyWithValue(struct, key, value, scope){
var keyResult = false;
var valueResult = [];
var i = 0;
if (!isValid("regex", arguments.scope, "(?i)one|all")){
throw(type="InvalidArgumentException", message="Search scope #arguments.scope# must be ""one"" or ""all"".");
}
keyResult = structFindKey(struct, key, "all");
for (i=1; i <= arrayLen(keyResult); i++){
if (keyResult[i].value == value){
arrayAppend(valueResult, keyResult[i]);
if (scope == "one"){
break;
}
}
}
return valueResult;
}
</cfscript>
<cfdump var="#result#">
Note that because it's a stuct function, you need to wrap your data in a struct first. Other than that it's fairly straight fwd.

Resources