FlutterStandardTypedData to array of int64 in objective C - objective-c

I am sorry I am not objective c developer but need to make a simple fix in flutter plugin code.
So my question:
In the objective c code I have this:
FlutterStandardTypedData *data = [call arguments];
data is array of ints coming from flutter side. How can I access these ints by index?
Thanks!

Related

multidemsional array objective c

I have made multidemensional arrays in c++ but I am confused on how to do this in objective c because it is a modified version of c. How would I go about making a multidimensional array in Objective C?
NSArray *twoDArray = #[#[#"0.0", #"0.1"],
#[#"1.0", #"1.1", #"1.2"],
#[#"2.0", #"2.1", #"2.2"]
];
Access it like:
// result = "0.1"
NSString *result = twoDArray[0][1];
// result = "1.2"
result = twoDArray[1][2];
// result = "2.0"
result = twoDArray[2][0];
You don't really use them much differently than you would in C, although (per the comments) they do function quite differently. Objective-C is also not really a modified version of C. It is everything that C is, plus more. So it really does not modify anything about C.
This syntax (for creating and accessing the array values) is also relatively new, for more information you can look at the documentation and this answer, which both outline some other features of Objective-C literals.

How to run code snippets in Objective-C

While trying to learn Objective C from a book, I'd like to be able to run some code snippets like...
NSString *str = #"Hello, world!";
NSLog(#"Retain count is %d", [str retainCount]);
In Ruby I'd just put this in an snippet.rb file and run ruby snippet.rb from the terminal. JavaScript has jsfiddle.net. Is there an equally easy way to do this with objective c?
If you're on a Mac there's the handy CodeRunner. It's $9.99 on the App Store but to me it was worth every penny.

ObjC structs of floats in arrays: Compact way to avoid NSValue?

I'm to port some JS to native ObjC code. Since a struct won't fit inside arrays, it needs to be wrapped.
The JS code goes as follows:
var bezierVertices = [{0: 14},{10: 32},{24: 16}];
Plain and easy JS: Array of anonymous objects.
I'm bound to the following requirement: Have the code as compact as possible, meaning I've been refused when proposing an NSArray of NSValue using [NSValue valueWithCGPoint:ccp(x,y)]
Going down the malloc way doesn't fit this criterion either. They want something as compact as the JS stated above.
Before writing something as ugly as an NSString like #"0:14;10:32;24:16"; that's split and parsed in a loop, I thought SO could help bring something clean :)
I'm allowed to use .mm so ObjC++ solutions could fit as well, but I'm not knowledgeable about C++ at all...
Thanks!
J.
They want something as compact as the JS stated above
Who's "they"? Do "they" have any understanding that Objective-C is a compiled language and the "compactness" of the source code is largely irrelevant?
Anyway, rant over. You can make a C array of CGPoints like this:
CGPoint myArray[] = {{0.0, 14.0}, {10.0, 32.0}, {24.0, 16.0}};
This is a standard C array initialiser. You get the number of elements like this:
int nElements = sizeof myArray / sizeof(CGPoint);
If you need to manage variable-length arrays of vertices, C++ provides std::vector<CGPoint>.

Elegant ways to use Objective C while developing an iOs / OsX application?

I've been developing iOs and OsX applications for several months now and it still feels like I'm doing something wrong. I try to stick to the Guidelines and I try to use the objects Apple provides as often as I can. But it seems they are making my code very hard to understand.
Example:
When I want to just "increment" a NSNumber Object (which is not mutable, but you get what I mean), I use awkward lines like this:
int value = [counter intValue];
counter = [NSNumber numberWithInt:value +1];
Is this really necessary? Are there more elegant ways (i++, inc(i), etc) to do simple things like this? Especially when you're working with coordinates it gets really frustrating and hard to work with.
When working with Objective C I feel like I'm allocating, deallocating and converting objects all the time and wasting so much of my own time and the CPU time with all those conversions. Thanks for your time, I really appreciate your answers and I'm looking forward to your tipps!
Using your example, is there any particular reason you are using NSNumber for a counter? It would be much better to use int so that you can use value++.
The key to good Objective-C code is to use objects when they make sense. Don't be afraid to use non-object data types and don't be afraid to drop down (not the best term) to C when required.
As #sosborn wrote: use objects only when it's required. But: when it's required, and you still feel wrong, simply don't. Write a macro for incrementing an NSNumber, use ARC for let the compiler do the memory management for you as efficiently as possible, etc. If you really worried about time, use C or assembly for time-critical tasks, or C++ if you want OO.
P. s.: NSNumber increment macro:
#define NSNUM_INC(n) do { n = [NSNumber numberWithInt:[n intValue] + 1]; } while (0);
You can write your category for NSNumber to implement the methods you need. For your example the file of category contains the following function:
-(NSNumber *)numberByAddingInt:(int)i
{
...
}
Include this file and then you can call it as:
counter = [counter numberByAddingInt:1];

Calling an Objective C function from a C function passing an array of floats

I´m trying to pass a reference of array of floats.
The problem is the call, because I´am developing for c but I want to make a call to an Objective C Function, Could anyone help me? How can I make the call?
There you have the code:
bool VideoCamera_Camera(float *buffer) {
[VideoCameraBinded VideoCamera_CameraUpdateBinded: buffer];
}
Thank you
I'm going to assume that VideoCameraBinded is an instance, and not a class. If I am mistaken, please let me know.
If you have a method defined on VideoCameraBinded's class, something like this:
- (void)VideoCamera_CameraUpdateBinded:(float *)buffer {
//...
}
then I don't know where your problem is coming from. Are you getting a specific error or some other issue?
If you have access to and can change the Objective-C code, add a C API there.
Otherwise, if you really can't change the Objective-C code you can use the Objective-C runtime directly, but this is discouraged:
#include <objc/runtime.h>
objc_msgSend(VideoCameraBinded, // receiver
sel_registerName("VideoCamera_CameraUpdateBinded:"), // selector
buffer); // comma separated list of arguments
You need to link to an Objective-C runtime library, usually libobjc:
$ clang mycode.c -lobjc
$ # or cc if you use GCC
If the Objective-C method expects an NSArray * instead of a float *, you can use Core Foundation with CFArrayRef. CFArrayRef and NSArray * are interchangeable, but CFArrayRef is a C type so you can use that. Same goes for CFNumberRef and NSNumber *, see Apple's documentation on this.
What is the parameter type for VideoCamera_CameraUpdateBinded:?
If its NSArray then you have to loop, create an array and send it like any other obj-c method. You'll have to store the floats in some kind of objects (e.g. NSNumber).
Otherwise, if the obj-c function is taking a float* then you should be good to go.
BTW, shouldn't you pass a bufferSize parameter too?