nsdata

iphone sdk see size of local file (one created by application)

拥有回忆 提交于 2019-12-12 12:33:16
问题 Is there anyway I can look at the size of a file the application creates in bytes then store that number to use later? OR is there any way I can tell if an object in an NSArray is empty, I've tried everything, but it just doesn't work! 回答1: Use NSFileManager class' method - (NSDictionary *)attributesOfItemAtPath:(NSString *)path error:(NSError **)error The size key in the returned dictionary is defined as NSString * const NSFileSize; So for an example NSError *error = nil; NSDictionary

Converting UIImage to NSData with UIImageJPEGRepresentaion() and saving it to a file increases the file size in bytes

谁说我不能喝 提交于 2019-12-12 12:27:13
问题 I have a requirement in which the user can select an image from camera roll and my application needs to optimize the image and upload it to a server. I am using ALAssets library and a custom picker for the user to select a photo from camera roll . I am able to achieve this perfectly but have a problem with the file size getting increased. The problem is as follows: When the user selects a photo, of 1.7MB (That is the full size as reported by the iOS when I try to mail the photo), when I

Turning NSData back to plain text NSString

落爺英雄遲暮 提交于 2019-12-12 11:03:51
问题 I have a simple NSString and I'm converting it to NSData : NSData *data = [[NSData dataWithBytes:[[NSString stringWithFormat:@",%@",self.targetId] dataUsingEncoding:NSASCIIStringEncoding] length:[[NSString stringWithFormat:@",%@",self.targetId] lengthOfBytesUsingEncoding:NSASCIIStringEncoding]] retain]; Now I want to get the plain text from the NSData object. If I'm doing that : NSString* dataStr = [NSString stringWithFormat:@"%@",data]; - I'm getting just an hex expression (i.e <9c3f473e

Elegant Algorithm for Parsing Data Stream Into Record

早过忘川 提交于 2019-12-12 09:19:11
问题 I am interfacing with a hardware device that streams data to my app over Wifi. The data is streaming in just fine. The data contains a character header (DATA:) that indicates a new record has begun. The issues is that the data I receive doesn't necessarily fall on the header boundary, so I have to capture the data until what I've captured contains the header. Then, everything that precedes the header goes into the previous record and everything that comes after it goes into a new record. I

AVPlayer loading AVAsset from file that is appended simultaneously by external source (for macOS and iOS)

六月ゝ 毕业季﹏ 提交于 2019-12-12 08:23:44
问题 I have a question concerning the use of AVFoundation’s AVPlayer (probably applicable to both iOS and macOS). I am trying to playback audio (uncompressed wav) data that come from a channel other than the standard HTTP Live Streaming. The case: Audio data packets come compressed in a channel along with other data the app needs to work with. For example, video and audio come in the same channel and get separated by a header. After filtering, I get the audio data and decompress them to a WAV

Using Structs (Bytes) with SWIFT - Struct to NSData and NSData to Struct

久未见 提交于 2019-12-12 07:59:46
问题 I'm trying to understand how structs work within SWIFT. I'm familiar with how .NET handles them and how it packs bytes into a structure, etc. I'm finding some weirdness with the following code: struct exampleStruct { var ModelNumber: Byte! var MajorVersion: Byte! var MinorVersion: Byte! var Revision: Byte! } var myStruct = exampleStruct ( ModelNumber: 1, MajorVersion: 2, MinorVersion: 3, Revision: 4 ) myStruct.MinorVersion // << Returns 3 // Struct to NSData. var data = NSData( bytes:

Trouble converting NSData Objective-C code to Swift

亡梦爱人 提交于 2019-12-12 05:32:01
问题 I've been having issues converting an Objective-C snippet to Swift that uses NSData and CoreBluetooth . I have looked at this question and a couple others dealing with NSData in Swift but haven't had any success. Objective-C Snippet: - (CGFloat) minTemperature { CGFloat result = NAN; int16_t value = 0; // characteristic is a CBCharacteristic if (characteristic) { [[characteristic value] getBytes:&value length:sizeof (value)]; result = (CGFloat)value / 10.0f; } return result; } What I have so

Unzip NSData folder from URL Swift

旧巷老猫 提交于 2019-12-12 05:01:02
问题 The code below works for downloading a single image from a url. func imageForImageURLString(imageURLString: String, completion: (image: UIImage?, success: Bool) -> Void) { guard let url = NSURL(string: imageURLString), let data = NSData(contentsOfURL: url), let image = UIImage(data: data) else { completion(image: UIImage(named:"absolut5.png"), success: false); return } completion(image: image, success: true) } however some of the urls I am working with are a zipped folder with several png

NSString to NSData conversion to Hex Value [duplicate]

我的未来我决定 提交于 2019-12-12 04:41:35
问题 This question already has answers here : Converting HEX NSString To NSData (4 answers) Closed 5 years ago . I've been trying to convert a user defaults NSString (tried NSData also), into a hex value I can use with char array. the problem is that every time I convert it from the NSString or NSData it takes the hex values and turns them into ASCII values, which isn't what I want at all. how to I tell it to literally take the values that are there and keep them hex? I'm struggling to find a

NSURL to NSDATA or Data is always nil

夙愿已清 提交于 2019-12-12 03:43:21
问题 I am trying to upload a video to a server file through Alamofire but I couldn't get the "data" going to be passed..its always nil var videoURL = NSURL(string: "") //returns Optional(file:///private/var/mobile/Containers/Data/Application/1FB40086-228B-4011-A9D4-7874E2EEF9F4/tmp/4A6AAD76-B899-4B67-8E96-925DA4AE9E93.mov) let videodata = NSData(contentsOfFile: (videoURL?.absoluteString)!) //nil let url = NSURL(fileURLWithPath: (videoURL?.absoluteString)!) let videodata = NSData(contentsOf: url as