nsdata

'bytes' is unavailable: use withUnsafeBytes instead

两盒软妹~` 提交于 2019-11-29 03:52:25
Code that was previously working in Swift 2.2 is now throwing the following error in Swift 3: Here is my code: let tempData: NSMutableData = NSMutableData(length: 26)! tempData.replaceBytes(in: NSMakeRange(0, data.count), withBytes:data.bytes) What should I replace "data.bytes" with to fix the error? I've tried implementing 'withUnsafeBytes' and had a look at Apple's documentation, but can't get my head around it! Assuming that data has type Data , the following should work: let tempData: NSMutableData = NSMutableData(length: 26)! data.withUnsafeBytes { tempData.replaceBytes(in: NSMakeRange(0,

Record audio to NSData

狂风中的少年 提交于 2019-11-29 02:37:58
I have set up a TCP connection between two iPhones and I am able to send NSData packages between the two. I would like to talk into the microphone and get the recording as an NSData object and send this to the other iPhone. I have successfulyl used Audio Queue Services to record audio and play it but I have not managed to get the recording as NSData. I posted a question about converting the recording to NSData when using Audio Queue Services but it has not got me any further. Therefore I would like to hear if there is any other approach I can take to speak into the microphone of an iPhone and

Storing images to CoreData - Swift

烈酒焚心 提交于 2019-11-29 02:37:41
In my code I managed to save a textLabel with CoreData but I can't seem to properly save the image. I've read some tutorials and I know I have to convert it to NSData. But how do I do it? Thanks in advance! Core Data isn't meant to save big binary files like images. Use Document Directory in file system instead. Here is sample code to achieve that. let documentsDirectory = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true).first as! String // self.fileName is whatever the filename that you need to append to base directory here. let path = documentsDirectory

How to convert AVAsset to NSData or save it to file manager

时光总嘲笑我的痴心妄想 提交于 2019-11-29 01:41:52
I am trying to do that using AVAsset to record Audio file and then after first i store it on NSFileManager and after that by convert it to nsdata i Call API to store it. I am successful to Create AVAsset recording file and play it using third party Class that is SCPlayer . Now problem is that i don't know how to Use AVAsset file for save it in file manager and then after call API to sent it by converting it to NSData . Is any way to convert AVAsset to NSData ??? Please Help... You can do the following: Use AVAssetExportSession to export your AVAsset object to a file path URL. Convert it to

Decode a base64 data to image

最后都变了- 提交于 2019-11-29 01:40:19
问题 This code doesn't working with Swift 3 anymore. imageData = NSData(base64EncodedString: mediaFile, options: NSDataBase64DecodingOptions.fromRaw(0)!) So is this one. imageData = NSData(base64EncodedString: mediaFile, options: .allZeros) 回答1: Instead of using NSData use directly Swift 3 native Data . if let decodedData = Data(base64Encoded: mediaFile, options: .ignoreUnknownCharacters) { let image = UIImage(data: decodedData) } 回答2: Swift 4.1 : Sometimes string has prefix data:image/png;base64

How to play video from NSData

为君一笑 提交于 2019-11-28 23:38:12
HI everyone, I would like to know if it's possible to play a video from an NSData object... with the MPMoviePlayerController. Thanks in advance, Sergio Ben's answer works perfectly on simulator but wont work on the device, You cannot write anywhere on the device. Check code below NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *path = [documentsDirectory stringByAppendingPathComponent:@"myMove.mp4"]; [videoData writeToFile:path atomically:YES]; NSURL *moveUrl = [NSURL

CGPDFDocumentRef from NSData

二次信任 提交于 2019-11-28 22:18:37
问题 I get my PDF from SQLite DB into a NSData variable. Now what are my options to create CGPDFDocumentRef from this NSData? Or what are my options anyway to create this CGPDFDocumentRef, have the data in SQLite? 回答1: You can create a PDF document using this function: CGPDFDocumentRef CGPDFDocumentCreateWithProvider ( CGDataProviderRef provider ); To create the provider you can use this function: CGDataProviderRef CGDataProviderCreateWithCFData ( CFDataRef data ); and consider that NSData and

Retrieve nsdata from sqlite stored in Blob data type for iPhone App

≯℡__Kan透↙ 提交于 2019-11-28 20:58:53
In iPhone App how to store UIImage converted into NSData to sqlite table in BLOB datatype? Is there any kind of binding needed( NSData ->Blob)? or While retrieving image stored in NSData form in sqlite Blob datatype, should I need to perform any task to convert that stored database in blob datatype to get back into NSData form? Please help and suggest. I used something like this: // prepare sqlite3 statement before this line int res = sqlite3_step(stmt); if (res == SQLITE_ROW) { const void *ptr = sqlite3_column_blob(stmt, 0); int size = sqlite3_column_bytes(stmt, 0); data = [[NSData alloc]

Is there a practical way to compress NSData?

对着背影说爱祢 提交于 2019-11-28 20:47:31
I haven't seen any documentation on the topic, but that doesn't mean it doesn't exist. zaph Yes, compress the data with zlib. @Brad Larson posted on this: see here and added the code as well. There is a CocoaPod which uses Objective-Zip by flyingdolphinstudio. Following @Zaph & @Brad Larson's posts, below are the 2 methods gzipInflate and gzipDeflate that work just fine to compress/decompress NSData . (code reformatted from cocoadev.com/wiki/NSDataCategory #import "zlib.h" // don't forget to add libz.1.2.x.dylib into your project - (NSData *)gzipInflate:(NSData*)data { if ([data length] == 0)

NSData & NSURL - url with space having problem

最后都变了- 提交于 2019-11-28 19:08:05
I have following code in my application. NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString:pathOfThumbNail]]; pathOfThumbNail has following path http://70.84.58.40/projects/igolf/TipThumb/GOLF 58B.jpg When I open above path in safari browser - path is changed automatically & image is successfully displayed. http://70.84.58.40/projects/igolf/TipThumb/GOLF%2058B.jpg But in iPhone, due to space in path, image isn't loaded in nsdata. Use: stringByAddingPercentEscapesUsingEncoding: Returns a representation of the receiver using a given encoding to determine the percent escapes