streamStatus as NSStreamStatusAtEnd - ios

What may be the reason for getting streamStatus as NSStreamStatusAtEnd for NSOutputStream?
if(self.outputStream.streamStatus == NSStreamStatusAtEnd)
{
// why this condition is true?
}

Related

Problems with list manipulation in Swift after iOS update 14.4.2

For some years, I use this simple code to read and manipulate a list in Swift:
if (Helper.hasSubscription()) {
self.allVisitedTrackHandles = Database.getAllCompletedTrackHandles(withDeleted: false, userid: self.userid)
if (self.allVisitedTrackHandles.count > 0) {
var counter = 0
for th: TrackHandle in self.allTrackHandles {
if self.allVisitedTrackHandles.contains(where: { $0.trackid == th.trackid }) {
for thv: TrackHandle in self.allVisitedTrackHandles {
if thv.trackid == th.trackid {
self.allTrackHandles[counter].date_in_milliseconds = thv.date_in_milliseconds
break
}
}
self.allTrackHandles[counter].visited = 1
}
counter += 1
}
}
}
After updating my iOS device to iOS 14.4.2, app is crashing on this line:
for th: TrackHandle in self.allTrackHandles
Only feedback Xcode gives me is this: Thread 79: EXC_BAD_ACCESS (code=1, address=0x12f100010)
I don't know why that line would suddenly start crashing; There is nothing in the code shown that would cause the crash. Are you updating the array somewhere else? Is this, perhaps, a threading issue?
You can refactor this code to make it simpler, clearer and more efficient. This may help;
if Helper.hasSubscription() {
self.allVisitedTrackHandles = Database.getAllCompletedTrackHandles(withDeleted: false, userid: self.userid)
if !self.allVisitedTrackHandles.isEmpty {
for index in 0..<self.allTrackHandles.count {
if let visited = self.allVisitedTrackHandles.first { $0.track id == self.allTrackHandles[index].track id } {
self.allTrackHandles[index].date_in_milliseconds = visited.date_in_milliseconds
}
self.allTrackHandles[index].visited = 1
}
}
}

OrderClosePrice returns a price different from the history pool

When closing a (selected) existing order with the api, and in that moment I try to get the closing price, sometimes (Perhaps one out of ten times) returns a price diferent from the one I can see in the history pool.
The code is something like this:
RefreshRates();
if(type == OP_BUY)
{
currentPrice = NormalizeDouble(MarketInfo(symbol, MODE_ASK), vdigits);
}
else if(type == OP_SELL)
{
currentPrice = NormalizeDouble(MarketInfo(symbol, MODE_BID), vdigits);
}
if (meetsRequirementsToClose(currentPrice))
{
desiredPrice = currentPrice;
// And then....
bool retVal = OrderClose(OrderTicket(), numLots, desiredPrice, currSlippage);
if (retVal)
{
this.reportClosePrice (myOrderId, OrderClosePrice(), desiredPrice, numLots, "closing");
return true;
}
}
The order was previously selected using SELECT_BY_POS in the pool MODE_TRADES.
anyone knows how to fix it?
Edited:
We have a broker that sometimes respects the requested price... sometimes not.
Disregarding the fact that we have to change broker for a more reliable one, we cannot rely on the requested price.
The deviation we see is greater than one hundred points, both for better and for worse prices than the real ones.
As sugested by #TheLastStark, the problem is solved selecting the order by its ticket just before closing.
The final code is something like:
RefreshRates();
if(type == OP_BUY)
{
currentPrice = NormalizeDouble(MarketInfo(symbol, MODE_ASK), vdigits);
}
else if(type == OP_SELL)
{
currentPrice = NormalizeDouble(MarketInfo(symbol, MODE_BID), vdigits);
}
if (meetsRequirementsToClose(currentPrice))
{
desiredPrice = currentPrice;
// And then....
int tickNum = OrderTicket();
bool retVal = OrderClose(OrderTicket(), numLots, desiredPrice, currSlippage);
if (retVal)
{
if (OrderSelect(tickNum,SELECT_BY_TICKET,MODE_HISTORY)== false)
{
//this.logger.error ("Error selecting the order");
this.reportClosePrice (myOrderId, -1, desiredPrice, numLots, "closing");
}
else
{
this.reportClosePrice (myOrderId, OrderClosePrice(), desiredPrice, numLots, "closing");
}
return true;
}
}

Swift if condition fails

Swift if statement works fine on all other devices but the iPhone 4S with iOS 9.2.1.
This is the set of code I am using:
I am printing a bool value above, before applying the condition, and it prints 0, but the compiler jumps directly to the else part, failing the if statement.
print(NSNumber.init(value: socketListener!.isConnected)) //prints 0
if socketListener!.isConnected == false {
// skipped
} else {
// executed
}
I would suggest you go the long, but the correct one, by unwrapping your socket listener optional, or you can even go directly with the long unwrapping:
guard let isConnected = socketListener.isConnected else { return }
print(NSNumber.init(value: isConnected)) //prints 0
if isConnected == false {
// Your code
} else {
// Your code
}

Including the max and offset criteria inside GORM criteriaBuilder returns an error

Can I make this code shorter?
if(count == null && from = null) {
creditAdviceList = CreditAdvice.findAll {
ilike('id', "%$idFilter%")
.....
ilike('statusCode', statusCodeFilter)
}
}
else if(count != null && from == null) {
creditAdviceList = CreditAdvice.findAll(max: count) {
ilike('id', "%$idFilter%")
.....
ilike('statusCode', statusCodeFilter)
}
}
else if(count == null && from != null) {
creditAdviceList = CreditAdvice.findAll(offset: from) {
ilike('id', "%$idFilter%")
.....
ilike('statusCode', statusCodeFilter)
}
}
else if(count != null && from != null) {
creditAdviceList = CreditAdvice.findAll(max: count, offset: from) {
ilike('id', "%$idFilter%")
.....
ilike('statusCode', statusCodeFilter)
}
}
You see, its a series if statement for each possible scenario. Imagine if one would to use also order and cache in the parameter- there will be basically 16 unique if statements!
I've tried this [more] shorter code:
creditAdviceList = CreditAdvice.findAll {
ilike('id', "%$idFilter%")
.....
ilike('statusCode', statusCodeFilter)
if(count != null) {
maxResults(count)
}
if(from != null) {
firstResult(from)
}
}
But it gives me an error:
...No signature of method: grails.gorm.DetachedCriteria.maxResults() is applicable for argument types: (java.lang.Integer)...
I tried to convert offset to int, Integer, String, etc. I also omit the if statement inside the criteria, but the same error message occur.
findAll with a closure passed is using a DetachedCriteria internally, which is not the same as the result you would get from createCriteria mentioned in the docs. If groovy would find "something close" enough, it would tell you in the error message. The easiest way to deal with your max/from demands would be with simply with a map (which is the first argument passed). E.g.:
def qcfg = [:]
if (count) {
qcfg.count = count
}
if (from) {
qcfg.offset = from
}
creditAdviceList = CreditAdvice.findAll(qcfg) { ... }
mix, match, extract, shorten as you see fit
As far as I see, the only difference is the pagination options. If my eyes are not tricking me, yes, you can:
Map paginationArgs = [max: count, offset: from].findAll {
it.value != null
}
List<CreditAdvice> creditAdviceList = CreditAdvice.findAll(paginationArgs) {
ilike('id', "%$idFilter%")
.....
ilike('statusCode', statusCodeFilter)
}
You can style it differently, but basically you can build the pagination arguments first, and pass them to the findAll. No duplicated code, clearer responsability of the conditions. To clarify, I'm adding all the options and then filtering them to exclude the ones that are null.

Issue with DevExpress XtraTabControl

I am having a DevExpress XtraTabControl with 3 XtraTabPages.
I am trying to remove a Tabpage based on a condition and after removing for the last iteration,it is getting error.
My Code is
foreach (DevExpress.XtraTab.XtraTabPage ptp in tabContactsDetails.TabPages)
{
if (tabContactsDetails.TabPages.Contains(ptp))
{
if (ptp.Name == "tabPTP")
{
if (maxid == String.Empty || maxid == null || maxid == "lblHiddenDebtorID")
{
tabContactsDetails.TabPages.Remove(ptp);
}
else
{
}
}
}
}
and I am getting an error like
Collection was modified; enumeration operation may not execute.
You cannot change a collection while iterating through it!
What I do is the following:
List<XtraTabPage> tabPagesToBeRemoved = new List<XtraTabPage>();
foreach (XtraTabPage ptp in tabContactsDetails.TabPages)
{
if (shouldBeRemoved())
{
tabPagesToBeRemoved.Add(ptp);
}
}
foreach (XtraTabPage pageToBeRemoved in tabPagesToBeRemoved)
{
tabContactsDetails.TabPages.Remove(pageToBeRemoved);
}

Resources