Swift For In loop not maintaining variable value in Archive - ios

I have a piece of code that works fine when deployed via Xcode directly onto the device but if I install the application via an adhoc archive it fails miserably.
This is the code, it is full of log statements as I wasn't able to utilise the debugger so I had to rely on the console output to work out what was happening.
var status: ShipmentStatus = ShipmentStatus.NOT_READY
let stopOrders = getStopOrders(true)
for order in stopOrders{
NSLog("Beginning Loop Shipment Status = %d", status.toRaw())
let stopStatus = order.getStopOrderStatus()
NSLog("%d Stop Status = %d", order.salesOrderHeader.salesOrderNo, stopStatus.toRaw())
if(stopStatus == StopOrderStatus.READY_FOR_PICKING || stopStatus == StopOrderStatus.PARTIALLY_PICKED){
return ShipmentStatus.READY_FOR_PICKING
} else if(stopStatus == StopOrderStatus.PICKING_COMPLETE){
status = ShipmentStatus.PICKING_COMPLETE
NSLog("Shipment Status = %d", status.toRaw())
} else if(stopStatus == StopOrderStatus.READY_FOR_DELIVERY || stopStatus == StopOrderStatus.PARTIALLY_DELIVERED){
if(status != ShipmentStatus.PICKING_COMPLETE){
status = ShipmentStatus.READY_FOR_DELIVERY
NSLog("Shipment Status = %d", status.toRaw())
} else {
NSLog("Shipment Status is not changed")
}
} else if(stopStatus == StopOrderStatus.DELIVERY_COMPLETE){
if(status != ShipmentStatus.PICKING_COMPLETE && status != ShipmentStatus.READY_FOR_DELIVERY){
status = ShipmentStatus.DELIVERY_COMPLETE
NSLog("Shipment Status = %d", status.toRaw())
} else {
NSLog("Shipment Status is not changed")
}
}
}
NSLog("Return Shipment Status = %d", status.toRaw())
return status
The issue is that unless the first condition is matched (ie it returns the value as part of the loop) the variable status is always equal to ShipmentStatus.NOT_READY. If I check the logs I can see that at every loop iteration status is also equal to ShipmentStatus.NOT_READY but I can also see in the console that it is being set correctly during the iteration. So it seems to be treating the variable as if it has been declared inside the loop and creating a new copy for every iteration.
As I mentioned this only occurs if the project is bundled up into an archive and deployed over the air. When deployed directly onto the device the code works as expected. This happens on both iOS 7.1.2 and iOS 8. I have just tested using Xcode 6 GM and the issue still exists.
Has anyone seen behaviour like this in their code? The strange thing is I have other code which follows a similar pattern and it appears to be returning the expected value.
================
Just for clarification, this is the log output that I see when deployed using Xcode
[7454:60b] Beginning Loop Shipment Status = 0
[7454:60b] 10000221 Stop Status = 70
[7454:60b] Shipment Status = 60
[7454:60b] Beginning Loop Shipment Status = 60
[7454:60b] 10000222 Stop Status = 70
[7454:60b] Shipment Status = 60
[7454:60b] Beginning Loop Shipment Status = 60
[7454:60b] 10000223 Stop Status = 70
[7454:60b] Shipment Status = 60
[7454:60b] Return Shipment Status = 60
And when it is deployed via an archive the result is
<Warning>: Beginning Loop Shipment Status = 0
<Warning>: 10000221 Stop Status = 70
<Warning>: Shipment Status = 60
<Warning>: Beginning Loop Shipment Status = 0
<Warning>: 10000222 Stop Status = 70
<Warning>: Shipment Status = 60
<Warning>: Beginning Loop Shipment Status = 0
<Warning>: 10000223 Stop Status = 70
<Warning>: Shipment Status = 60
<Warning>: Return Shipment Status = 0

OK, problem resolved but using what I would consider a workaround as I assume that because of the nature of the issue and the fact that it doesn't cause an issue when the app is deployed via Xcode that this a bug in the package builder.
The enum definition for ShipmentStatus was defined in the same Swift file as this function. So I moved the enum into a separate file and hey presto, the issue goes away.

Related

Offlineimap stops retrieving after first 20-30 messages

I have been trying to set up offlineimap to sync mail from gmail to the local folders on my mac machine.
The issue with my current set-up is that, offlineimap will start to sync the mail from both accounts, I can see lines like -
Copy message 3 (3 of 10966) repo1_remote:[Gmail]/Important -> repo1_local
But, after around 20-30 copy message, these lines just stop. Offlineimap is still connected though, it refreshes after 10 minutes and syncs again but, I cant see any more copy message lines in the repos any longer, it just stops. I can see these new 20-30 new messages in mutt, but not more. Killing and restarting offlineimap agains copies 20-30 new messages and again stops. I have no clue as to what is wrong. I guess it should copy all messages locally. Here is my offlineimaprc. I have the python file set up correctly.
[general]
metadata = ~/.offlineimap
accounts = repo1, repo2
maxsyncaccounts = 10
#ui = blinkenlights
ui = ttyui
pythonfile = ~/Development/OfflineIMAP/mail/offlineimap.py
#socktimeout = 60
[mbnames]
[Account repo2]
localrepository = repo2_local
remoterepository = repo2_remote
autorefresh = 10
status_backend = sqlite
synclabels = yes
[Account repo1]
localrepository = repo1_local
remoterepository = repo1_remote
autorefresh = 10
status_backend = sqlite
synclabels = yes
[Repository repo2_local]
type = GmailMaildir
nametrans = get_remote_name
localfolders = ~/Development/OfflineIMAP/mail/repo2
sep = /
restoreatime = yes
[Repository repo1_local]
type = GmailMaildir
nametrans = get_remote_name
localfolders = ~/Development/OfflineIMAP/mail/repo1
sep = /
restoreatime = yes
[Repository repo2_remote]
type = Gmail
folderfilter = is_included
nametrans = get_local_name
cert_fingerprint = 3ffdb8519c1c8242ce8387d3d9fccc208a776b4a
remoteuser = asd#gmail.com
remotepasseval = get_password('asd')
usecompression = yes
maxconnections = 3
[Repository repo1_remote]
type = Gmail
folderfilter = is_included
nametrans = get_local_name
cert_fingerprint = 3ffdb8519c1c8242ce8387d3d9fccc208a776b4a
remoteuser = qwe#gmail.com
remotepasseval = get_password('qwe')
usecompression = yes
maxconnections = 3
I would like to know what is preventing offlineimap from copying further messages and what should I change in the config to make it work properly.
I've just recently ran into the same problem with gmail. In my case disabling compression and setting connections limit to 1 resolved the issue (didn't have time to investigate fully). Have you tried doing this?

I get this error, how would i fix it?

//if day is sat/sun, set value to W. calendar.set(year,monthNumberForCalendar,dayOfMonth) if(contract.workingDays.id == mondayToFriday.id)
{
if(calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY){ monthMap.put(dayOfMonth, "W")
URI
/oulhr/leaveView/show
Class
java.lang.NullPointerException
Message
Cannot get property 'id' on null object
//leaveMonths = this.getLeaveMonths(year)
def employeeContract = new Contract()
employeeContract = this.getCurrentContract(employee) leaveMonths = this.getLeaveMonths(year,employeeContract)
/*add leave days to month(e.g Jan). When jan is filled up, add to the following month(.e.g Feb) */
int monthNumber = 0;
The error message is clear.
This is happening because of either workingDays or mondayToFriday is null.
To confidently say:
contract.workingDays.id = mondayToFriday.id
You have to first make sure that contract, contract.workingDays, mondayToFriday are not null.

How do you dynamically add new instruments to AUGraph

I am currently making a music app where you can add new instruments as tracks to the music sequnce.
Here's what I have for when a new track has been added:
MusicPlayerStop(_musicPlayer);
status = MusicSequenceNewTrack(sequence, &tracks[tracksCount]);
timeDiff = 32.f/_tempo;
[self setLoopDuration:currentLoopDuration forPattern:tracks[tracksCount]];
AudioComponentDescription samplerNodeDesc;
samplerNodeDesc.componentManufacturer = (OSType)kAudioUnitManufacturer_Apple;
samplerNodeDesc.componentType = (OSType)kAudioUnitType_MusicDevice;
samplerNodeDesc.componentSubType = (OSType)kAudioUnitSubType_Sampler;
samplerNodeDesc.componentFlags = 0;
samplerNodeDesc.componentFlagsMask = 0;
status = AUGraphAddNode(graph, &samplerNodeDesc, &auNodes[tracksCount]);
status = AUGraphNodeInfo(graph, auNodes[tracksCount], 0, &audioUnits[tracksCount]);
status = AUGraphConnectNodeInput(graph, auNodes[tracksCount], 0, filterNode, 0);
status = MusicTrackSetDestNode(tracks[tracksCount], auNodes[tracksCount]);
int trackId = tracksCount;
tracksCount++;
MusicPlayerStart(_musicPlayer);
return trackId;
The following doesn't produce audio at all, what can I Do here please.
Thanks so much !
You need to call AUGraphUpdate(graph, nil); Or if you want the graph to block until it has ben added you supply it with a pointer to a Boolean and the calling thread will wait for the audio thread to add the audio unit.
Boolean updated;
AUGraphUpdate(graph, &updated); //will block until end of next audio cycle
if (updated){
printf("hooray\n");
}

Send sms using kannel & smmpsim

I'm trying to send sms using kannel & smppsim.
I use docker as container.
I use this kannel.conf:
group = core
admin-port = 13000
smsbox-port = 13001
admin-password = bar
admin-allow-ip = "127.0.0.1;192.168.59.103"
box-allow-ip = "127.0.0.1;192.168.59.103"
group = smsc
smsc = smpp
smsc-id = SMPPSim
host = 192.168.59.103
port = 2775
transceiver-mode = 1
smsc-username = smppclient1
smsc-password = password
system-type = 'VMA'
#service-type = 'test'
interface-version = 34
#system-id = smppclient
preferred-smsc-id = SMPPSim
connect-allow-ip = 192.168.59.103
group = smsbox
bearerbox-host = bearerbox
sendsms-port = 13013
global-sender = 13013
group = sendsms-user
username = tester
password = foobar
group = sms-service
keyword = default
text = "No service specified"
when sending a request to send sms I get "0: Accepted for delivery"
I'm seeing these errors in smsbox log:
2015-03-21 20:20:52 [1] [3] DEBUG: Status: 202 Answer: <Sent.>
2015-03-21 20:20:52 [1] [3] DEBUG: Delayed reply - wait for bearerbox
2015-03-21 20:20:52 [1] [0] DEBUG: Got ACK (0) of 74f9cefe-db95-4b7d-aa99-f07395d32915
2015-03-21 20:20:52 [1] [0] DEBUG: HTTP: Resetting HTTPClient for `192.168.59.3'.
2015-03-21 20:20:52 [1] [1] ERROR: Error reading from fd 24:
2015-03-21 20:20:52 [1] [1] ERROR: System error 104: Connection reset by peer
2015-03-21 20:20:52 [1] [1] DEBUG: HTTP: Destroying HTTPClient area 0x7fe8d0000ad0.
Bearbox doesn't present any errors and seem to pass the message to smppsim, smppsim shows this in log:
21 Assessing state of 1 messages in the OutboundQueue
21 Message:2 state=DELIVERED
The sms is not sent, what could be wrong?
I think its a problem with your Kannel configuration file, specially with smsbox and later parts. I used following as smsbox
group = smsbox
bearerbox-host = 127.0.0.1
sendsms-port = 13013
global-sender = your sim number which you use in USB modem
sendsms-chars = "0123456789 +-"
log-file = "/var/log/kannel/smsbox.log"
log-level = 0
access-log = "/var/log/kannel/access.log"
and you can get my full configuration file from here. This worked fine for me.
This might be a problem of lоѕѕ оf thе соnnесtіоn оn thе rеmоtе ѕосkеt due tо а tіmеоut.
And SMPPSim is just a testing tool for kannel. It won't really send a message to your or mentioned mobile number. To send real messages you need to add either gsm modems or SMS operator details.
You can refer to userGuide from kannel.org.
To check your kannel status simply go to http://localhost:13000/status?password=password(password of your kannel)

removeAtIndex() not working on Swift array

I have a Swift n00b question.
I'm having a hard time understanding why I cannot remove an element from an array.
I first filter it twice to contain only the values I need:
let filteredShowtimes = movieShowtimes.filter{$0.dateTime.laterDate(newStartTime!).isEqualToDate($0.dateTime)}
var furtherFilteredShowtimes = filteredShowtimes.filter{$0.endTime.earlierDate(endTime!).isEqualToDate($0.endTime)}
And, down the line, inside a while loop that depends on the size of the array - but doesn't iterate over it or modify it - I try removing the first element like so:
furtherFilteredShowtimes.removeAtIndex(0)
But the element count remains the same.
Any idea what I'm missing?
Here's the whole code:
while(furtherFilteredShowtimes.count > 0) {
println("showtime \(furtherFilteredShowtimes.first!.dateTime)")
//if the start time of the movie is after the start of the time period, and its end before
//the requested end time
if (newStartTime!.compare(furtherFilteredShowtimes.first!.dateTime) == NSComparisonResult.OrderedAscending) && (endTime!.compare(furtherFilteredShowtimes.first!.endTime) == NSComparisonResult.OrderedDescending) {
let interval = 1200 as NSTimeInterval
//if the matching screenings dict already contains one movie,
//make sure the next one starts within 20 min of the previous
//one
if(theaterMovies.count > 1 && endTime!.timeIntervalSinceDate(newStartTime!) < interval {
//add movie to the matching screenings dictionary
println("we have a match with \(movies[currentMovie.row].title)")
theaterMovies[furtherFilteredShowtimes.first!.dateTime] = movies[currentMovie.row].title
//set the new start time for after the added movie ends
newStartTime = movieShowtimes.first!.endTime
//stop looking for screenings for this movie
break
}
else if(theaterMovies.count == 0) {
//add movie to the matching screenings dictionary
theaterMovies[furtherFilteredShowtimes.first!.dateTime] = movies[currentMovie.row].title
println("we have a new itinerary with \(movies[currentMovie.row].title)")
//set the new start time for after the added movie ends
newStartTime = furtherFilteredShowtimes.first!.endTime
//stop looking for screenings for this movie
break
}
}
else { //if the showtime doesn't fit, remove it from the list
println("removing showtime \(furtherFilteredShowtimes.first!.dateTime)")
furtherFilteredShowtimes.removeAtIndex(0)
}
}
You only say removeAtIndex(0) in one place, in an else.
So if it doesn't happen, that means that line is never being executed because the else is not executed - the if is executed instead.
And you break at the end of each if, so that's the end of the while loop!
In other words, let's pretend that the first two nested if conditions succeed. Your structure is like this:
while(furtherFilteredShowtimes.count > 0) {
if (something) {
if (somethingelse) {
break
break means jump out of the while, so if those two if conditions succeed, that's the end! We never loop. We certainly will never get to the removeAtIndex().

Resources