Questions tagged [nsdata]
The NSData class is an Apple class for holding generic data. Often used when reading/writing from and to files, and the internet.
2,486
questions
1
vote
0
answers
39
views
Download mp4 file from link and save to documents directory in IOS Swift or Objective-C
I would like app users to be able to to download MP4 files from a remote link and save them to the local app documents directory (not photos). I'm guessing this may create storage problems at some ...
0
votes
0
answers
36
views
How to find and remove strings in nsdata
I'm working on converting vcard to cncontact.
I'm using CNContactVCardSerialization.contacts(with data: Data).
However, when I tried to import 4000 contacts using that method, I was only able to ...
0
votes
0
answers
25
views
Convert Data to stream of CVPixelBuffer
How to convert Data to stream of CVPixelBuffer,
I am working on CVPixelBuffer output from AVSession and ARSession.
following is the code on which I am converting CVPixelBuffer to Data and able to save ...
1
vote
1
answer
35
views
Release NSData not release all memory
I'm using this code to get NSData of a specific file:
NSData* data = [[NSData alloc] initWithContentsOfURL:object.fileURL];
Before this line the memory usage was 18MB and after this line it become 66....
0
votes
1
answer
142
views
How to import AVIF image in iOS by PHPicker
I use PHPicker for user to import photos, but UIImage not support the pic of .AVIF, so I want to get the origin data of .AVIF pic, this is my code:
func picker(_ picker: PHPickerViewController, ...
1
vote
0
answers
340
views
How to get the NSData from a file path in KMM?
Currently, I am building the app in KMM, which has a feature to capture images.
Once the image is captured got the URL of the file, and then I am saving the path in SqlDelight DB.
I tried to save both ...
-2
votes
1
answer
102
views
Hexadecimal String to Byte Array Conversion
How to convert 0x01 into byte array in swift.
I need to convert "0x01" into byte array and then the resulting byte array need to share as NSData type
2
votes
0
answers
180
views
Create UnsafeMutableRawPointer from NSData
I'm converting a ObjC tutorial (Apple's Selecting Device Objects for Compute Processing tutorial, in particular) to Swift.
I am doing it in increments, so I have to interface to some code still ...
0
votes
1
answer
88
views
NSData subdataWithRange crashing
I have the following code and I am getting an exception with it.
-[_NSInlineData replaceBytesInRange:withBytes:]: unrecognized selector sent to instance 0x6000027ff2e0'
terminating with uncaught ...
0
votes
0
answers
46
views
NSMutableData increment the underneath pointer and pass it to other APIs
I have been given a task to replace all uint_8 * to NSMutableData.
In the existing code, a lot of pointer arithmetic is done on uint8_t and then passed onto other APIs which also accept uint8_t *.
...
0
votes
1
answer
204
views
In swift, how to download a json file from storage in Firestore?
I create a function to download a json file from urlLink in the storage of Firestore.
Here it is:
func chargerLObjetDeFirestore(urlLink: String, completion: @escaping (_ menuObject: MenuObjectPartager?...
-1
votes
2
answers
666
views
In Xcode 14 & iOS 16 - purple warning when downloading an image from URL with NSData dataWithContentsOfURL
In Xcode 14 & iOS 16 - purple warning when downloading an image from URL with NSData dataWithContentsOfURL
Synchronous URL loading of <URL> should not occur on this application's main thread ...
0
votes
1
answer
59
views
Display image on UIImageView using Web server image
I want to display an image on UIImageView calling the Web server image.
Because I want to replace and show it right away.
here's the code
NSURL *imageURL = [NSURL URLWithString:urlString];
NSData *...
3
votes
0
answers
299
views
iOS Swift how to convert AVCaptureSynchronizedSampleBufferData/AVCaptureVideoDataOutput to Data format or URL format
In my app i am using AVCaptureDataOutputSynchronizerDelegate for video output of recording through camera.
The data i got is AVCaptureSynchronizedSampleBufferData and i have to convert it into Data or ...
-1
votes
1
answer
39
views
Assigning Null to NSMutableData or checking if its empty
I need to return null or an empty value to identify an error condition. Since NSMutableData is not assignable to NULL in the following method, I'm just initialising it using the init() method.
Now ...
0
votes
0
answers
110
views
NSData methods equivalent in Java
I am trying to match iOS code to Java code, and I run into the problem. I read all the answers and as far as I understood I need to use ByteBuffer as an equivalent to NSData in Swift.
But I couldn't ...
0
votes
0
answers
30
views
Converting all NSData in a large NSDictionary to Hex-NSString in Swift
I have multiple large dynamically created NSDictionaries which contain (among other) multiple NSData objects.
I need to "pretty-print" this dictionary. Using -description I get a quite good ...
1
vote
1
answer
1k
views
Swift Data to Int array
I'd like to access the raw bytes in Data as an array of numeric types for quick parsing. I have lots of data to parse, so I'm looking for efficiency. Data is a mix of shorts, ints, longs, and ...
0
votes
0
answers
37
views
How to convert NSData to a C struct and use it in Swift program
the data should be binary data, it came from a 360 camera with bluetooth or wifi link ,it will call the function when data is prepared
//ins_gyro_info binary @property (nullable, nonatomic, strong) ...
0
votes
0
answers
109
views
NSData decompression taking too much time / slow
Basically I have simple Codable struct I want to save to disk with compression using lz4 algorithm, which seems to be the fastest one. Compresses with no problem and very fast, takes 2 ms, but ...
0
votes
0
answers
102
views
Find compression algorithm of NSData
When using decompressed(using:) method of NSData I have to provide a NSData.CompressionAlgorithm to uncompress the data.
Is there a way to detect the compression method of a NSData object so I don't ...
2
votes
1
answer
513
views
How to convert Objective-C NSData to Swift Data?
I have a NSData in Objective-C, the NSData has value 0x10, code like bellows:
@implementation BufUtil
+ (NSData *_Nonnull) getOCBuf {
std::vector<uint8_t> sendData = {0x10};
NSData * ...
0
votes
1
answer
429
views
Convert unsigned char* to NSData and vice-versa in Objective-C
Just want to convert NSData to Byte and Byte to NSData using objective-c
unsigned char* dataToByteArray = (unsigned char*) [data bytes];
NSLog(@"Bytes is %@", dataToByteArray);
...
0
votes
1
answer
139
views
How to make dataWithEPSInsideRect vector rather than bitmap in vector format?
Hello i'm trying to export data from an NSImageView as an EPS vector however the export doesn't appear to be vector but more like a bitmap in EPS format.
Can anyone suggest where I am going wrong and ...
1
vote
2
answers
855
views
How to convert `Date` to `Data`, and vice versa in Swift 5? [duplicate]
I'm trying to save a date in Keychain, and (from my understanding) this first requires converting the Date object into a Data object.
This Stack Overflow Q/A explains how to do it (or at least part of ...
1
vote
1
answer
952
views
Sending .MOV video file as part of POST request to own server as part of a multipart/form-data request in Swift not working
We are attempting to send video from iOS device or iOS simulator to our own server hosted on AWS using Swift and multipart/form-data post request.
We have the request setup in postman correctly and ...
1
vote
1
answer
58
views
Image from URL with .zip ending
I got a URL from which I need to extract an image. The image is PNG, however the URL look like this:
http://something.../something.zip
If I open this URL in safari, it automatically downloads a PNG. ...
0
votes
1
answer
725
views
Swift encode structs to data without having the full keys in the JSON
For protocol reasons, I have to convert my objects to Data. All methods I find online are using JSON for this, but since it's Swift-to-Swift, I am wondering whether there is a built-in mechanism ...
-1
votes
1
answer
1k
views
NSData.decompressed throws error in Swift
Hei folks, i want to decompress a gz file using NSData's decompressed method in Swift.
The file is loaded successfully into NSData, but if i try to decompress it, it trows error.
var data: NSData
let ...
0
votes
0
answers
277
views
How to pass NSData from javascript to swift 5?
I am trying to call the write method of CoreBluetooth from react-native. I have created a mediator class and created a write method on it.
Here it is:
@objc func write(_ serviceUUID: String, _ ...
0
votes
1
answer
146
views
Check whether the file retrieved from Firestore is empty
I need to make sure I can always feedback an Image object from the backend, but the thing is that it's not guaranteed that every query can get the image using the following function.
let store = ...
0
votes
1
answer
37
views
NSData result causing delay in NSTimer
I have a NSTimer which should fire its selector after 10 seconds. But due to delay in NSData result, timer is also getting delayed and it fires its selector after NSData operation is performed.
...
0
votes
0
answers
201
views
How to read the contents of a file into an NSArray using a url from UIDocumentPickerViewController?
I am not a developer but I am trying to create an app that reads in the contents of a wavefront obj file from the native iOS "Files" folder on the iPad that a user selects, get the contents ...
0
votes
0
answers
77
views
How to convert a keyedArchiver to a string and back again
I want to convert a custom object into a propertyList. Then later I want to retrieve it via NSOutlineView. I use a NSKeyedArchiver/unArchiver to convert my object to and from a NSData.
In my custom ...
0
votes
1
answer
77
views
Data constructor has different semantics when populating data across iOS versions
Here is the poc piece of code I had:
let text = "Hello, World"
let data = text.data(using: .utf8)! as CFData
let newData = Data(data as NSData)
print(newData.base64EncodedString())
...
1
vote
1
answer
449
views
Convert NSData to float array in Objective-C
What is the most efficient way to convert a NSData to a float array?
I've the following:
NSData* dataOutputNumDetections = [outputNumDetections dataWithError:&error];
NSLog(@"%@",...
0
votes
2
answers
1k
views
iOS Swift replace or update specific line in a file using file handle?
I am writing a point cloud file and need to keep updating the file header with the total number of points in a file: vertexCount. I don't know when the points will stop coming, so I can not just keep ...
1
vote
1
answer
72
views
iOS: How to generate public key using decimal X NSData and decimal Y NSData?
I have a method like this
+ (NSData *)getPublicKeyFromDecimalX:(NSData *)xInput decimalY:(NSData *)yInput { ... }
I know how to generate it when I have hexX: (NSData*) like this...
UInt8 iBytes[] = {...
0
votes
1
answer
416
views
Swift 5 - How to convert LONGBLOB/Buffer into Data
I am currently working on a project for school.
I have written an API using Express connected to a mysql database. And now I am writing the iOS app.
My problem is that I need to save profile pictures. ...
0
votes
0
answers
368
views
Swift Encoding a JSON dictionary [String: Any], can't get rid of the quotes
We are grabbing some data from an API, which we decode into a [String: Any] dictionary.
We want to then take this dictionary, and mutate a value for a key "$twitter_card".
Then we want to ...
0
votes
0
answers
295
views
How do I assemble and combine video data chunks in swift?
I have a very large video file and I have split the video NSDATA in chunks of 5mb, but now I want to assemble all those chunks into a single NSDATA again in original format so I can test that the ...
0
votes
1
answer
153
views
How to add padding to NSData so that it will be a multiple of 8 bytes?
In my code I construct a hex NSString first and then use the utility function below to convert it to NSData for transmission.
For example:
+ (NSData *)convertHexString:(NSString *)hexString {
NSString ...
0
votes
0
answers
262
views
How to combine and split Data in swift
I am working on sending encrypted messages between two or more devices on swift.
I have 3 constants of type Data: ephemeralPublicKey, ciphertext and signature
I need to combine all 3 of them into 1 ...
0
votes
0
answers
435
views
Permission Denied when read a local file using Data(contentsOf: URL)
The file I'm reading is (let data = try Data(contentsOf: url) ...)
url: file:///var/mobile/Containers/Data/Application/15666F33-0EA8-4F1B-BFBA-634EEE9FC97D/Documents/Attachments/Documents/test....
0
votes
1
answer
140
views
How to separate 16 bytes from Base 64 string in iOS using objective c?
Hello I am appending two NSDatas to form a NSMutableData using objective c . The code is given below:
NSData *data1 = key1;
NSData *data2 = encryptedData;
NSMutableData *completeData = [data1 ...
0
votes
1
answer
276
views
Convert a custom object to Data to be saved in NSUserDefauts
We have a custom object setup like so:
struct BallPark: Codable,Equatable {
static func == (lhs: LeanVenue, rhs: LeanVenue) -> Bool {
return lhs.id == rhs.id
}
let id: String
...
1
vote
1
answer
85
views
Storing the data representations of multiple, differently typed objects in a single Data instance
Motivation
To my knowledge, Data is a struct that abstracts a byte buffer. It references a physical area in memory, in other words: a contiguous number of bytes. Now I want to efficiently store ...
0
votes
0
answers
110
views
Converting attachment data string from Gmail API to Data always returns nil on iOS
I've been using this SO post (iOS - download attachment from Gmail using messageId and attachmentId) as a reference for
I've been able to make the API call, get the response data and parse out the ...
1
vote
2
answers
639
views
Saving nested dictionary into UserDefaults using Xcode and Swift
I'm trying to save a nested dictionary in userDefaults.
The app crashes when I try to save it the usual way, i.e.
defaults.set(totalBuy, forKey: "test")
and I get this error:
Terminating ...
0
votes
1
answer
67
views
Convert Large NSString to NSData in Notification Service Class
I receive long size payload of NSString in body payload of push notification that I need to convert it to NSData and then save it in corredata.
I am using the method:
dataUsingEncoding:...