What is the use of [i] in below program Xcode?
for (unsigned short int i=0; i<100; i++) {
NSLog(#"Top iOS Apps %i in App store is - %# released on - %#",i,appStore100Apps[#"feed"][#"results"][i][#"name"],appStore100Apps[#"feed"][#"results"][i][#"releaseDate"]);
}
The for loop goes through the first 100 elements in the array, and i acts as the counter when iterating through the loop, and accesses the ith result in the app store feed specifically via index subscripting on the array of results
[i] will increase when the loop goes. It will get each record of appStore100Apps until it hits 100.
Related
I am just writing up the API and implementation spec and I was thinking of using Spring Data JPA to handle the paging of the results. The Page class already contains information I need which is the total number of records for the whole collection but I want to avoid loading the all the records in the page into memory.
You can load all data in smaller chunks.
First of all you need to have count of the whole data.
long count = (your_count_query)
Then make a total page according to the count.
bulkSize is the value you want each page to contain. f.e 10,000
int totalPage = (int) Math.ceil(count * 1.0 / bulkSize);
And finally get result through the loop.
for (int i = 0; i < totalPage; i++) {
Pageable currentPageable = PageRequest.of(i, bulkSize, Sort.by("some_property"));
Page<Object> page= repository.findPage(currentPageable);
}
When using OrderSelect() in mql4, are the orders ordered according to the ticket number by default? My intention is to use OrderModify() on orders starting from the first that was opened to the most recent.
Never assume anything in MQL unless it's explicitly specified in the documentation. That said, you'll need to sort your ticket numbers before iterating them in order.
CArrayInt tickets;
for(int i=0; OrderSelect(i, SELECT_BY_POS); i++)
tickets.Add(OrderTicket());
tickets.Sort();
for(int i=0; i<tickets.Total(); i++)
if(OrderSelect(tickets[i], SELECT_BY_TICKET))
...
`enter code here`
int Magic = 12345;
// This reads the orders LIFO (last in...)
// the index is an integer and is incremented from 0
// as the orders are placed. It is NOT
// the ticket number. No sorting necessary.
for(int i=OrdersTotal()-1;i>=0;i--)
if(_Symbol=OrderSymbol() && Magic = OrderMagicNumber())
if(OrderSelect(i, SELECT_BY_POS) {
Print("Order Index: ",i,", Ticket: ",OrderTicket());
You cannot call OrderSelect() function without parameters. You must specify id and the way the orders are selected. If you know an ID of the order, as it is seen it MT4 terminal window, you can call OrderSelect( order_id, SELECT_BY_TICKET), if you dont know or in case you loop over history trades you have to apply OrderSelect(i,SELECT_BY_POS) or OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) where i is integer between 0 and OrdersTotal() or OrdersHistoryTotal() respectfully.
If you loop over the array of trades with i as an integer, you are strongly advised to loop from the maximum value to zero (and not vice versa), and you can obtain ticket id by calling OrderTicket() function after OrderSelect(*,*[,MODE_HISTORY]) is successful.
Currently I am trying to store images in an SQLite DB and I have it working with one but I want to be able to store multiple Byte arrays inside the SQLite DB in one cell of the DB.
So to achieve this I have set up a list which contains multiple Byte Arrays. What I want to be able to do is add some sort of delimiter after every array inside the list so that when I retrieve the data back from the DB I can use the delimiters to split the List into the different byte arrays which I can then use for my table to show the different images.
I a bit stuck on how to do this so hopefully somebody can help.
This is the only thing I have come up with but really does not work at all (Still pretty new to this) Im using this to split the Byte array list into separate arrays and after each one appending a forward slash and then storing it in a new array to be added to the DB:
private byte[] SplitListAndReturnByteArray(List<byte[]> list)
{
int count = 0;
foreach (var item in list)
{
FormResults.finalByteArray.SetValue(item, count);
count++;
FormResults.finalByteArray.SetValue("/", count);
count++;
}
return FormResults.finalByteArray;
}
I have an array of core data objects called samples, each sample has a depthFrom and depthToo. I load each sample into a tableView to show the depthFrom and Too. I need to check for gaps between the values and if there is, insert a new sample.
The samples in the table could look like below with depthFrom and depthToo,
The issue is since there is a gap between the numbers from 100 to 210 new samples should be added to the table. using a gap of 50 as much as possible so it would look like this with the auto generated samples.
What im unsure of is how to compare the values, i would rather do it as the view loads before cellForRowAtIndexPath is called so i would not need to reload the table again. I was thinking of looping through each value and comparing them but there all in the same array so im not sure how i would do this. I have all the data displaying correctly in my app its just the gaps i need to account for and if im able to find a way to compare the values in the array then i can manage adding in the new objects i just need pointing in the right direction as this is new to me.
If theres anything about my question that is confusing then just add a comment and i will update it accordingly, thanks for any help.
To fix the gaps, you must keep track of the last depthTo and check if there's a gap between it and the current sample. If there is, insert samples with a spacing of 50*, until we reach our current sample.
Here's a pseudocode solution:
samples = NSMutableArray
int lastDepthTo = 0;
for (i = 0; i < [samples count]; i++) {
s = samples[i]
// add missing samples (upto current s.depthFrom)
while (s.depthFrom > lastDepthTo) {
genDepthTo = MIN(d.depthFrom, lastDepthTo+50)
generated = new sample(depthFrom: lastDepthTo, depthTo: genDepthTo)
[samples insert:generated atIndex:i]
i++ // increment i to skip inserted sample
lastDepthTo = genDepthTo
}
lastDepthTo = s.depthTo
}
Note: this is untested, maybe off by 1 for the indexing of i.
I have two arrays fetch from web servers, both only contains same numbers of dictionaries. i want to parse every dictionary in two nested for each loops, so used following code:
for (NSDictionary *subscription in feedsArray)
{
for (NSDictionary *unreadCount in unreadCountsArray)
{
[RDInsertObjects insertFeedsWithSubscription:subscription
unreadCount:unreadCount];
}
}
But the results returned isn't me wanted, the inner for loop seemed executed over many times, anyone can tell me how exactly do right things to make this code make sense?
The way you do it, for each single iteration of the first loop the second loop iterates completely.
I think it won't work with a for-in loop. But you said the number of items in the two arrays is the same - so you can easily do:
for (i=0; i< feedsArray.count; i++) {
NSDictionary subscription = feedsArray[i];
NSDictionary unreadCount = unreadCountsArray[i];
[RDInsertObjects insertFeedsWithSubscription: subscription unreadCount: unreadCount];
}
This will only work, if the number of items in the array are always ever the same - if sometime they aren't, you need a modification to prevent an out-of-bounds error or it will crash!