NSUserDefaults only loads correctly half of the time - ios

I am currently creating an app with Swift2 that stores user entered data. Right now I am just using NSUserDefaults even though I will be using an external DB in the future.
With my current implementation, I have 2 Dictionaries stored to NSUserDefaults. "allNouns", "myNouns", and "nounTimes". When I load my app, the data only loads every other time. I have my code to get the data and the log print outs below.
func saveObject(object: AnyObject, objectKey: String) {
let objectData = NSKeyedArchiver.archivedDataWithRootObject(object)
NSUserDefaults.standardUserDefaults().setObject(objectData, forKey: objectKey)
}
func loadObject(objectKey: String) -> AnyObject? {
var object : AnyObject? = nil
if( NSUserDefaults.standardUserDefaults().objectForKey(objectKey) != nil ) {
let objectData = NSUserDefaults.standardUserDefaults().objectForKey(objectKey) as? NSData
if let objectData = objectData {
object = NSKeyedUnarchiver.unarchiveObjectWithData(objectData)!
}
}
return object
}
override func viewDidLoad() {
super.viewDidLoad()
if( NSUserDefaults.standardUserDefaults().objectForKey("allNouns") != nil ) {
allNouns = loadObject("allNouns") as! [Int : Noun]
allNounIdList = Array(allNouns.keys)
}
if( NSUserDefaults.standardUserDefaults().objectForKey("myNouns") != nil ) {
myNouns = loadObject("myNouns") as! [Int : [NSDate]]
myNounIdList = Array(myNouns.keys)
}
}
Here are all the places I save data:
func stashNoun(nounId: Int) {
let myNounTimes = myNouns[nounId]
if( myNounTimes == nil || myNounTimes!.isEmpty ) {
myNouns[nounId] = [ NSDate() ]
myNounIdList.append(nounId)
}
else {
myNouns[nounId]!.append(NSDate())
}
saveObject(myNouns, objectKey: "my")
}
#IBAction func addButtonClicked(sender: AnyObject) {
let newNoun = Noun(name: nameTextField, type: typeTextField, year: yearTextField)
allNouns[newNoun.id] = newNoun
allNounIdList.append(newNoun.id)
saveObject(allNouns, objectKey: "allNouns")
}
Here is a log of when I have data:
["AppleKeyboards": (
"en_US#hw=US;sw=QWERTY",
"emoji#sw=Emoji",
"en_US#hw=US;sw=QWERTY"
), "allNouns": <62706c69 73743030 d4010203 04050665 66582476 65727369 6f6e5824 6f626a65 63747359 24617263 68697665 72542474 6f701200 0186a0af 10130708 1718191a 1b292a31 3f404e4f 50515260 6155246e 756c6cd3 090a0b0c 1116574e 532e6b65 79735a4e 532e6f62 6a656374 73562463 6c617373 a40d0e0f 10800280 03800480 05a41213 14158006 8009800b 80108012 13688188 08c2d54a e71391c9 681dc633 746913ce dfdb57f5 78a12113 cddfb115 bd62466c d71c1d0b 1e1f2021 22222425 26222256 72656769 6f6e5563 6f6c6f72 52696454 79656172 54747970 65546e61 6d658007 80078008 13688188 08c2d54a e7100380 07800751 63d22b2c 2d2e5a24 636c6173 736e616d 65582463 6c617373 65735e43 6f726b53 74617368 2e57696e 65a22f30 5e436f72 6b537461 73682e57 696e6558 4e534f62 6a656374 d732330b 34353637 3838243b 3c383856 72656769 6f6e5563 6f6c6f72 52696454 79656172 54747970 65546e61 6d65800a 800a8008 1391c968 1dc63374 69100280 0a800a51 62d74142 0b434445 46474824 4a4b4c4d 56726567 696f6e55 636f6c6f 72526964 54796561 72547479 7065546e 616d6580 0e800f80 0813cedf db57f578 a1211107 c5800d80 0c5f101a 696c6927 73207375 70657220 64656c69 63696f75 73207769 6e655c70 696e6f74 20677269 67696f5a 41757374 72616c69 616e5577 68697465 d753540b 55565758 5959245c 5d595956 72656769 6f6e5563 6f6c6f72 52696454 79656172 54747970 65546e61 6d658011 80118008 13cddfb1 15bd6246 6c100180 11801151 61d22b2c 62635c4e 53446963 74696f6e 617279a2 64305c4e 53446963 74696f6e 6172795f 100f4e53 4b657965 64417263 68697665 72d16768 54726f6f 74800100 08001100 1a002300 2d003200 37004d00 53005a00 62006d00 74007900 7b007d00 7f008100 86008800 8a008c00 8e009000 9900a200 ab00b400 c300ca00 d000d300 d800dd00 e200e400 e600e800 f100f300 f500f700 f900fe01 09011201 21012401 33013c01 4b015201 58015b01 60016501 6a016c01 6e017001 79017b01 7d017f01 81019001 97019d01 a001a501 aa01af01 b101b301 b501be01 c101c301 c501e201 ef01fa02 00020f02 16021c02 1f022402 29022e02 30023202 34023d02 3f024102 43024502 4a025702 5a026702 79027c02 81000000 00000002 01000000 00000000 69000000 00000000 00000000 00000002 83>, "AppleKeyboardsExpanded": 1, "AddingEmojiKeybordHandled": 1, "AppleLanguages": (
"en-US"
), "ApplePasscodeKeyboards": (
"en_US"
), "nounTimes": <62706c69 73743030 d4010203 0405063f 40582476 65727369 6f6e5824 6f626a65 63747359 24617263 68697665 72542474 6f701200 0186a0af 100f0708 15161718 1d21272a 2d313438 3b55246e 756c6cd3 090a0b0c 1014574e 532e6b65 79735a4e 532e6f62 6a656374 73562463 6c617373 a30d0e0f 80028003 8004a311 12138005 800a800c 800e1368 818808c2 d54ae713 cddfb115 bd62466c 13cedfdb 57f578a1 21d20a0b 191ca21a 1b800680 088009d2 1e0b1f20 574e532e 74696d65 2341bbaa 1eb23666 778007d2 22232425 5a24636c 6173736e 616d6558 24636c61 73736573 564e5344 617465a2 2426584e 534f626a 656374d2 1e0b2820 2341bbab 0aa3ea33 6a8007d2 22232b2c 574e5341 72726179 a22b26d2 0a0b2e1c a12f800b 8009d21e 0b322023 41bbaa1c 3b5fcfc4 8007d20a 0b351ca1 36800d80 09d21e0b 39202341 bbab0a88 d0ea0780 07d22223 3c3d5c4e 53446963 74696f6e 617279a2 3e265c4e 53446963 74696f6e 6172795f 100f4e53 4b657965 64417263 68697665 72d14142 54726f6f 74800100 08001100 1a002300 2d003200 37004900 4f005600 5e006900 70007400 76007800 7a007e00 80008200 84008600 8f009800 a100a600 a900ab00 ad00af00 b400bc00 c500c700 cc00d700 e000e700 ea00f300 f8010101 03010801 10011301 18011a01 1c011e01 23012c01 2e013301 35013701 39013e01 47014901 4e015b01 5e016b01 7d018001 85000000 00000002 01000000 00000000 43000000 00000000 00000000 00000001 87>, "AppleLocale": en_US, "NSInterfaceStyle": macintosh, "MSVLoggingMasterSwitchEnabledKey": 0, "NSLanguages": (
"en-US",
en
), "AppleITunesStoreItemKinds": (
audiobook,
"tv-episode",
booklet,
software,
"software-update",
"itunes-u",
ringtone,
"tv-season",
movie,
mix,
newsstand,
song,
wemix,
tone,
artist,
"podcast-episode",
podcast,
document,
eBook,
album,
"music-video"
), "AppleLanguagesDidMigrate": 9.0, "myNouns": <62706c69 73743030 d4010203 04050653 54582476 65727369 6f6e5824 6f626a65 63747359 24617263 68697665 72542474 6f701200 0186a0af 10100708 15161718 26272e3c 3d4b4c4d 4e4f5524 6e756c6c d3090a0b 0c101457 4e532e6b 6579735a 4e532e6f 626a6563 74735624 636c6173 73a30d0e 0f800280 038004a3 11121380 05800880 0a800f13 68818808 c2d54ae7 13cddfb1 15bd6246 6c13cedf db57f578 a121d719 1a0b1b1c 1d1e1f1f 2122231f 1f567265 67696f6e 55636f6c 6f725269 64547965 61725474 79706554 6e616d65 80068006 80071368 818808c2 d54ae710 03800680 065163d2 28292a2b 5a24636c 6173736e 616d6558 24636c61 73736573 5e436f72 6b537461 73682e57 696e65a2 2c2d5e43 6f726b53 74617368 2e57696e 65584e53 4f626a65 6374d72f 300b3132 33343535 21383935 35567265 67696f6e 55636f6c 6f725269 64547965 61725474 79706554 6e616d65 80098009 800713cd dfb115bd 62466c10 01800980 095161d7 3e3f0b40 41424344 45214748 494a5672 6567696f 6e55636f 6c6f7252 69645479 65617254 74797065 546e616d 65800d80 0e800713 cedfdb57 f578a121 1107c580 0c800b5f 101a696c 69277320 73757065 72206465 6c696369 6f757320 77696e65 5c70696e 6f742067 72696769 6f5a4175 73747261 6c69616e 55776869 7465d228 2950515c 4e534469 6374696f 6e617279 a2522d5c 4e534469 6374696f 6e617279 5f100f4e 534b6579 65644172 63686976 6572d155 5654726f 6f748001 00080011 001a0023 002d0032 0037004a 00500057 005f006a 00710075 00770079 007b007f 00810083 00850087 00900099 00a200b1 00b800be 00c100c6 00cb00d0 00d200d4 00d600df 00e100e3 00e500e7 00ec00f7 0100010f 01120121 012a0139 01400146 0149014e 01530158 015a015c 015e0167 0169016b 016d016f 017e0185 018b018e 01930198 019d019f 01a101a3 01ac01af 01b101b3 01d001dd 01e801ee 01f30200 02030210 02220225 022a0000 00000000 02010000 00000000 00570000 00000000 00000000 00000000 022c>]
Here is when it does not have my data saved:
["AppleLocale": en_US, "NSInterfaceStyle": macintosh, "MSVLoggingMasterSwitchEnabledKey": 0, "NSLanguages": (
"en-US",
en
), "AppleKeyboards": (
"en_US#hw=US;sw=QWERTY",
"emoji#sw=Emoji",
"en_US#hw=US;sw=QWERTY"
), "AppleKeyboardsExpanded": 1, "AppleITunesStoreItemKinds": (
audiobook,
"tv-episode",
booklet,
software,
"software-update",
"itunes-u",
ringtone,
"tv-season",
movie,
mix,
newsstand,
song,
wemix,
tone,
artist,
"podcast-episode",
podcast,
document,
eBook,
album,
"music-video"
), "AddingEmojiKeybordHandled": 1, "AppleLanguagesDidMigrate": 9.0, "AppleLanguages": (
"en-US"
), "ApplePasscodeKeyboards": (
"en_US"
)]

When you're done sending the data to NSUserDefaults you must call synchronize from its instance to be sure that your data was persisted. Otherwise your data may not be persisted in a timely fashion (the app may be terminated before this call is made automatically).
Check the documentation.

Related

Can't access a property in a Struct

I have the struct Subsection, like so:
struct Subsection: Decodable {
let subsectionName: String
let subsectionID: Int
}
That is a type in another class MenuInfo, like so:
struct MenuInfo: Decodable {
let subsections: [Subsection]
let menuItems: [MenuItem]
}
Which finally is used inside another struct RestaurantInfo, like so:
struct RestaurantInfo: Decodable {
let restaurantName: String
let menuInfo: MenuInfo
enum CodingKeys: String, CodingKey {
case restaurantName = "restaurant_name"
case menuInfo
}
}
I created a mock constant:
let restaurantMenuInfo = RestaurantInfo(
restaurantName: "SUBWAY",
menuInfo: MenuInfo(
subsections: [
Subsection(subsectionName: "SANDWICHES", subsectionID: 1),
Subsection(subsectionName: "DRINKS", subsectionID: 2),
Subsection(subsectionName: "DESSERTS", subsectionID: 3)
],
menuItems: [
MenuItem(menuItemName: "Chicken Sandwich", menuItemDescription: "Bread / Chicken Filé / Cheese", menuItemPrice: 9.99, subsection: 1),
MenuItem(menuItemName: "BLT", menuItemDescription: "Bread / Bacon / Lettuce / Tomatoes", menuItemPrice: 12.99, subsection: 1),
MenuItem(menuItemName: "BBQ sandwich", menuItemDescription: "Garlix Bread / BBQ Sauce / Roast Beef", menuItemPrice: 14.99, subsection: 1),
MenuItem(menuItemName: "Veggie Burger", menuItemDescription: "Bread / Soy Meat / Pickles", menuItemPrice: 17.99, subsection: 1),
MenuItem(menuItemName: "Mountain Dew", menuItemDescription: "Lemon / Raspberry / Grape", menuItemPrice: 2.99, subsection: 2),
MenuItem(menuItemName: "Iced Tea", menuItemDescription: "Tea with Lemon", menuItemPrice: 3.99, subsection: 2),
MenuItem(menuItemName: "Cookie", menuItemDescription: "Chocolate Chip Cookie", menuItemPrice: 1.99, subsection: 3),
MenuItem(menuItemName: "Cheese Cake", menuItemDescription: "Cheese cake / Blueberry", menuItemPrice: 5.99, subsection: 3),
MenuItem(menuItemName: "Chips", menuItemDescription: "Potato chips", menuItemPrice: 2.99, subsection: 3)
]
)
)
I am trying to get a stack view to load a .xib final with the subsectionName but I can't access the property subsectionName in the ViewController.
func setUpMenuSubsection() {
for subsection in restaurantMenuInfo.menuInfo.subsections.subsectionName {
if let subsectionView = Bundle.main.loadNibNamed("SubsectionView", owner: nil, options: nil)?.first as? SubsectionView {
subsectionView.setUpSubsection(subsection: subsection)
stackSubsections.addArrangedSubview(subsectionView)
}
}
}
But I get the error:
Value of type '[Subsection]' has no member 'subsectionName' on the second line of my function right on ".subsectionName".
The setup of your types is perfectly fine. However, when we look at the loop you are using:
func setUpMenuSubsection() {
for subsection in restaurantMenuInfo.menuInfo.subsections.subsectionName { // <-- this line
if let subsectionView = Bundle.main.loadNibNamed("SubsectionView", owner: nil, options: nil)?.first as? SubsectionView {
subsectionView.setUpSubsection(subsection: subsection)
stackSubsections.addArrangedSubview(subsectionView)
}
}
}
The error is on the marked line. That is because subsections, which is of type [Subsection], does not have a property subsectionName. If you just want to loop over the subsections (which is probably what you want), you can simply remove .subsectionName, and then to access the name of each subsection, inside the loop you would say subsection.subsectionName like so:
func setUpMenuSubsection() {
for subsection in restaurantMenuInfo.menuInfo.subsections {
print(subsection.subsectionName)
}
}
If, however, you want to loop only over the names, and do not care about the subsections themselves, you can do this:
func setUpMenuSubsection() {
for subsectionName in restaurantMenuInfo.menuInfo.subsections.map(\.subsectionName) {
print(subsectionName)
}
}

Connection of varispeed with RemoteIO in iOS

I am working with audio units to play and change the speed of playback. Since AudioGraph is deprecated.
What I have done, I have successfully played Audio coming from UDP via audio-units and made connections like:
converterUnit -> varispeed -> outConverterUnit -> RemoteIO (Out)
Our format for playing is int16(PCM), but varispeed requires float datatype, So we are using converters for varispeed.
Here is my code:
var ioFormat = CAStreamBasicDescription(
sampleRate: 48000.0,
numChannels: 1,
pcmf: .int16,
isInterleaved: false
)
var varispeedFormat = CAStreamBasicDescription(
sampleRate: 16000,
numChannels: 1,
pcmf: .float32,
isInterleaved: false
)
init(_ client: UDPClient, _ tcpClient: TCPClient, _ opusHelper: OpusHelper, _ tvTemp: UILabel) {
super.init()
let success = initCircularBuffer(&circularBuffer, 4096)
if success {
print("Circular buffer init was successful")
} else {
print("Circular buffer init not successful")
}
self.opusHelper = opusHelper
self.tvTemp = tvTemp
monotonicTimer = MonotonicTimer()
self.udpClient = client
self.tcpClient = tcpClient
//Creating Description for REMOTE IO
var outputDesc = AudioComponentDescription(
componentType: OSType(kAudioUnitType_Output),
componentSubType: OSType(kAudioUnitSubType_VoiceProcessingIO),
componentManufacturer: OSType(kAudioUnitManufacturer_Apple),
componentFlags: 0,
componentFlagsMask: 0
)
let inputComponent = AudioComponentFindNext(nil, &outputDesc)
check(error: AudioComponentInstanceNew(inputComponent!, &outputUnit), description: "Output unit instance new failed")
//Creating Description for converterUnit
var firstConverterDesc = AudioComponentDescription(
componentType: OSType(kAudioUnitType_FormatConverter),
componentSubType: OSType(kAudioUnitSubType_AUConverter),
componentManufacturer: OSType(kAudioUnitManufacturer_Apple),
componentFlags: 0,
componentFlagsMask: 0
)
let firstConverterComponent = AudioComponentFindNext(nil, &firstConverterDesc)
check(error: AudioComponentInstanceNew(firstConverterComponent!, &firstConverterUnit), description: "First converter unit instance new failed")
//Creating Description for Varispeed Unit
var variSpeedConverterDesc = AudioComponentDescription(
componentType: OSType(kAudioUnitType_FormatConverter),
componentSubType: OSType(kAudioUnitSubType_Varispeed),
componentManufacturer: OSType(kAudioUnitManufacturer_Apple),
componentFlags: 0,
componentFlagsMask: 0
)
let variSpeedConverterComponent = AudioComponentFindNext(nil, &variSpeedConverterDesc)
check(error: AudioComponentInstanceNew(variSpeedConverterComponent!, &varispeedUnit), description: "First converter unit instance new failed")
//Creating Description for outConverter
var secondConverterDesc = AudioComponentDescription(
componentType: OSType(kAudioUnitType_FormatConverter),
componentSubType: OSType(kAudioUnitSubType_AUConverter),
componentManufacturer: OSType(kAudioUnitManufacturer_Apple),
componentFlags: 0,
componentFlagsMask: 0
)
let secondConverterComponent = AudioComponentFindNext(nil, &secondConverterDesc)
check(error: AudioComponentInstanceNew(secondConverterComponent!, &secondConverterUnit), description: "Second converter unit instance new failed")
//Converting incoming bytes to AUConverter (Float 32 format)
check(error: AudioUnitSetProperty(
firstConverterUnit!,
AudioUnitPropertyID(kAudioUnitProperty_StreamFormat),
AudioUnitScope(kAudioUnitScope_Output),
0,
&varispeedFormat,
MemoryLayoutStride.SizeOf32(varispeedFormat)
),
description: "Failed to set input of second converter to our temp format"
)
//Putting converted bytes in varispeed unit
check(error: AudioUnitSetProperty(
varispeedUnit!,
AudioUnitPropertyID(kAudioUnitProperty_StreamFormat),
AudioUnitScope(kAudioUnitScope_Input),
0,
&varispeedFormat,
MemoryLayoutStride.SizeOf32(varispeedFormat)
),
description: "Failed to set input format as varispeed format of the second converter unit"
)
//Getting converted bytes from varispeed unit
check(error: AudioUnitSetProperty(
varispeedUnit!,
AudioUnitPropertyID(kAudioUnitProperty_StreamFormat),
AudioUnitScope(kAudioUnitScope_Output),
0,
&varispeedFormat,
MemoryLayoutStride.SizeOf32(varispeedFormat)
),
description: "Failed to set input format as varispeed format of the second converter unit"
)
//Putting converted bytes in outConverterUnit
check(error: AudioUnitSetProperty(
secondConverterUnit!,
AudioUnitPropertyID(kAudioUnitProperty_StreamFormat),
AudioUnitScope(kAudioUnitScope_Input),
0,
&varispeedFormat,
MemoryLayoutStride.SizeOf32(varispeedFormat)
),
description: "Failed to set input of second converter to our temp11 format"
)
//Getting converted bytes from outConverterUnit in int16(PCM)
check(error: AudioUnitSetProperty(
secondConverterUnit!,
AudioUnitPropertyID(kAudioUnitProperty_StreamFormat),
AudioUnitScope(kAudioUnitScope_Output),
0,
&ioFormat,
MemoryLayoutStride.SizeOf32(ioFormat)
),
description: "Failed to set input of second converter to our temp11 format"
)
//Connecting firstConverter to varispeed
var tempConnection = AudioUnitConnection(
sourceAudioUnit: firstConverterUnit!,
sourceOutputNumber: 0,
destInputNumber: 0
)
check(error: AudioUnitSetProperty(
varispeedUnit!,
AudioUnitPropertyID(kAudioUnitProperty_MakeConnection),
AudioUnitScope(kAudioUnitScope_Input),
0,
&tempConnection,
MemoryLayoutStride.SizeOf32(AudioUnitConnection())
),
description: "Failed to connect second converter to output Unit"
)
//Connecting verispeedUnit to to outConverter
var temp1Connection = AudioUnitConnection(
sourceAudioUnit: varispeedUnit!,
sourceOutputNumber: 0,
destInputNumber: 0
)
check(error: AudioUnitSetProperty(
secondConverterUnit!,
AudioUnitPropertyID(kAudioUnitProperty_MakeConnection),
AudioUnitScope(kAudioUnitScope_Input),
0,
&temp1Connection,
MemoryLayoutStride.SizeOf32(AudioUnitConnection())
),
description: "Failed to connect second converter to output Unit"
)
//Connecting outConverter to outputUnit
var secondToOutputConnection = AudioUnitConnection(
sourceAudioUnit: secondConverterUnit!,
sourceOutputNumber: 0,
destInputNumber: 0
)
check(error: AudioUnitSetProperty(
outputUnit!,
AudioUnitPropertyID(kAudioUnitProperty_MakeConnection),
AudioUnitScope(kAudioUnitScope_Input),
0,
&secondToOutputConnection,
MemoryLayoutStride.SizeOf32(AudioUnitConnection())
),
description: "Failed to connect second converter to output Unit"
)
check(error: AudioUnitInitialize(outputUnit!), description: "Failed to init output unit")
check(error: AudioUnitInitialize(firstConverterUnit!), description: "Failed to init first converter unit")
check(error: AudioUnitInitialize(varispeedUnit!), description: "Failed to init varispeed unit")
check(error: AudioUnitInitialize(secondConverterUnit!), description: "Failed to init second converter unit")
var playbackCallback = AURenderCallbackStruct(
inputProc: AudioController_PlaybackCallback,
inputProcRefCon: UnsafeMutableRawPointer(Unmanaged.passUnretained(self).toOpaque())
)
check(error: AudioUnitSetProperty(
outputUnit!,
AudioUnitPropertyID(kAudioUnitProperty_SetRenderCallback),
AudioUnitScope(kAudioUnitScope_Input),
kOutputBus,
&playbackCallback,
MemoryLayout<AURenderCallbackStruct>.size.ui
),
description: "Failed to set recording render callback"
)
}
The parameter for changing the playback speed is given here.
func performPlayback(
_ ioActionFlags: UnsafeMutablePointer<AudioUnitRenderActionFlags>,
inTimeStamp: UnsafePointer<AudioTimeStamp>,
inBufNumber: UInt32,
inNumberFrames: UInt32,
ioData: UnsafeMutablePointer<AudioBufferList>
) -> OSStatus {
let buffer = ioData[0].mBuffers
let bytesToCopy = ioData[0].mBuffers.mDataByteSize
var bufferTail: UnsafeMutableRawPointer?
// print("BYTES TO COPY: \(bytesToCopy)")
self.availableBytes = 0
bufferTail = TPCircularBufferTail(&self.circularBuffer, &self.availableBytes)
bytesToWrite = min(bytesToCopy, self.availableBytes)
check(error: AudioUnitSetParameter(
varispeedUnit!,
AudioUnitParameterID(kVarispeedParam_PlaybackRate),
AudioUnitScope(kAudioUnitScope_Global),
0,
AudioUnitParameterValue(1.9999000082426955),
0
),
description: "Failed to set parameter rate for varispeed unit"
)
print("BYTES TO WRITE: \(bytesToWrite)")
if bytesToWrite >= 3840 {
memcpy(buffer.mData, bufferTail, Int(bytesToWrite))
TPCircularBufferConsume(&self.circularBuffer, bytesToWrite)
} else {
let silence = [Int16](repeating: 0, count: Int(bytesToCopy))
memcpy(buffer.mData, silence, Int(bytesToCopy))
}
return noErr
}
The problem is, I don't feel any difference in voice if I use varispeed or not. Can anyone point out the problem in my code?
https://stackoverflow.com/a/60552075/7798783
https://stackoverflow.com/a/34750857/7798783
https://stackoverflow.com/a/34671010/7798783
I have studied these answers and tried to implement them in our situation with no result.
I think scopes and elements might be the problem.

Swift 2 sqlite - library routine called out of sequence

I am using below code to insert records to sqlite. SQLite DB is already created and sqlite file exists in the right place.
However, when i run my test it gives an error:
Any help on this is appreciated. Already spent some time on this.
By the way, am new to SWIFT :(
"sqlite3_errmsg(carParkDB) UnsafePointer 0x000000010f44a863 "library routine called out of sequence"
Error appears at the first bind statement
sqlite3_bind_text(insertStmt, 1, carParkData.dataSource.rawValue, -1, SQLITE_TRANSIENT)
Below is my DAOImpl
import Foundation
class CarParkDaoImpl : CarParkDao{
var carParkDB : COpaquePointer = nil
var insertStmt: COpaquePointer = nil
let SQLITE_TRANSIENT = unsafeBitCast(-1, sqlite3_destructor_type.self)
func initializeDB(){
let carParkDataSQ = Constants.Paths.path + "/CarParkData.sqlite"
print("Sqlite file: \(carParkDataSQ)")
if(sqlite3_open(carParkDataSQ, &carParkDB) == SQLITE_OK){
let ret:Int32 = sqlite3_exec(carParkDB, Constants.CAR_PARK_SQL.createSql, nil, nil, nil);
if ( ret != SQLITE_OK){
print("Failed to create table: \(Constants.CAR_PARK_SQL.createSql)")
print("Error: \(sqlite3_errmsg(carParkDB))")
closeDB()
}
}else{
print("Falied to open : \(carParkDataSQ)")
print("Error: \(sqlite3_errmsg(carParkDB))")
closeDB()
}
}
func closeDB(){
sqlite3_close(carParkDB)
}
init(){
initializeDB()
}
/**
Responsible to insert the car park data
- Parameter carParkData: CarParkData.
- returns Bool
*/
func insert(carParkData: CarParkData) -> Bool{
prepareInsStatments()
var ret: Bool = false
sqlite3_bind_text(insertStmt, 1, carParkData.dataSource.rawValue, -1, SQLITE_TRANSIENT)
sqlite3_bind_text(insertStmt, 2, carParkData.address, -1, SQLITE_TRANSIENT)
sqlite3_bind_double(insertStmt, 3, carParkData.latitude)
sqlite3_bind_double(insertStmt, 4, carParkData.longitude)
sqlite3_bind_int(insertStmt, 5, Int32(carParkData.ltaCarParkID))
sqlite3_bind_text(insertStmt, 6, carParkData.ltaArea, -1, SQLITE_TRANSIENT)
sqlite3_bind_int(insertStmt, 7, Int32(carParkData.ltaLots))
sqlite3_bind_double(insertStmt, 8, carParkData.ltaPrice)
sqlite3_bind_text(insertStmt, 9, carParkData.hdbShortTermParking, -1, SQLITE_TRANSIENT)
sqlite3_bind_text(insertStmt, 10, carParkData.hdbCarParkType, -1, SQLITE_TRANSIENT)
sqlite3_bind_text(insertStmt, 11, carParkData.hdbFreeParking, -1, SQLITE_TRANSIENT)
sqlite3_bind_text(insertStmt, 12, carParkData.hdbNightParking, -1, SQLITE_TRANSIENT)
sqlite3_bind_int(insertStmt, 13, Int32(carParkData.hdbId))
sqlite3_bind_text(insertStmt, 14, carParkData.hdbAdHocParking, -1, SQLITE_TRANSIENT)
sqlite3_bind_text(insertStmt, 15, carParkData.hdbCarParkNo, -1, SQLITE_TRANSIENT)
let rc:Int32 = sqlite3_bind_text(insertStmt, 16, carParkData.hdbTypeOfParking, -1, SQLITE_TRANSIENT)
if (rc != SQLITE_OK) {
print(stderr, "failed to prepare statement: %s\n",
sqlite3_errmsg(carParkDB));
sqlite3_close(carParkDB);
return ret;
}
if(sqlite3_step(insertStmt) == SQLITE_DONE){
ret = true;
}
sqlite3_reset(insertStmt)
sqlite3_clear_bindings(insertStmt)
return ret
}
/**
Responsible to finalize all the prepared statements
*/
func finalize(){
sqlite3_finalize(insertStmt)
sqlite3_finalize(updateStmt)
sqlite3_finalize(deleteStmt)
sqlite3_finalize(selectAllStmt)
sqlite3_finalize(selectByIdStmt)
sqlite3_finalize(selectByDataSourceStmt)
}
func prepareInsStatments(){
let stmt = Constants.CAR_PARK_SQL.insertSql.cStringUsingEncoding(NSUTF8StringEncoding)
let ret:Int32 = sqlite3_prepare_v2(carParkDB, stmt!, -1, &insertStmt, nil)
if (ret != SQLITE_OK) {
print(stderr, "failed to prepare statement: %s\n",
sqlite3_errmsg(carParkDB));
sqlite3_close(carParkDB);
}
}
}
Here is my insert sql
static let insertSql:String =
"INSERT INTO CAR_PARK_DATA ( DATASOURCE, ADDRESS, LATITUDE, LONGITUDE "
+ " , LTA_CAR_PARK_ID, LTA_AREA, LTA_LOTS, LTA_PRICE, HDB_SHORT_TERM_PAKING "
+ " , HDB_CAR_PARK_TYPE, HDB_FREE_PARKING, HDB_NIGHT_PARKING, HDB_ID "
+ " , HDB_ADHOC_PARKING, HDB_CAR_PARK_NO, HDB_TYPE_PARK_SYSTEM ) "
+ " VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) "
Here is my test method
func testInsert(){
carParkData = CarParkData(dataType: DataSourceType.LTA.rawValue, address: "This is Test address", latitude: 100.0, longitude: 200.0, carParkID : 10, ltaCarParkID : 20, ltaArea: "LTA Area", ltaLots: 20, hdbShortTermParking: "Test HDB Short Praking", hdbCarParkType: "HDB Car Park Type", hdbFreeParking: "HDB Free Parking", hdbNightParking: "HDB Night Parking", hdbId : 30, hdbAdHocParking: "HDB Ad Hoc Parking", hdbCarParkNo: "HDB Car Park No", hdbTypeOfParking: "HDB Parking type", ltaPrice: 10.96778, favourite: true)
var val:Bool = carParkDao.insert(carParkData);
XCTAssertTrue(val)

IOS Swift 2D Array Sort

Using Swift i would like to sort the below array using the country name [0][1] instead of country code. Not sure how to achieve this.
let prefixCodes = [["AD", "Andorra"], ["AE", "United Arab Emirates"], ["AF", "Afghanistan"], ["AG", "Antigua & Barbuda"], ["AI", "Anguilla"], ["AL", "Albania"], ["AM", "Armenia"], ["AO", "Angola"], ["AQ", "Antarctica"], ["AR", "Argentina"], ["AS", "American Samoa"], ["AT", "Austria"], ["AU", "Australia"], ["AW", "Aruba"], ["AX", "Åland Islands"], ["AZ", "Azerbaijan"], ["BA", "Bosnia & Herzegovina"], ["BB", "Barbados"], ["BD", "Bangladesh"], ["BE", "Belgium"], ["BF", "Burkina Faso"], ["BG", "Bulgaria"], ["BH", "Bahrain"], ["BI", "Burundi"], ["BJ", "Benin"], ["BL", "St. Barthélemy"], ["BM", "Bermuda"], ["BN", "Brunei"], ["BO", "Bolivia"], ["BQ", "Caribbean Netherlands"], ["BR", "Brazil"], ["BS", "Bahamas"], ["BT", "Bhutan"], ["BV", "Bouvet Island"], ["BW", "Botswana"], ["BY", "Belarus"], ["BZ", "Belize"], ["CA", "Canada"], ["CC", "Cocos (Keeling) Islands"], ["CD", "Congo - Kinshasa"], ["CF", "Central African Republic"], ["CG", "Congo - Brazzaville"], ["CH", "Switzerland"], ["CI", "Côte d’Ivoire"], ["CK", "Cook Islands"], ["CL", "Chile"], ["CM", "Cameroon"], ["CN", "China"], ["CO", "Colombia"], ["CR", "Costa Rica"], ["CU", "Cuba"], ["CV", "Cape Verde"], ["CW", "Curaçao"], ["CX", "Christmas Island"], ["CY", "Cyprus"], ["CZ", "Czech Republic"], ["DE", "Germany"], ["DJ", "Djibouti"], ["DK", "Denmark"], ["DM", "Dominica"], ["DO", "Dominican Republic"], ["DZ", "Algeria"], ["EC", "Ecuador"], ["EE", "Estonia"], ["EG", "Egypt"], ["EH", "Western Sahara"], ["ER", "Eritrea"], ["ES", "Spain"], ["ET", "Ethiopia"], ["FI", "Finland"], ["FJ", "Fiji"], ["FK", "Falkland Islands"], ["FM", "Micronesia"], ["FO", "Faroe Islands"], ["FR", "France"], ["GA", "Gabon"], ["GB", "United Kingdom"], ["GD", "Grenada"], ["GE", "Georgia"], ["GF", "French Guiana"], ["GG", "Guernsey"], ["GH", "Ghana"], ["GI", "Gibraltar"], ["GL", "Greenland"], ["GM", "Gambia"], ["GN", "Guinea"], ["GP", "Guadeloupe"], ["GQ", "Equatorial Guinea"], ["GR", "Greece"], ["GS", "So. Georgia & So. Sandwich Isl."], ["GT", "Guatemala"], ["GU", "Guam"], ["GW", "Guinea-Bissau"], ["GY", "Guyana"], ["HK", "Hong Kong SAR China"], ["HM", "Heard & McDonald Islands"], ["HN", "Honduras"], ["HR", "Croatia"], ["HT", "Haiti"], ["HU", "Hungary"], ["ID", "Indonesia"], ["IE", "Ireland"], ["IL", "Israel"], ["IM", "Isle of Man"], ["IN", "India"], ["IO", "British Indian Ocean Territory"], ["IQ", "Iraq"], ["IR", "Iran"], ["IS", "Iceland"], ["IT", "Italy"], ["JE", "Jersey"], ["JM", "Jamaica"], ["JO", "Jordan"], ["JP", "Japan"], ["KE", "Kenya"], ["KG", "Kyrgyzstan"], ["KH", "Cambodia"], ["KI", "Kiribati"], ["KM", "Comoros"], ["KN", "St. Kitts & Nevis"], ["KP", "North Korea"], ["KR", "South Korea"], ["KW", "Kuwait"], ["KY", "Cayman Islands"], ["KZ", "Kazakhstan"], ["LA", "Laos"], ["LB", "Lebanon"], ["LC", "St. Lucia"], ["LI", "Liechtenstein"], ["LK", "Sri Lanka"], ["LR", "Liberia"], ["LS", "Lesotho"], ["LT", "Lithuania"], ["LU", "Luxembourg"], ["LV", "Latvia"], ["LY", "Libya"], ["MA", "Morocco"], ["MC", "Monaco"], ["MD", "Moldova"], ["ME", "Montenegro"], ["MF", "St. Martin"], ["MG", "Madagascar"], ["MH", "Marshall Islands"], ["MK", "Macedonia"], ["ML", "Mali"], ["MM", "Myanmar (Burma)"], ["MN", "Mongolia"], ["MO", "Macau SAR China"], ["MP", "Northern Mariana Islands"], ["MQ", "Martinique"], ["MR", "Mauritania"], ["MS", "Montserrat"], ["MT", "Malta"], ["MU", "Mauritius"], ["MV", "Maldives"], ["MW", "Malawi"], ["MX", "Mexico"], ["MY", "Malaysia"], ["MZ", "Mozambique"], ["NA", "Namibia"], ["NC", "New Caledonia"], ["NE", "Niger"], ["NF", "Norfolk Island"], ["NG", "Nigeria"], ["NI", "Nicaragua"], ["NL", "Netherlands"], ["NO", "Norway"], ["NP", "Nepal"], ["NR", "Nauru"], ["NU", "Niue"], ["NZ", "New Zealand"], ["OM", "Oman"], ["PA", "Panama"], ["PE", "Peru"], ["PF", "French Polynesia"], ["PG", "Papua New Guinea"], ["PH", "Philippines"], ["PK", "Pakistan"], ["PL", "Poland"], ["PM", "St. Pierre & Miquelon"], ["PN", "Pitcairn Islands"], ["PR", "Puerto Rico"], ["PS", "Palestinian Territories"], ["PT", "Portugal"], ["PW", "Palau"], ["PY", "Paraguay"], ["QA", "Qatar"], ["RE", "Réunion"], ["RO", "Romania"], ["RS", "Serbia"], ["RU", "Russia"], ["RW", "Rwanda"], ["SA", "Saudi Arabia"], ["SB", "Solomon Islands"], ["SC", "Seychelles"], ["SD", "Sudan"], ["SE", "Sweden"], ["SG", "Singapore"], ["SH", "St. Helena"], ["SI", "Slovenia"], ["SJ", "Svalbard & Jan Mayen"], ["SK", "Slovakia"], ["SL", "Sierra Leone"], ["SM", "San Marino"], ["SN", "Senegal"], ["SO", "Somalia"], ["SR", "Suriname"], ["SS", "South Sudan"], ["ST", "São Tomé & Príncipe"], ["SV", "El Salvador"], ["SX", "Sint Maarten"], ["SY", "Syria"], ["SZ", "Swaziland"], ["TC", "Turks & Caicos Islands"], ["TD", "Chad"], ["TF", "French Southern Territories"], ["TG", "Togo"], ["TH", "Thailand"], ["TJ", "Tajikistan"], ["TK", "Tokelau"], ["TL", "Timor-Leste"], ["TM", "Turkmenistan"], ["TN", "Tunisia"], ["TO", "Tonga"], ["TR", "Turkey"], ["TT", "Trinidad & Tobago"], ["TV", "Tuvalu"], ["TW", "Taiwan"], ["TZ", "Tanzania"], ["UA", "Ukraine"], ["UG", "Uganda"], ["UM", "U.S. Outlying Islands"], ["US", "United States"], ["UY", "Uruguay"], ["UZ", "Uzbekistan"], ["VA", "Vatican City"], ["VC", "St. Vincent & Grenadines"], ["VE", "Venezuela"], ["VG", "British Virgin Islands"], ["VI", "U.S. Virgin Islands"], ["VN", "Vietnam"], ["VU", "Vanuatu"], ["WF", "Wallis & Futuna"], ["WS", "Samoa"], ["YE", "Yemen"], ["YT", "Mayotte"], ["ZA", "South Africa"], ["ZM", "Zambia"], ["ZW", "Zimbabwe"]]
Thank you in advance.
With sort and the shorthand arguments you can order the second element in your 2D array like this:
let sortedAfterCountryNames = prefixCodes.sort{ $0[1] < $1[1] }
print(sortedAfterCountryNames)
// [["AF", "Afghanistan"], ["AL", "Albania"], ["DZ", "Algeria"], ["AS", "American Samoa"], ...
Hope this will help you.
let sortedArray = prefixCodes.sort { (first, second) -> Bool in
return first.last < second.last
}
You should use the sort method to sort your array.
Let's first create an unsorted array:
var arr = [["A", "Hello world"],
["C", "Bye world"],
["B", "idk what to say here"]]
Now let's look at what arguments the sort method needs. Apparently it needs a closure of the following signature:
([String], [String]) -> Bool
The most straightforward (but not so swifty) approach would be to write a function with that signature:
func myFunction (first: [String], second: [String]) -> Bool {
}
In that function, you need to decide whether the algorithm should swap the two arguments. If it should not, return true, otherwise false. I think if you want to sort in alphabetical order, you should just compare the two strings
return first[1] < second[1]
You access the element at index 1 because that is where you store the country names, right?
Then, call sort with the function
arr = arr.sort(myFunction)
However, that is not very swifty. To make this the most swifty, you can do this:
arr.sort {
$0[1] < $1[1]
}
Much better!
You may do the following:
prefixCodes.sort { $0[1] < $1[1] }
But to be safer, I think that you should define a Country struct like this:
struct Country {
let code: String
let name: String
init(_ code: String, _ name: String) {
self.code = code
self.name = name
}
}
let countries = [Country("AD", "Andorra"), Country("AE", "United Arab Emirates"), Country("BQ", "Caribbean Netherlands")]
print(countries.sort { $0.name < $1.name })
So that if you want to add more details to your countries, you will not have a chance to break your sort closure.
Or if you want to keep things simple but still enforce strong typing, you could use tuples:
let countries = [("AD", "Andorra"), ("AE", "United Arab Emirates"), ("BQ", "Caribbean Netherlands")]
print(countries.sort { $0.1 < $1.1 })
If you mix different tuple lengths in your array:
let countries = [("AD", "Andorra"), ("toto"), ("tata", "titi", "tutu")]
Swift will return this error:
error: type of expression is ambiguous without more context

Image from iphone app to wcf service

Can any one suggest me that how can I retrive a image from iphone app through WCF web service
and save it to a directory.
I am recieving a image from iphone app in form of NSDATA(Don't know about that,Actually iphone develpoer is giving me a image as Nsdata).
and I am doing like this to convert this data to image and save to my directory
public Image byteArrayToImage(byte[] byteArrayIn)
{
Image returnImage = null;
string ApplicationVerifyPath = ConfigurationManager.AppSettings["ImagePath"].ToString();
ApplicationVerifyPath = ApplicationVerifyPath + "RetailerAdmin/ProductImages/";
using (MemoryStream ms = new MemoryStream(byteArrayIn, 0, byteArrayIn.Length))
{
ms.Write(byteArrayIn, 0, byteArrayIn.Length);
ms.Seek(0, SeekOrigin.Begin);
returnImage = Image.FromStream(ms);
returnImage.Save(ApplicationVerifyPath + returnImage, System.Drawing.Imaging.ImageFormat.Png);
}
return returnImage;
}
it is showing (parameter is invalid error in Image.FromStream(ms).
Kindly help me to get out from this solution.
Image data example
ffd8ffe0 00104a46 49460001 01000001 00010000 ffe10058 45786966 00004d4d 002a0000 00080002
01120003 00000001 00010000 87690004 00000001 00000026 00000000 0003a001 00030000 00010001 0000a002
00040000 00010000 00e1a003 00040000 00010000 00e10000 0000ffdb 00430020 16181c18 14201c1a 1c242220
26305034 302c2c30 62464a3a 5074667a 78726670 6e8090b8 9c8088ae 8a6e70a0 daa2aebe c4ced0ce 7c9ae2f2
e0c8f0b8 cacec6ff db004301 22242430 2a305e34 345ec684 7084c6c6 c6c6c6c6 c6c6c6c6 c6c6c6c6 c6c6c6c6
c6c6c6c6 c6c6c6c6 c6c6c6c6 c6c6c6c6 c6c6c6c6 c6c6c6c6 c6c6c6c6 c6c6c6c6 ffc00011 0800e100 e1030122
00021101 031101ff c4001f00 00010501 01010101 01000000 00000000 00010203 04050607 08090a0b ffc400b5
10000201 03030204 03050504 04000001 7d010203 00041105 12213141 06135161 07227114 328191a1 082342b1
c11552d1 f0243362 7282090a 16171819 1a252627 28292a34 35363738 393a4344 45464748 494a5354 55565758
595a6364 65666768 696a7374 75767778 797a8384 85868788 898a9293 94959697 98999aa2 a3a4a5a6 a7a8a9aa
b2b3b4b5 b6b7b8b9 bac2c3c4 c5c6c7c8 c9cad2d3 d4d5d6d7 d8d9dae1 e2e3e4e5 e6e7e8e9 eaf1f2f3 f4f5f6f7
f8f9faff c4001f01 00030101 01010101 01010100 00000000 00010203 04050607 08090a0b ffc400b5 11000201
02040403 04070504 04000102 77000102 03110405 21310612 41510761 71132232 81081442 91a1b1c1 09233352
f0156272 d10a1624 34e125f1 1718191a 26272829 2a353637 38393a43 44454647 48494a53 54555657 58595a63
64656667 68696a73 74757677 78797a82 83848586 8788898a 92939495 96979899 9aa2a3a4 a5a6a7a8 a9aab2b3
b4b5b6b7 b8b9bac2 c3c4c5c6 c7c8c9ca d2d3d4d5 d6d7d8d9 dae2e3e4 e5e6e7e8 e9eaf2f3 f4f5f6f7 f8f9faff
da000c03 01000211 0311003f 00e828a2 aadede47 6716f7e5 8f0aa3a9 34016738 a85eeedd 0e1e7894 fbb815ce
5c5ddcde 37ef1c85 3d11781f fd7a885b 36385fe9 401d3fdb ad3fe7e6 1ffbec51 f6eb4ff9 f987fefb 15ccfd99
bfba3f31 47d99bfb bfa8a00e 9bedd69f f3f30ffd f628fb75 a7fcfcc3 ff007d8a e67eccdf dd1f98a3 eccdfdd1
f98a00e9 bedd69ff 003f30ff 00df628f b75a7fcf cc3ff7d8 ae67eccd fdd1f98a 3eccdfdd 1f98a00e 9bedd69f
f3f30ffd f628fb75 a7fcfcc3 ff007d8a e67eccdf dd1f98a3 eccde83f 31401d37 dbad3fe7 e61ffbec 51f6eb4f
f9f987fe fb15ccfd 99bd07e6 297eccdf dd1f98a0 0e97edd6 9ff3f30f fdf628fb 75a7fcfc c3ff007d 8ae67ecc
dfdd1f98 a3eccdfd d1f98a00 e9bedd69 ff003f30 ff00df62 8fb75a7f cfcc3ff7 d8ae67ec cde83f31 47d99bfb
a3f31401 d37dbad3 fe7e61ff 00bec51f 6eb4ff00 9f987fef b15ccfd9 9bfba3f3 147d99bf ba3f3140 1d37dbad
3fe7e61f fbec51f6 eb4ff9f9 87fefb15 cd7d99bf ba3f3149 f666fee8 fcc50074 df6eb4ff 009f987f efb147db
ad3fe7e6 1ffbec57 33f666fe e8fcc51f 666feefe a2803a75 bcb56385 b8889f40 e2a60411 906b9236 cd8fbbfa
d2c33dc5 9b7ee5ca e3f84f4f ca803ada 2a8e9da8 25ea107e 5957ef2f f51ed57a 800a28a2 80109c0c d72b7970
6f2eda4c e541c20f 6ae8ef9c a5a4cc3a 8427f4ae 5a100628 0275c20e 3af73464 9ea68a28 00a29296 800e68e6
8a2800a2 8a2800fc 68a28a00 28a4a5a0 028a4a28 0168a292 80168a4a 5a0028a2 8a0028a2 8a0039f5 a52430c3
7e06928a 008e391e d675993a a9e9ea3b 8aeae291 658d5d4e 430c835c 9cb5d068 cc5b4e8b 3d811f91 22802fd1
45140153 51ff008f 19ff00eb 9b7f2ae6 a2ed5d2e a5ff001e 33ff00d7 36fe55cc c5401351 45140051 4945002d
14514005 14514005 14946680 168a4cd2 6e1400ea 29bb87ad 2eea005a 29334500 2d1494b4 00514514 00514514
00514514 011cb5bb a27fc83e 3fc7f99a c296b774 4ff907c7 f53fccd0 06951451 4015352f f8f19ffe b9b7f2ae
662ae9b5 2ff8f19f feb9b7f2 ae662a00 968a4a5a 0028a4a2 80168a4a 28016834 84e2a6b3 b396f1fe 4f9507de
73fd2802 11962154 1627a003 26af5be9 37128065 2221e879 35ad6b67 0daae235 f9bbb1ea 6ac50067 c7a3db27
df2f21f7 381fa54e ba7da01f f1ef19fa 8cd59a69 9635382e a3ea6802 03a7da11 ff001ef1 8fa2e2a1 9348b57f
ba1a33fe cb7f8d5c 13447a48 87fe0429 f401873e 8f320cc2 e241e878 354183c6 db24528c 3b118aea ea2b8b68
ae536ca8 08ec7b8f a5007339 a2ac5f58 4966770f 9e1fef77 1f5aac0e 680168a2 8a0028a2 9280168a 29280192
d6f689ff 0020f8fe a7f99ac1 92b7b44f f907c7f5 3fccd006 95145140 15352ff8 f19ffeb9 b7f2ae62 2ae9f52f
f8f19ffe b9b7f2ae 622a0096 8a4a2801 68a4a280 1690d148 0348eb1a 0cb31c01 40162c6d 1af26db9 c46bf7db
fa574714 69146111 42a81c01 515a5bad adbac4bd ba9f5353 92154963 803a9340 01200c93 802b32e7 57018c76
89e637f7 cfdd1fe3 556eeede fe42884a db838f77 ff00eb51 1a2a2e00 a9723a21 4afab18d f69b8399 a77c7f75
4e0520b3 8fb8c9f5 353e68cd 4dcd9452 20365176 5c52aa4f 01cc13ba fb139153 668cd170 714c96df 57746097
898ffa68 bd3f115a 88eb2207 460ca790 45623287 1c8a8e09 e4d3e4ca 7cd093f3 27f514d4 8c6747aa 3a0650ca
430c83d4 1ae7b52b 236926f8 c7ee58f1 fec9f4ad f8e449a3 5910e558 641a4962 49a368dc 655860d5 9ce72e0e
68a59a26 b6b8785f aa9ebea3 b1a6d002 d1494500 2d149450 0324aded 13fe41f1 fd5bf99a c192b7f4 4ff907c7
f56fe668 034a8a28 a00a9a9f fc78cfff 005cdbf9 572f1575 1a9ffc78 4fff005c dbf9572f 1d004b45 251400b4
52514001 ad0d0e0d f3bcec38 4185fa9a cd63815d 0e931f97 a745c72f f39fc7ff 00ad4017 4726b2f5 9b924ada
21ebcb9f 6ec2b4f2 154b13c0 1cd736ae 669e499b abb67fc2 a64ec8da 8c39a44f 1a851802 9d9a6668 cd6676d8
7e68cd33 346680b0 fcd19a66 68cd0161 f9a6b00c 39a4cd19 a02c4da5 5c1b7b9f b331fddc 9cafb1f4 ad93c1ae
6ae32007 53865390 6ba18651 35bc728f e200d691 671d6872 bb99baec 198d2e14 72a76b7d 0d648391 5d2ddc5e
75a4b1ff 00794e3e bdab9843 95aa301f 45251400 b452519a 006c95bd a1ff00c8 3e3fab7f 33581256 fe87ff00
20f8fead ff00a11a 00d3a28a 28029ea7 ff001e13 ff00d736 fe55cbc7 5d46a7ff 001e13ff 00d736fe 55cbc740
12514514 0052d251 400c9490 a71e95d5 c2a1208d 47f0a815 c94bf70f d2bad560 63523b81 4011deb9 4b19d81e
429ac080 e12b7350 e74f9ffd dae7d0e0 715133b7 0aaf72ce ea37541b 8d2ee350 75f293ee a37541bc d1bcd01c
a4fba8dd 506f346f 34072936 ea37543b 8d26e340 72924ad9 4ad8d218 b69c993f 74902b09 98915b5a 3f1a70ff
0078d544 e5c4ab24 5feb5c99 1b25917f baec3f23 5d58ae52 420dccc4 77918fea 6b43845a 28a2800a 28a28019
25741a17 fc83a3fa b7fe846b 9f92ba0d 0bfe41f1 fd5bff00 423401a7 45145005 3d4ffe3c 27ff00ae 6dfcab96
8eba9d4f fe3c27ff 00ae6dfc ab968e80 24a2928a 005a2928 a006b8c8 ae974f93 cdd3e06f f6003f51 c5736dd2
b5f40981 864809e5 0ee1f434 01a52287 8dd0ff00 12915cc2 e54953d4 1c1aea1b 8ac2d520 30dd79aa 3e4939fc
7bd4491d 1879f2ca c56a2933 45667a37 168a4a28 0b8b4525 1405c5a2 928cd017 11ce16ba 2b28cc56 71211ced
c9fc6b0e ca037374 aa47c8bc b7d2ba21 c9ad22ba 9c1899dd d824711c 4ee7a2a9 26b938f2 464f53c9 adfd6a6f
2ac0a03f 34a768fa 77ac15e0 559ca3e8 a4a28017 34525140 0d7ae874 2ff907c7 f56ffd08 d73cf5d0 e85ff20e
8feadffa 11a00d3a 28a28029 ea7ff1e1 3ffd736f e55cac75 d56a7ff1 e13ffd73 6fe55caa 5003e969 28a00296
928a000d 3ed2e0da 5da4dd87 0c3da994 d619a00e b32aea19 4e548c82 2abdcc2b 3c4d1bf4 3d0fa1ac ed1aff00
6e2d263c 7fcb363f cab61968 04ec7332 c6f04a63 90608fd6 9335bb73 6d1dc26d 9074e8c3 a8ac6b8b 49ad8e48
de9fde1f d6b3713b 69d74f46 47453036 69d9a93a 3993168a 4cd216c5 01cc8752 00d23844 1b98f402 9f05bcd7
27f76bf2 f763d056 c5a59c76 c3e5f99c f56354a3 730a9592 d10fb2b6 16d0ec07 2c7963ef 57145314 567eb17e
21436d11 fde30f98 8fe11fe3 5a1c4ddd dd99fa9d d0bbbd25 4e638fe5 5f7f5355 c714c418 14fa042d 25145002
d1494500 35eba2d0 bfe41d1f d5bff423 5cebd743 a17fc83a 3fab7fe8 46803528 a28a00a7 a9ff00c7 84ff00f5
cdbf9572 895d5ea7 ff001e13 ff00d736 fe55ca25 003e8a28 a0028a28 a0028345 1400c65a d7d3b560 4082e8e0
f4590f7f ad651a6b 2e6803ac 65c8e2a3 208ae7ed 3519ecc6 d07cc8ff 00b8ddbe 9e95af6f aa5acfc1 6f29ff00
baff00e3 4004b656 d29cb440 1f55e2a0 3a4c24f1 2c8bed8c d69050c3 2a4107b8 a361a564 52935b33 306910e7
99a43f80 a9e3b0b5 8cf116e3 eae73573 61a5da00 e68b2073 6fa8c038 e071e952 2a5559f5 1b4b6183 26f6feea
726b26ef 559ee414 8c7951fa 03c9fa9a 649a1a8e aab0030d b90f2f76 ecbffd7a c3e598b3 12c49c92 7a9a4550
074a78e2 80147145 14500145 14500145 1450035e ba2d0bfe 41d1fd5b ff004235 cebd745a 17fc83a3 fab7fe84
6803528a 28a00a7a a7fc784f ff005cdb f957269d abacd53f e3c2e3fe b9b7f2ae 4d2801f4 51450014 5252d001
45145001 45149400 100d34a8 3da9f494 00d46923 3fbb774f f75b153a dfdea0e2 e1ff001c 1a8a8c0a 0095b50b
d61cdc37 e000a85d e597fd6c aeff00ef 3134b8a3 02801a10 0e829c00 1452d001 45145001 45149400 b4514500
14514500 35aba3d0 bfe41d1f d5bff423 5ce35747 a0ff00c8 3a2fab7f e8468035 28a28a00 a7aa7fc7 84ff00f5
cdbf9572 69dabadd 48136338 1ff3cdbf 957229d2 801f4525 1400b452 52d00145 251400b4 5251400b 45251400
b4514500 14514940 0b452514 00b45251 400b4525 1400b452 51400b45 2514008d 5d2683ff 0020e8be adff00a1
1ae6daba 5d0b8d3a 2fc7f99a 00d3a28a 280229d7 72104704 571d2c4d 04ef1375 53f98ed5 da30c8ac 6d574ff3
ff007883 120fd680 30fad14d 21918ab8 2ac3a834 b9a005a2 93346680 168a4cd1 9a005a29 33466801 68a4cd19
a005a293 34668016 8a4cd19a 005a2933 46680168 a4cd19a0 05a29334 6680168a 4cd19a00 5a293349 924e00c9
3d00a005 c33b0551 9663802b aeb18843 6f1c63f8 540ac8d2 b4e64613 4c3e7fe1 1e9ffd7a de45c2d0 03e8a28a
002a3910 30a928a0 0cdb9b18 e618740d fcea8b68 d0e78320 f606b7c8 069be58f 4a00c0fe c68bfbd2 7e63fc28
fec68bfb d27e63fc 2b7fcb1e 947963d2 80303fb1 a2fef49f 98ff000a 3fb1a2fe f49f98ff 000adff2 c7a51e58
f4a00c0f ec68bfbd 27e63fc2 8fec68bf bd27e63f c2b7fcb1 e947963d 280303fb 1a2fef49 f98ff0a3 fb1a2fef
49f98ff0 adff002c 7a51e58f 4a00c0fe c68bfbd2 7e63fc28 fec68bfb d27e63fc 2b7fcb1e 947963d2 80303fb1
a2fef49f 98ff000a 3fb1a2fe f49f98ff 000adff2 c7a51e58 f4a00c0f ec68bfbd 27e63fc2 8fec68bf bd27e63f
c2b7fcb1 e947963d 280303fb 1a2fef49 f98ff0a3 fb1a2fef 49f98ff0 adff002c 7a51e58f 4a00c0fe c68bfbd2
7e63fc28 fec68bfb d27e63fc 2b7fcb1e 947963d2 80303fb1 a2fef49f 98ff000a 3fb1a2fe f49f98ff 000adff2
c7a51e58 f4a00c11 a3459e5a 43f8d5cb 6d3e2879 4400faf7 ad2f2c52 85028019 1c61474a 92968a00 28a28a00
28a28a00 28a28a00 28a28a00 28a28a00 28a28a00 28a28a00 28a28a00 28a28a00 28a28a00 28a28a00 28a28a00
28a28a00 28a28a00 28a28a00 28a28a00 ffd9
You can try the below way as I had implemented in one of my project when intergrating WCF REST service in iPhone.
Get NSDATA to string property or variable. Use this string as Base64 string and convert it into an image and save it to your directory.
public void Base64ToImage(string imageString)
{
// Convert Base64 String to byte[]
byte[] imageBytes = Convert.FromBase64String(imageString);
MemoryStream ms = new MemoryStream(imageBytes, 0,
imageBytes.Length);
// Convert byte[] to Image
ms.Write(imageBytes, 0, imageBytes.Length);
System.Drawing.Image image = System.Drawing.Image.FromStream(ms, true);
image.Save("Base64ToImage.png"); //Specify your filename here
}

Resources