IOS App crashes - unrecognized selector sent to instance - ios

In tableView:cellForRowAtIndexpath method, my code is as below.
When I comment out the if condition enclosed in double asterisk(*), the app crashes with the exception mentioned below. And if I uncomment it then it works fine. Please help as I am new to Objective-C.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = #“MyTableCell";
cell = (MyTableCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#“MyTableCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
**if (invoiceList.count == indexPath.row + 1)**
{
NSMutableDictionary *currentDictionary = [invoiceList objectAtIndex:indexPath.row];
cell.invoiceDetails = currentDictionary;
for ( NSString *key in [cell.invoiceDetails allKeys]) {
NSString *value = [cell.invoiceDetails valueForKey:key];
if([key isEqualToString:MERCHANT_NAME]){
cell.merchantNameValue.text = (value == (id)[NSNull null]) ? #"" : value;
}
if([key isEqualToString:INVOICE_ID]){
cell.invoiceIdValue.text = (value == (id)[NSNull null]) ? #"" : value;
}
if([key isEqualToString:TOTAL_AMOUNT]){
cell.totalAmountValue.text = (value == (id)[NSNull null]) ? #"" : value;
}
}
}
return cell;
}
Exception thrown is:
-[__NSDictionaryM objectAtIndex:]: unrecognized selector sent to instance 0x7fc2a604e9f0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryM objectAtIndex:]: unrecognized selector sent to instance 0x7fc2a604e9f0'
*** First throw call stack:
(
0 CoreFoundation 0x000000010fbd1f35 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010f63ebb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010fbd904d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010fb3127c ___forwarding___ + 988
4 CoreFoundation 0x000000010fb30e18 _CF_forwarding_prep_0 + 120
5 MobileWalletBanking 0x000000010cf0037f -[MyViewController tableView:cellForRowAtIndexPath:] + 479
6 UIKit 0x000000010dd9b4b3 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 508
7 UIKit 0x000000010dd7afb1 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2846
8 UIKit 0x000000010dd90e3c -[UITableView layoutSubviews] + 213
9 UIKit 0x000000010dd1d973 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 521
10 QuartzCore 0x000000010d2bade8 -[CALayer layoutSublayers] + 150
...
)
EDIT:
NSLog of invoiceList:
{
501 = 72;
610 = Merchant1;
611 = Merchant1;
612 = 51573;
615 = 51573;
616 = "07/08/2015 00:00:00";
617 = "64.01";
618 = 498;
619 = 498;
662 = (
{
501 = 72;
520 = "15.18";
615 = 51573;
616 = "07/08/2015 00:00:00";
620 = 43;
621 = "15.18";
623 = True;
624 = 43;
740 = “Text1";
},
{
501 = 72;
520 = 0;
615 = 51573;
616 = "07/08/2015 00:00:00";
620 = 10;
621 = 0;
623 = True;
624 = 10;
740 = “Text2";
},
{
501 = 72;
520 = "37.63";
615 = 51573;
616 = "07/08/2015 00:00:00";
620 = 2;
621 = "37.63";
623 = True;
624 = 2;
740 = “Text3";
},
{
501 = 72;
520 = "11.20";
615 = 51573;
616 = "07/08/2015 00:00:00";
620 = 3;
621 = "11.20";
623 = True;
624 = 3;
740 = “Text4";
},
{
501 = 72;
520 = 0;
615 = 51573;
616 = "07/08/2015 00:00:00";
620 = 14;
621 = 0;
623 = True;
624 = 14;
740 = “Text5";
}
);
663 = (
(
{
Key = 501;
Value = 83;
},
{
Key = Name;
Value = "INVOICE_CONNECTION_PROPERTIES";
},
{
Key = 611;
Value = Merchant1;
},
{
Key = 610;
Value = "";
},
{
Key = 615;
Value = 51573;
},
{
Key = 620;
Value = 1;
},
{
Key = "SERVICE_NAME";
Value = “Text1";
},
{
Key = "FIELD_1";
Value = 4272035;
},
{
Key = "FIELD_1_CONNECTION_FIELD_ID";
Value = 000000000000481;
},
{
Key = "FIELD_1_QS_NAME";
Value = "Id";
},
{
Key = "FIELD_1_QS_VALUE";
Value = "Id";
},
{
Key = "FIELD_2";
Value = 10;
},
{
Key = "FIELD_2_CONNECTION_FIELD_ID";
Value = 000000000000482;
},
{
Key = "FIELD_2_QS_NAME";
Value = "index1";
},
{
Key = "FIELD_2_QS_VALUE";
Value = "index1";
},
{
Key = "FIELD_3";
Value = "";
},
{
Key = "FIELD_3_IS_MODIFIED";
Value = 1;
},
{
Key = "FIELD_3_CONNECTION_FIELD_ID";
Value = 000000000000483;
},
{
Key = "FIELD_3_QS_NAME";
Value = "index2";
},
{
Key = "FIELD_3_QS_VALUE";
Value = "index2";
},
{
Key = "FIELD_4";
Value = R;
},
{
Key = "FIELD_4_CONNECTION_FIELD_ID";
Value = 000000000000488;
},
{
Key = "FIELD_4_QS_NAME";
Value = "index_Type";
},
{
Key = "FIELD_4_QS_VALUE";
Value = "Index_Type";
}
),
(
{
Key = 501;
Value = 83;
},
{
Key = Name;
Value = "INVOICE_CONNECTION_PROPERTIES";
},
{
Key = 611;
Value = Merchant1;
},
{
Key = 610;
Value = "";
},
{
Key = 615;
Value = 51573;
},
{
Key = 620;
Value = 2;
},
{
Key = "SERVICE_NAME";
Value = “Text2";
},
{
Key = "FIELD_1";
Value = 4272033;
},
{
Key = "FIELD_1_CONNECTION_FIELD_ID";
Value = 000000000000481;
},
{
Key = "FIELD_1_QS_NAME";
Value = "Id";
},
{
Key = "FIELD_1_QS_VALUE";
Value = "Id";
},
{
Key = "FIELD_2";
Value = 3;
},
{
Key = "FIELD_2_CONNECTION_FIELD_ID";
Value = 000000000000482;
},
{
Key = "FIELD_2_QS_NAME";
Value = "index1";
},
{
Key = "FIELD_2_QS_VALUE";
Value = "index1";
},
{
Key = "FIELD_3";
Value = "";
},
{
Key = "FIELD_3_IS_MODIFIED";
Value = 1;
},
{
Key = "FIELD_3_CONNECTION_FIELD_ID";
Value = 000000000000483;
},
{
Key = "FIELD_3_QS_NAME";
Value = "index2";
},
{
Key = "FIELD_3_QS_VALUE";
Value = "index2";
},
{
Key = "FIELD_4";
Value = C;
},
{
Key = "FIELD_4_CONNECTION_FIELD_ID";
Value = 000000000000488;
},
{
Key = "FIELD_4_QS_NAME";
Value = "index_type";
},
{
Key = "FIELD_4_QS_VALUE";
Value = "index_type";
}
)
);
664 = (
(
{
Key = 501;
Value = 73;
},
{
Key = 625;
Value = 000000000000481;
},
{
Key = 611;
Value = Merchant1;
},
{
Key = 626;
Value = "id";
},
{
Key = 627;
Value = 1;
},
{
Key = 590;
Value = True;
}
),
(
{
Key = 501;
Value = 73;
},
{
Key = 625;
Value = 000000000000482;
},
{
Key = 611;
Value = Merchant1;
},
{
Key = 626;
Value = "index1";
},
{
Key = 627;
Value = 2;
},
{
Key = 590;
Value = True;
}
),
(
{
Key = 501;
Value = 73;
},
{
Key = 625;
Value = 000000000000483;
},
{
Key = 611;
Value = Merchant1;
},
{
Key = 626;
Value = "index2";
},
{
Key = 627;
Value = 3;
},
{
Key = 590;
Value = True;
}
),
(
{
Key = 501;
Value = 73;
},
{
Key = 625;
Value = 000000000000488;
},
{
Key = 611;
Value = Merchant1;
},
{
Key = 626;
Value = "index_type";
},
{
Key = 627;
Value = 4;
},
{
Key = 590;
Value = True;
}
)
);
}

You are checking if (invoiceList.count == indexPath.row + 1) but instead of it, use if (invoiceList.count> indexPath.row ). Please also check "numberOfRowsInIndexpath" is returning as invoiceList.count.

Related

Iterate through multiple lists using locals in Terraform code

I have the following list of Resource Group names and Virtual Machine Names, I will like to create a map using locals so I can iterate through it using each.key and each.value in my code.
VARIABLES:
variable "vm_names" {
default = [
"vm1",
"vm2",
"vm3",
"vm4",
"vm5"
]
variable "rg_names" {
default = [
"rg1",
"rg2",
"rg3",
"rg4",
"rg5"
]
LOCALS:
locals {
vm = var.vm_names
rg = var.rg_names
vmrg=[for k,v in zipmap(local.vm, local.rg):{
vm = k
rg = v
}]
}
RESULT:
+ vmrg = [
+ {
+ rg = "rg1"
+ vm = "vm1"
},
+ {
+ rg = "rg2"
+ vm = "vm2"
},
+ {
+ rg = "rg3"
+ vm = "vm3"
},
+ {
+ rg = "rg4"
+ vm = "vm4"
},
+ {
+ rg = "rg5"
+ vm = "vm5"
},
]
DESIRED RESULT:
vmrg = {
vm1 = "rg1"
vm2 = "rg2"
vm3 = "rg3"
vm4 = "rg4"
vm5 = "rg5"
}
Actually, it is much simpler and you were already close to figuring it out. The only thing you need is the zipmap built-in function:
vmrg = zipmap(local.vm, local.rg)
will yield:
> local.vmrg
{
"vm1" = "rg1"
"vm2" = "rg2"
"vm3" = "rg3"
"vm4" = "rg4"
"vm5" = "rg5"
}

Google Sheet formula for cumulative sum with condition

I have a Google Sheet with the following layout:
Number | Counted? | Cumulative Total
4 | Y | 4
2 | | 6
9 | Y | 15
... | ... | ...
The first cell in the Cumulative Total column is populated with this formula:
=ArrayFormula((SUMIF(ROW(C2:C1000),"<="&ROW(C2:1000),C2:C1000)
However this counts all rows in the 'Number' column. How can I make the Cumulative Total only count rows where the Counted? cell is Y?
Try this in C2 and copy down:
= N(C1) + A2 * (B2 = "Y")
Update
Doesn't seem to work with SUMIFS, but there is a very slow matrix multiplication alternative:
=ArrayFormula(MMult((Row(2:1000)>=Transpose(Row(2:1000)))*Transpose(A2:A1000*(B2:B1000="Y")), Row(2:1000)^0))
Assuming "Number" in column A and "Counted?" in column B, try in C1
={"SUM"; ArrayFormula(if(ISBLANK(B2:B),,mmult(transpose(if(transpose(row(B2:B))>=row(B2:B), if(B2:B="Y", A2:A,0), 0)),row(B2:B)^0)))}
(Change ranges to suit).
Example
custom formula sample:
=INDEX(IF(B3:B="","", runningTotal(B3:B,1,,A3:A)))
sample file
source code
related
code:
/**
* Get running total for the array of numbers
* by makhrov.max#gmail.com
*
* #param {array} numbers The array of numbers
* #param {number} total_types (1-dafault) sum, (2) avg, (3) min, (4) max, (5) count;
* 1-d array or number
* #param {number} limit number of last values to count next time.
* Set to 0 (defualt) to take all values
* #param {array} keys (optional) array of keys. Function will group result by keys
* #return The hex-code of cell background & font color
* #customfunction
*/
function runningTotal(numbers, total_types, limit, keys) {
// possible types to return
var oTypes = {
'1': 'sum',
'2': 'avg',
'3': 'min',
'4': 'max',
'5': 'count'
}
// checks and defaults
var errPre = '🥴 ';
if( typeof numbers != "object" ) {
numbers = [ [numbers] ];
}
total_types = total_types || [1];
if( typeof total_types != "object" ) {
total_types = [ total_types ];
}
if( keys && typeof keys != "object" ) {
keys = [ [keys] ];
}
if (keys) {
if (numbers.length !== keys.length) {
throw errPre + 'Numbers(' +
numbers.length +
') and keys(' +
keys.length +
') are of different length'; }
}
// assign types
var types = [], type, k;
for (var i = 0; i < total_types.length; i++) {
k = '' + total_types[i];
type = oTypes[k];
if (!type) {
throw errPre + 'Unknown total_type = ' + k;
}
types.push(type);
}
limit = limit || 0;
if (isNaN(limit)) {
throw errPre + '`limit` is not a Number!';
}
limit = parseInt(limit);
// calculating running totals
var result = [],
subres = [],
nodes = {},
key = '-',
val;
var defaultNode_ = {
values: [],
count: 0,
sum: 0,
max: null,
min: null,
avg: null,
maxA: Number.MIN_VALUE,
maxB: Number.MIN_VALUE,
maxC: Number.MIN_VALUE,
minA: Number.MAX_VALUE,
minB: Number.MAX_VALUE,
minC: Number.MAX_VALUE
};
for (var i = 0; i < numbers.length; i++) {
val = numbers[i][0];
// find correct node
if (keys) { key = keys[i][0]; }
node = nodes[key] ||
JSON.parse(JSON.stringify(defaultNode_));
/**
* For findig running Max/Min
* sourse of algorithm
* https://www.geeksforgeeks.org
* /sliding-window-maximum-maximum-of-all-subarrays-of-size-k/
*/
// max
//reset first second and third largest elements
//in response to new incoming elements
if (node.maxA<val) {
node.maxC = node.maxB;
node.maxB = node.maxA;
node.maxA = val;
} else if (node.maxB<val) {
node.maxC = node.maxB;
node.maxB = val;
} else if (node.maxC<val) {
node.maxC = val;
}
// min
if (node.minA>val) {
node.minC = node.minB;
node.minB = node.minA;
node.minA = val;
} else if (node.minB>val) {
node.minC = node.minB;
node.minB = val;
} else if (node.minC>val) {
node.minC = val;
}
// if limit exceeds
if (limit !== 0 && node.count === limit) {
//if the first biggest we earlier found
//is matching from the element that
//needs to be removed from the subarray
if(node.values[0]==node.maxA) {
//reset first biggest to second and second to third
node.maxA = node.maxB;
node.maxB = node.maxC;
node.maxC = Number.MIN_VALUE;
if (val <= node.maxB) {
node.maxC = val;
}
} else if (node.values[0]==node.maxB) {
node.maxB = node.maxC;
node.maxC = Number.MIN_VALUE;
if (val <= node.maxB) {
node.maxC = val;
}
} else if (node.values[0]==node.maxC) {
node.maxC = Number.MIN_VALUE;
if (val <= node.maxB) {
node.maxC = val;
}
} else if(node.values[0]==node.minA) {
//reset first smallest to second and second to third
node.minA = node.minB;
node.minB = node.minC;
node.minC = Number.MAX_VALUE;
if (val > node.minB) {
node.minC = val;
}
}
if (node.values[0]==node.minB) {
node.minB = node.minC;
node.minC = Number.MAX_VALUE;
if (val > node.minB) {
node.minC = val;
}
}
if (node.values[0]==node.minC) {
node.minC = Number.MAX_VALUE;
if (val > node.minB) {
node.minC = val;
}
}
// sum
node.sum -= node.values[0];
// delete first value
node.values.shift();
// start new counter
node.count = limit-1;
}
// add new values
node.count++;
node.values.push(val);
node.sum += val;
node.avg = node.sum/node.count;
node.max = node.maxA;
node.min = node.minA;
// remember entered values for the next loop
nodes[key] = node;
// get the result depending on
// selected total_types
subres = [];
for (var t = 0; t < types.length; t++) {
subres.push(node[types[t]]);
}
result.push(subres);
}
// console.log(JSON.stringify(nodes, null, 4));
return result;
}

Skip Function repeating values while appending in View

I am trying to use skip in mvc4 project so that previous value should not repeated while it append in the Razor view but i am getting same value after some value
here is my code :
var planetfeedsOrder = from a in db.PlanetFeeds
where a.PlanetFeedOwnerId == id || a.PlanetFeedPosterId ==id
&& a.CurrentState != 1
join c in db.Graphs on a.PlanetFeedItemGraphId equals c.GraphID
join u in db.UserInfos on a.PlanetFeedOwnerId equals u.UserInfoID
orderby a.PostDate descending
select new UserInfoViewModel
{
AvatarURL = u.AvatarURL,
UserName=u.FirstName +" "+u.LastName,
GraphItemDescription = c.GraphItemDescription,
GraphItemURL = c.GraphItemURL,
GraphItemUserFullName = c.GraphItemUserFullName,
ItemSummary = c.ItemSummary,
GraphItemThumbUrl = c.GraphItemThumbUrl,
GraphID = c.GraphID,
ItemType = c.ItemType,
ItemUserID = c.ItemUserID,
GraphItemTitle = c.GraphItemTitle,
isRootFeed = a.isRootFeed,
PostDate = a.PostDate,
CommentCount = c.CountResponses,
CountReactions = c.CountPositiveReactions,
CountReaction = c.CountNegativeReactions,
ItemID = c.ItemID,
UserLevel =u.UserLevel,
CurrentState = a.CurrentState,
RecieverUserAvatarURL = c.Address
};
return PartialView("_PlanetfeedPartial", planetfeedsOrder.Skip(SkipCount).Take(itemCount).ToList());
and here is ajax view where i am trying to append it :
$.ajax(
{
type: "Post",
url: "/PlanetFeed/PlanetfeedPartial",
dataType: "html",
data: { id: planetFeedOwnerId, filterType: filterType, taggedItemGraphId: taggedItemGraphId, itemCount: itemCount,skipCount: SkipCount }, //"feedGraphId=10696",
success: function (data) {
var div = $('.planetFeed:last');
$('.planetFeed').removeClass('.tile-group');
SkipCount = itemCount+2;
div.after(data);
var bigDivCount = $('.tile-group').length;
var bigDivWidth = bigDivCount * 486;
$('.tile-area').css({ 'width': bigDivWidth });
Based on your code and subsequent comments if the initial values of itemCount and skipCount are zero then in the first call (note I have substituted variables with the actual values in the data parameter so its easier to see what will be returned)
itemCount = itemCount + 5; // itemCount = 0 + 5 = 5
data: { skipCount: 0, itemCount: 5 } // returns items 1-5
skipCount = itemCount + 5; // skipCount = 5 + 5 = 10;
second call
itemCount = itemCount + 5; // itemCount = 5 + 5 = 10;
data: { skipCount: 10, itemCount: 10 } // returns items 11-20 (items 6-10 missed)
skipCount = itemCount + 5; // skipCount = 10 + 5 = 15;
third call
itemCount = itemCount + 5; // itemCount = 10 + 5 = 15;
data: { skipCount: 15, itemCount: 15 } // returns items 16-30 (items 16-20 repeated)
skipCount = itemCount + 5; // skipCount = 15 + 5 = 20;
You need to change the way you set the value of skip count and use skipCount = skipCount + itemCount;
first call
itemCount = itemCount + 5; // itemCount = 0 + 5 = 5
data: { skipCount: 0, itemCount: 5 } // returns items 1-5
skipCount = skipCount + itemCount; // skipCount = 0 + 5 = 5;
second call
itemCount = itemCount + 5; // itemCount = 5 + 5 = 10;
data: { skipCount: 5, itemCount: 10 } // returns items 6-15
skipCount = skipCount + itemCount; // skipCount = 5 + 10 = 15;
third call
itemCount = itemCount + 5; // itemCount = 10 + 5 = 15;
data: { skipCount: 15, itemCount: 15 } // returns items 16-30
skipCount = skipCount + itemCount; // skipCount = 15 + 15 = 30;
forth call
itemCount = itemCount + 5; // itemCount = 15 + 5 = 20;
data: { skipCount: 30, itemCount: 20 } // returns items 31-50
skipCount = skipCount + itemCount; // skipCount = 30 + 20 = 50;

How to parse this string received from TMDB in iOS

I am getting the popular movie data from TMDB in my iOS App. however i am having great trouble in parsing and getting the meaningful data from it. I am totally new to iOS. i have done similar thing in Windows Phone, where i created Poco's and used DataContractJsonSerializer to parse the data.
but i am not getting any idea on how to do this in iOS.
I want to retrieve id, original_title and poster path from this string.
this is the data i am getting
{
buffer = {
0 = 123;
1 = 34;
10 = 34;
100 = 114;
3451 = 34;
3452 = 58;
3453 = 52;
3454 = 54;
3455 = 46;
3456 = 55;
3457 = 50;
3458 = 49;
3459 = 54;
346 = 110;
3460 = 49;
3461 = 48;
// lot of number in between
977 = 87;
978 = 75;
979 = 68;
98 = 34;
980 = 108;
981 = 51;
982 = 88;
983 = 97;
984 = 98;
985 = 99;
986 = 112;
987 = 72;
988 = 82;
989 = 110;
99 = 111;
990 = 110;
991 = 76;
992 = 77;
993 = 75;
994 = 102;
995 = 85;
996 = 46;
997 = 106;
998 = 112;
999 = 103;
length = 5810;
};
};
cookies = {
};
data = {
page = 1;
results = (
{
adult = 0;
"backdrop_path" = "/AdRL6c4BoMJgk7ZFUB2oUVzav2p.jpg";
id = 41602;
"original_title" = "The Necessary Death of Charlie Countryman";
popularity = "110.726084305053";
"poster_path" = "/fSwdCCGmO50IMaH4XMAixjclLDF.jpg";
"release_date" = "2013-11-15";
title = "The Necessary Death of Charlie Countryman";
"vote_average" = "7.5";
"vote_count" = 37;
},
{
adult = 0;
"backdrop_path" = "/mrvlpJFAzKwZZkLm9VD7Rh2VECi.jpg";
id = 116745;
"original_title" = "The Secret Life of Walter Mitty";
popularity = "64.2212199623452";
"poster_path" = "/v3e1LdwTXupH9L78eIWCKBjclhJ.jpg";
"release_date" = "2013-12-25";
title = "The Secret Life of Walter Mitty";
"vote_average" = "7.2";
"vote_count" = 124;
},
{
adult = 0;
"backdrop_path" = "/8aZHR0wXacn5DVYK3cS2ozWYPCN.jpg";
id = 64686;
"original_title" = "47 Ronin";
popularity = "95.9101659814315";
"poster_path" = "/v9JCVROrdlHZCWP3D6pnV8Xc29w.jpg";
"release_date" = "2013-12-25";
title = "47 Ronin";
"vote_average" = "6.5";
"vote_count" = 81;
},
{
adult = 0;
"backdrop_path" = "/zZTyJ6fbWKDl3XabcpHRnnLMKfU.jpg";
id = 249397;
"original_title" = "Nymphomaniac: Vol. II";
popularity = "94.03616025076791";
"poster_path" = "/pCW6krILJ2L0rXDXH0715teKTtm.jpg";
"release_date" = "2014-03-20";
title = "Nymphomaniac: Vol. II";
"vote_average" = "6.8";
"vote_count" = 11;
},
{
adult = 0;
"backdrop_path" = "/hyR7Fs6Tepgu3yCQGtgO4Ilz9tY.jpg";
id = 57158;
"original_title" = "The Hobbit: The Desolation of Smaug";
popularity = "88.3637510164635";
"poster_path" = "/gQCiuxGsfiXH1su6lp9n0nd0UeH.jpg";
"release_date" = "2013-12-13";
title = "The Hobbit: The Desolation of Smaug";
"vote_average" = "7.6";
"vote_count" = 434;
},
{
adult = 0;
"backdrop_path" = "/cAhCDpAq80QCeQvHytY9JkBalpH.jpg";
id = 109445;
"original_title" = Frozen;
popularity = "69.4628746979819";
"poster_path" = "/jIjdFXKUNtdf1bwqMrhearpyjMj.jpg";
"release_date" = "2013-11-19";
title = Frozen;
"vote_average" = "7.7";
"vote_count" = 348;
},
{
adult = 0;
"backdrop_path" = "/rP36Rx5RQh0rmH2ynEIaG8DxbV2.jpg";
id = 106646;
"original_title" = "The Wolf of Wall Street";
popularity = "64.6183486216064";
"poster_path" = "/wAgdJRx4uZ0u4uzu34NOMvtjLAR.jpg";
"release_date" = "2013-12-25";
title = "The Wolf of Wall Street";
"vote_average" = "7.9";
"vote_count" = 330;
},
{
adult = 0;
"backdrop_path" = "/r7Lmi2Jj1CJLdipYtLEU5iA4SB5.jpg";
id = 64807;
"original_title" = "Grudge Match";
popularity = "59.9853953814402";
"poster_path" = "/vzIIna3nvQAVGBBXbZgzvPSxg36.jpg";
"release_date" = "2013-12-25";
title = "Grudge Match";
"vote_average" = "6.6";
"vote_count" = 16;
},
{
adult = 0;
"backdrop_path" = "/mnxWdWTP3jbfxC4oaPrwevwvOZ2.jpg";
id = 53182;
"original_title" = "300: Rise of an Empire";
popularity = "49.8372271195572";
"poster_path" = "/d4kPMHsoTEH3FIkBDJM0uVOlas6.jpg";
"release_date" = "2014-03-07";
title = "300: Rise of an Empire";
"vote_average" = "6.6";
"vote_count" = 102;
},
{
adult = 0;
"backdrop_path" = "/rO75nODBBmJx4u5ZRy2BsGFgbO7.jpg";
id = 177494;
"original_title" = "Veronica Mars";
popularity = "48.7870515185193";
"poster_path" = "/nS3L07mQfcNJcisLEKgi8fWoBS1.jpg";
"release_date" = "2014-03-14";
title = "Veronica Mars";
"vote_average" = "7.2";
"vote_count" = 19;
},
{
adult = 0;
"backdrop_path" = "/iJtq3PHsLgjcYIrNlT2glzEdBo5.jpg";
id = 110415;
"original_title" = Snowpiercer;
popularity = "47.3945315956173";
"poster_path" = "/3J4QoMpQYE2MehOTQG9X2KUP4aq.jpg";
"release_date" = "2013-08-01";
title = Snowpiercer;
"vote_average" = "7.2";
"vote_count" = 29;
},
{
adult = 0;
"backdrop_path" = "/qMDiCjxfv6Y8JN2DFViTX5D1ORH.jpg";
id = 24253;
"original_title" = "Flickan som lekte med elden";
popularity = "46.7216104479466";
"poster_path" = "/qHRpU2d9NWB0WDulwgFwg6a9JRK.jpg";
"release_date" = "2009-09-18";
title = "The Girl Who Played with Fire";
"vote_average" = "6.8";
"vote_count" = 141;
},
{
adult = 0;
"backdrop_path" = "/1DfcGAQ4EVIZFnveo1IzHFtgFTS.jpg";
id = 175112;
"original_title" = "The Pirate Fairy";
popularity = "46.03463240154";
"poster_path" = "/6VmPnBPDCTbpZ3Jj5lbgHD10IZm.jpg";
"release_date" = "2014-04-01";
title = "The Pirate Fairy";
"vote_average" = "7.6";
"vote_count" = 5;
},
{
adult = 0;
"backdrop_path" = "/1RTiQXeHoEMXkZNWaB8W5uaEZ2.jpg";
id = 205220;
"original_title" = Philomena;
popularity = "45.1210557523094";
"poster_path" = "/6BTXHupSPkrwsoz4Br6qwwSVmhj.jpg";
"release_date" = "2013-11-27";
title = Philomena;
"vote_average" = "7.5";
"vote_count" = 31;
},
{
adult = 0;
"backdrop_path" = "/wRCPG1lsgfTFkWJ7G3eWgxCgv0C.jpg";
id = 101299;
"original_title" = "The Hunger Games: Catching Fire";
popularity = "41.4568100606251";
"poster_path" = "/tAhSyLxpaZJCr1oc2a3flvC2B7x.jpg";
"release_date" = "2013-11-22";
title = "The Hunger Games: Catching Fire";
"vote_average" = "7.7";
"vote_count" = 518;
},
{
adult = 0;
"backdrop_path" = "/hz3JfAikYXtaNWIJhWM4p5sy5OZ.jpg";
id = 49047;
"original_title" = Gravity;
popularity = "40.0573419755177";
"poster_path" = "/2gPjLWIyrWlAn2DgKMOKTBnZYyO.jpg";
"release_date" = "2013-10-04";
title = Gravity;
"vote_average" = "7.9";
"vote_count" = 751;
},
{
adult = 0;
"backdrop_path" = "/3FweBee0xZoY77uO1bhUOlQorNH.jpg";
id = 76338;
"original_title" = "Thor: The Dark World";
popularity = "38.5511611536454";
"poster_path" = "/aROh4ZwLfv9tmtOAsrnkYTbpujA.jpg";
"release_date" = "2013-11-08";
title = "Thor: The Dark World";
"vote_average" = "7.1";
"vote_count" = 503;
},
{
adult = 0;
"backdrop_path" = "/dNPmXYRS3nN4vD7MLtz5lP79DCB.jpg";
id = 11824;
"original_title" = "Teen Wolf";
popularity = "37.546317184227";
"poster_path" = "/3TKJbKNpHvRP8YVnwbgfok41AAC.jpg";
"release_date" = "1985-08-23";
title = "Teen Wolf";
"vote_average" = "7.1";
"vote_count" = 31;
},
{
adult = 0;
"backdrop_path" = "/kJzvjhJP6Xf7QQofVl3y0NvpwmI.jpg";
id = 256731;
"original_title" = "Bad Country";
popularity = "37.123709776744";
"poster_path" = "/6bjfGrtUYmuZzFCia3TcvY0Kz1e.jpg";
"release_date" = "2014-03-10";
title = "Bad Country";
"vote_average" = "5.5";
"vote_count" = 3;
},
{
adult = 0;
"backdrop_path" = "/6Ace8kIosYGnAiJUHgbLO4MNI6k.jpg";
id = 77067;
"original_title" = DeadHeads;
popularity = "36.41";
"poster_path" = "/A7kD47MEXywqKPeKHrxBfkvPTqy.jpg";
"release_date" = "2011-04-29";
title = DeadHeads;
"vote_average" = "5.8";
"vote_count" = 6;
}
);
"total_pages" = 7848;
"total_results" = 156953;
};
headers = {
"Access-Control-Allow-Origin" = "*";
Age = 3350;
"Cache-Control" = "public, max-age=14400";
Connection = "keep-alive";
"Content-Length" = 5810;
"Content-Type" = "application/json;charset=utf-8";
Date = "Sat, 29 Mar 2014 10:14:03 GMT";
ETag = "\"76070c8ebb216a66cbbc36e56c1407fa\"";
Server = nginx;
Status = "200 OK";
Vary = "Accept-Encoding";
Via = "1.0 localhost (squid/3.1.19)";
"X-Apiary-Ratelimit-Limit" = 120;
"X-Apiary-Ratelimit-Remaining" = 119;
"X-Apiary-Transaction-Id" = 53369cebed260702000005cc;
"X-Cache" = "HIT from localhost";
"X-Cache-Lookup" = "HIT from localhost:3128";
"X-Memc" = HIT;
"X-Memc-Age" = 12648;
"X-Memc-Expires" = 1752;
"X-Memc-Key" = eb13032fb1ef09086dcaac2d14c098c0;
};
status = 200;
text = "{\"page\":1,\"results\":[{\"adult\":false,\"backdrop_path\":\"/AdRL6c4BoMJgk7ZFUB2oUVzav2p.jpg\",\"id\":41602,\"original_title\":\"The Necessary Death of Charlie Countryman\",\"release_date\":\"2013-11-15\",\"poster_path\":\"/fSwdCCGmO50IMaH4XMAixjclLDF.jpg\",\"popularity\":110.726084305053,\"title\":\"The Necessary Death of Charlie Countryman\",\"vote_average\":7.5,\"vote_count\":37},{\"adult\":false,\"backdrop_path\":\"/mrvlpJFAzKwZZkLm9VD7Rh2VECi.jpg\",\"id\":116745,\"original_title\":\"The Secret Life of Walter Mitty\",\"release_date\":\"2013-12-25\",\"poster_path\":\"/v3e1LdwTXupH9L78eIWCKBjclhJ.jpg\",\"popularity\":64.2212199623452,\"title\":\"The Secret Life of Walter Mitty\",\"vote_average\":7.2,\"vote_count\":124},{\"adult\":false,\"backdrop_path\":\"/8aZHR0wXacn5DVYK3cS2ozWYPCN.jpg\",\"id\":64686,\"original_title\":\"47 Ronin\",\"release_date\":\"2013-12-25\",\"poster_path\":\"/v9JCVROrdlHZCWP3D6pnV8Xc29w.jpg\",\"popularity\":95.9101659814315,\"title\":\"47 Ronin\",\"vote_average\":6.5,\"vote_count\":81},{\"adult\":false,\"backdrop_path\":\"/zZTyJ6fbWKDl3XabcpHRnnLMKfU.jpg\",\"id\":249397,\"original_title\":\"Nymphomaniac: Vol. II\",\"release_date\":\"2014-03-20\",\"poster_path\":\"/pCW6krILJ2L0rXDXH0715teKTtm.jpg\",\"popularity\":94.0361602507679,\"title\":\"Nymphomaniac: Vol. II\",\"vote_average\":6.8,\"vote_count\":11},{\"adult\":false,\"backdrop_path\":\"/hyR7Fs6Tepgu3yCQGtgO4Ilz9tY.jpg\",\"id\":57158,\"original_title\":\"The Hobbit: The Desolation of Smaug\",\"release_date\":\"2013-12-13\",\"poster_path\":\"/gQCiuxGsfiXH1su6lp9n0nd0UeH.jpg\",\"popularity\":88.3637510164635,\"title\":\"The Hobbit: The Desolation of Smaug\",\"vote_average\":7.6,\"vote_count\":434},{\"adult\":false,\"backdrop_path\":\"/cAhCDpAq80QCeQvHytY9JkBalpH.jpg\",\"id\":109445,\"original_title\":\"Frozen\",\"release_date\":\"2013-11-19\",\"poster_path\":\"/jIjdFXKUNtdf1bwqMrhearpyjMj.jpg\",\"popularity\":69.4628746979819,\"title\":\"Frozen\",\"vote_average\":7.7,\"vote_count\":348},{\"adult\":false,\"backdrop_path\":\"/rP36Rx5RQh0rmH2ynEIaG8DxbV2.jpg\",\"id\":106646,\"original_title\":\"The Wolf of Wall Street\",\"release_date\":\"2013-12-25\",\"poster_path\":\"/wAgdJRx4uZ0u4uzu34NOMvtjLAR.jpg\",\"popularity\":64.6183486216064,\"title\":\"The Wolf of Wall Street\",\"vote_average\":7.9,\"vote_count\":330},{\"adult\":false,\"backdrop_path\":\"/r7Lmi2Jj1CJLdipYtLEU5iA4SB5.jpg\",\"id\":64807,\"original_title\":\"Grudge Match\",\"release_date\":\"2013-12-25\",\"poster_path\":\"/vzIIna3nvQAVGBBXbZgzvPSxg36.jpg\",\"popularity\":59.9853953814402,\"title\":\"Grudge Match\",\"vote_average\":6.6,\"vote_count\":16},{\"adult\":false,\"backdrop_path\":\"/mnxWdWTP3jbfxC4oaPrwevwvOZ2.jpg\",\"id\":53182,\"original_title\":\"300: Rise of an Empire\",\"release_date\":\"2014-03-07\",\"poster_path\":\"/d4kPMHsoTEH3FIkBDJM0uVOlas6.jpg\",\"popularity\":49.8372271195572,\"title\":\"300: Rise of an Empire\",\"vote_average\":6.6,\"vote_count\":102},{\"adult\":false,\"backdrop_path\":\"/rO75nODBBmJx4u5ZRy2BsGFgbO7.jpg\",\"id\":177494,\"original_title\":\"Veronica Mars\",\"release_date\":\"2014-03-14\",\"poster_path\":\"/nS3L07mQfcNJcisLEKgi8fWoBS1.jpg\",\"popularity\":48.7870515185193,\"title\":\"Veronica Mars\",\"vote_average\":7.2,\"vote_count\":19},{\"adult\":false,\"backdrop_path\":\"/iJtq3PHsLgjcYIrNlT2glzEdBo5.jpg\",\"id\":110415,\"original_title\":\"Snowpiercer\",\"release_date\":\"2013-08-01\",\"poster_path\":\"/3J4QoMpQYE2MehOTQG9X2KUP4aq.jpg\",\"popularity\":47.3945315956173,\"title\":\"Snowpiercer\",\"vote_average\":7.2,\"vote_count\":29},{\"adult\":false,\"backdrop_path\":\"/qMDiCjxfv6Y8JN2DFViTX5D1ORH.jpg\",\"id\":24253,\"original_title\":\"Flickan som lekte med elden\",\"release_date\":\"2009-09-18\",\"poster_path\":\"/qHRpU2d9NWB0WDulwgFwg6a9JRK.jpg\",\"popularity\":46.7216104479466,\"title\":\"The Girl Who Played with Fire\",\"vote_average\":6.8,\"vote_count\":141},{\"adult\":false,\"backdrop_path\":\"/1DfcGAQ4EVIZFnveo1IzHFtgFTS.jpg\",\"id\":175112,\"original_title\":\"The Pirate Fairy\",\"release_date\":\"2014-04-01\",\"poster_path\":\"/6VmPnBPDCTbpZ3Jj5lbgHD10IZm.jpg\",\"popularity\":46.03463240154,\"title\":\"The Pirate Fairy\",\"vote_average\":7.6,\"vote_count\":5},{\"adult\":false,\"backdrop_path\":\"/1RTiQXeHoEMXkZNWaB8W5uaEZ2.jpg\",\"id\":205220,\"original_title\":\"Philomena\",\"release_date\":\"2013-11-27\",\"poster_path\":\"/6BTXHupSPkrwsoz4Br6qwwSVmhj.jpg\",\"popularity\":45.1210557523094,\"title\":\"Philomena\",\"vote_average\":7.5,\"vote_count\":31},{\"adult\":false,\"backdrop_path\":\"/wRCPG1lsgfTFkWJ7G3eWgxCgv0C.jpg\",\"id\":101299,\"original_title\":\"The Hunger Games: Catching Fire\",\"release_date\":\"2013-11-22\",\"poster_path\":\"/tAhSyLxpaZJCr1oc2a3flvC2B7x.jpg\",\"popularity\":41.4568100606251,\"title\":\"The Hunger Games: Catching Fire\",\"vote_average\":7.7,\"vote_count\":518},{\"adult\":false,\"backdrop_path\":\"/hz3JfAikYXtaNWIJhWM4p5sy5OZ.jpg\",\"id\":49047,\"original_title\":\"Gravity\",\"release_date\":\"2013-10-04\",\"poster_path\":\"/2gPjLWIyrWlAn2DgKMOKTBnZYyO.jpg\",\"popularity\":40.0573419755177,\"title\":\"Gravity\",\"vote_average\":7.9,\"vote_count\":751},{\"adult\":false,\"backdrop_path\":\"/3FweBee0xZoY77uO1bhUOlQorNH.jpg\",\"id\":76338,\"original_title\":\"Thor: The Dark World\",\"release_date\":\"2013-11-08\",\"poster_path\":\"/aROh4ZwLfv9tmtOAsrnkYTbpujA.jpg\",\"popularity\":38.5511611536454,\"title\":\"Thor: The Dark World\",\"vote_average\":7.1,\"vote_count\":503},{\"adult\":false,\"backdrop_path\":\"/dNPmXYRS3nN4vD7MLtz5lP79DCB.jpg\",\"id\":11824,\"original_title\":\"Teen Wolf\",\"release_date\":\"1985-08-23\",\"poster_path\":\"/3TKJbKNpHvRP8YVnwbgfok41AAC.jpg\",\"popularity\":37.546317184227,\"title\":\"Teen Wolf\",\"vote_average\":7.1,\"vote_count\":31},{\"adult\":false,\"backdrop_path\":\"/kJzvjhJP6Xf7QQofVl3y0NvpwmI.jpg\",\"id\":256731,\"original_title\":\"Bad Country\",\"release_date\":\"2014-03-10\",\"poster_path\":\"/6bjfGrtUYmuZzFCia3TcvY0Kz1e.jpg\",\"popularity\":37.123709776744,\"title\":\"Bad Country\",\"vote_average\":5.5,\"vote_count\":3},{\"adult\":false,\"backdrop_path\":\"/6Ace8kIosYGnAiJUHgbLO4MNI6k.jpg\",\"id\":77067,\"original_title\":\"DeadHeads\",\"release_date\":\"2011-04-29\",\"poster_path\":\"/A7kD47MEXywqKPeKHrxBfkvPTqy.jpg\",\"popularity\":36.41,\"title\":\"DeadHeads\",\"vote_average\":5.8,\"vote_count\":6}],\"total_pages\":7848,\"total_results\":156953}";
uuid = "bb4cca64-b0c4-0308-b92f-49980466092c";
}
The code that i tried till now
[MYCloud callFunctionInBackground:#"popularMovie"
withParameters:#{#"movie": #" "}
block:^(id response, NSError *error) {
if (!error) {
// ratings is 4.5
NSArray *movieArray;
movieArray = [response allValues];
NSDictionary *firstObject = [movieArray objectAtIndex:0];
NSDictionary *entities = [firstObject objectForKey:#"results"];
NSLog(#"json :%#",[response description]);
it crashes at NSDictionary *entities = [firstObject objectForKey:#"results"];
======================================================================================
this is the crash log on trying
NSDictionary *blah = [NSJSONSerialization JSONObjectWithData:response options:0 error:nil];
2014-03-29 16:21:48.572 Moviez[6804:60b] -[__NSDictionaryM bytes]: unrecognized selector sent to instance 0x9daf000
2014-03-29 16:21:48.575 Moviez[6804:60b] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryM bytes]: unrecognized selector sent to instance 0x9daf000'
* First throw call stack:
(
0 CoreFoundation 0x026271e4 exceptionPreprocess + 180
1 libobjc.A.dylib 0x023a68e5 objc_exception_throw + 44
2 CoreFoundation 0x026c4243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0261750b __forwarding + 1019
4 CoreFoundation 0x026170ee _CF_forwarding_prep_0 + 14
5 Foundation 0x020ec4bc -[_NSJSONReader findEncodingFromData:withBOMSkipLength:] + 36
6 Foundation 0x020ec66b -[_NSJSONReader parseData:options:] + 63
7 Foundation 0x020ecc30 +[NSJSONSerialization JSONObjectWithData:options:error:] + 161
8 Moviez 0x00002884 32-[HILViewController viewDidLoad]_block_invoke + 212
9 Moviez 0x00053f47 __40-[PFTask thenCallBackOnMainThreadAsync:]_block_invoke_2 + 241
10 libdispatch.dylib 0x02c7a7b8 _dispatch_call_block_and_release + 15
11 libdispatch.dylib 0x02c8f4d0 _dispatch_client_callout + 14
12 libdispatch.dylib 0x02c7d726 _dispatch_main_queue_callback_4CF + 340
13 CoreFoundation 0x0268c43e __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE + 14
14 CoreFoundation 0x025cd5cb __CFRunLoopRun + 1963
15 CoreFoundation 0x025cc9d3 CFRunLoopRunSpecific + 467
16 CoreFoundation 0x025cc7eb CFRunLoopRunInMode + 123
17 GraphicsServices 0x0420b5ee GSEventRunModal + 192
18 GraphicsServices 0x0420b42b GSEventRun + 104
19 UIKit 0x01066f9b UIApplicationMain + 1225
20 Moviez 0x00002ded main + 141
21 libdyld.dylib 0x02ec4701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
UPDATED to match the full data you are getting
As you say response is already an NSDictionary so your code should be something like this...
// Results is an Array of movie entries
NSDictionary *movieData = [response objectForKey:#"data"];
NSArray * movieArray = [movieData objectForKey:#"results"];
NSDictionary *firstObject = [movieArray objectAtIndex:0];
Or in modern objective c you could do
NSDictionary *movieData = response[#"data"];
NSArray * movieArray = movieData[#"results"];
NSDictionary *firstObject = movieArray[0];
Or if you are really confident its always going to contain something you could do
NSDictionary *firstObject = response[#"data"][#"results"][0];
(I think)
Well the top level object is an NSDictionary.
So...
NSDictionary *blah = [NSJSONSerialization JSONObjectWithData:theData options:0 error:nil];
That will turn the data into an object that you can use.

Lua accessing table stored in external file

I have an external lua file that has a table stored in it that is formatted as follows:
sgeT = {
2535047 = {
{
["account"] = "TG-MCB110105",
["exec"] = "/share/home/00288/tg455591/NAMD_2.8b3/NAMD_2.8b3_Linux-x86_64-MVAPICH-Intel-Ranger/namd2",
["execEpoch"] = 1305825864,
["execModify"] = "Thu May 19 12:24:24 2011",
["execType"] = "user:binary",
["jobID"] = "2535047",
["numCores"] = "128",
["numNodes"] = "8",
pkgT = {
},
["runTime"] = "65125",
["sha1"] = "e157dd510a7be4d775d6ceb271373ea24e7f9559",
sizeT = {
["bss"] = "104552",
["data"] = "192168",
["text"] = "10650813",
},
["startEpoch"] = "1335843433",
["startTime"] = "Mon Apr 30 22:37:13 2012",
["user"] = "guo",
},
},
2535094 = {
{
["account"] = "TG-MCB110105",
["exec"] = "/share/home/00288/tg455591/NAMD_2.8b3/NAMD_2.8b3_Linux-x86_64-MVAPICH-Intel-Ranger/namd2",
["execEpoch"] = 1305825864,
["execModify"] = "Thu May 19 12:24:24 2011",
["execType"] = "user:binary",
["jobID"] = "2535094",
["numCores"] = "128",
["numNodes"] = "8",
pkgT = {
},
["runTime"] = "81635",
["sha1"] = "e157dd510a7be4d775d6ceb271373ea24e7f9559",
sizeT = {
["bss"] = "104552",
["data"] = "192168",
["text"] = "10650813",
},
["startEpoch"] = "1335823028",
["startTime"] = "Mon Apr 30 16:57:08 2012",
["user"] = "guo",
},
}
I want to iterate through the table like an array and return the exec key, value pair, and I am completely new to lua and I am using the following script:
FileStr = "lariatData-sgeT-2012-05-31.lua"
Hnd, ErrStd = io.open(FileStr, "r")
myTable = loadTable(FileStr)
if Hnd then
for Str in Hnd:lines() do
print(Str, "\n")
for exec, val in pairs(myTable) do
print(exec.." "..val, "\n")
end
end
Hnd.close()
else
print(ErrStr, "\n")
end
However, it is returning that the table is nil. What am I doing wrong?
In continuation of comments above:
-- Notice that I've used `[2535047]`
sgeT = {
[2535047] = {
{
["account"] = "TG-MCB110105",
["exec"] = "/share/home/00288/tg455591/NAMD_2.8b3/NAMD_2.8b3_Linux-x86_64-MVAPICH-Intel-Ranger/namd2",
["execEpoch"] = 1305825864,
["execModify"] = "Thu May 19 12:24:24 2011",
["execType"] = "user:binary",
["jobID"] = "2535047",
["numCores"] = "128",
["numNodes"] = "8",
pkgT = {
},
["runTime"] = "65125",
["sha1"] = "e157dd510a7be4d775d6ceb271373ea24e7f9559",
sizeT = {
["bss"] = "104552",
["data"] = "192168",
["text"] = "10650813",
},
["startEpoch"] = "1335843433",
["startTime"] = "Mon Apr 30 22:37:13 2012",
["user"] = "guo",
},
},
}
The above is your file. Then, your Lua program shall be:
FileStr = "lariatData-sgeT-2012-05-31.lua"
Hnd, ErrStr = io.open(FileStr, "r")
if Hnd then
dofile(FileStr)
for Str in Hnd:lines() do
print(Str, "\n")
for exec, val in pairs(sgeT) do
print(exec.." "..val, "\n")
end
end
Hnd.close()
else
print(ErrStr, "\n")
end

Resources