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,480
questions
-1
votes
1
answer
34
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
39
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
28
views
How can I return the position of an [UInt8] object? So far this is all I have been able to create. Any suggestions as too what I could change?
I wanted to create a class that would covert a file of type string into an array object of type [UInt8]. So far this is what I have, but I have been able to return the length of new array of type [...
0
votes
0
answers
8
views
How do I convert an struct of type Data to an object of type CNGroup?
I'm having trouble converting a CNGroup object to a Data object and back to a CNGroup object. I decided to start rethinking the problem again. Somewhere along the way I decided that I should use the ...
0
votes
0
answers
21
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 ...
0
votes
1
answer
198
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
87
views
iOS convert CIImage to Data without metadata loss
I am trying to convert a CIImage object to Data object. When I do it like this the modified metadata (exif and gps) gets lost.
func ciImageToData(ciimage: CIImage) -> Data? {
guard let ...
0
votes
0
answers
29
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
55
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
46
views
How to save and retrieve UIImageView in local storage as Data?
I have made app that parse SVG paths and convert them into CAShapeLayers and add them to UIImageView. I made some changes in it and want to save it as Data for future edit.
But I don't know how?
Any ...
0
votes
0
answers
56
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 ...
1
vote
1
answer
201
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
91
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
93
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 ...
0
votes
2
answers
201
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 ...
0
votes
0
answers
34
views
Swift: write a function that resizes an image to a certain size and lowers its compression quality
I would like to write a function that takes a given UIImage as its input, resizing it if needed so the greatest edge would not exceed a given size, and transforming it as a JPG image with a ...
1
vote
1
answer
435
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
37
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
221
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
463
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
127
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
51
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
33
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
98
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
55
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
26
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())
...
0
votes
1
answer
97
views
Convert NSData to float array 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
689
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
37
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
212
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
162
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
193
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
80
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
132
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
225
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
69
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
78
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
66
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
49
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 ...
0
votes
2
answers
362
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
53
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:...
1
vote
0
answers
458
views
Convert Base64 string to audio file in swift
I received a base64 string(string is too long) from the XML parsing which I want to convert into an audio file and I do write that base64 string converting into the NSData and successfully write in ...
-1
votes
1
answer
54
views
Get Int from NSData
I am using a library which has the ability to pull data from a BTLE device and place it in NSData. However i need to pull out the individual lines of data into int's. How do i do this?
here is the ...
0
votes
0
answers
73
views
NSURLSessionConfiguration and NSData always returning nil
I am new to Mac application development and i am working on fixing the deprecation issues present in the application. I am using XCode 11.3 in Mojave MacOS 10.14 and Our application contains the ...
1
vote
1
answer
130
views
Swift -How to know if a file was successfully saved in .cachesDirectory
I have a .mp4 video saved in Firebase and I want to save it to the .cachesDirectory. I want to make sure it is saved and tried to use a do-try block but it wouldn't accept it:
No calls to throwing ...
1
vote
0
answers
114
views
Can't decrypt NSData when running BGProcessingTask
I setup everything to run some code in the background when my app isn't active. I use BGProcessingTask.
When I Pause the program execution, and enter the command e -l objc -- (void)[[BGTaskScheduler ...
1
vote
1
answer
164
views
Convert DATA to Date
I am trying to get last used date of a file using NSFileManager, i am getting the date in NSData format but i am not sure how to convert Data to Date.
I am getting below values from NSFileManager
...
8
votes
1
answer
5k
views
How can I convert from UIImage to HEIF / HEIC Data in Swift?
Is NSKeyedArchiver appropriate to convert UIImage to Data?
do {
let data = try NSKeyedArchiver.archivedData(withRootObject: UIImage(named: somePath), requiringSecureCoding: true)
...
} catch {...
0
votes
0
answers
74
views
Recommendation on how to store mp3 and image files in Core Data which is synced with CloudKit
I have an app that needs to work offline but sync across devices. The plan is to use Core Data and CloudKit to achieve this.
My question is how to store mp3 and image files (small file sizes). Is it ...
4
votes
4
answers
367
views
Objective-C to C++ reading binary file into multidimensional array of float
I want to convert the following code from objective C to C++.
In the class myClass, I have this attribute:
float tab[dim1][dim2][dim3];
In an objective-C file, the multidimensional array is filled ...