4

Return NSString from a C function

 3 years ago
source link: https://www.codesd.com/item/return-nsstring-from-a-c-function.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Return NSString from a C function

advertisements

In iOS development, is it possible to use NSString and return it from a function?

(NSString * ) foo {
  return @"";

}

This is not an objective c method, just function


Yes, seeing as objective-c objects are just pointers, you can create a C function to return one:

NS_RETURNS_RETAINED NSString *myFunction() {
    return [[NSString alloc] init];
}

Notice the use of NS_RETURNS_RETAINED. This is a hint to ARC and the static analyzer that this function returns a retained value to the receiver, and that it's their responsibility to release it.

If you were returning an autoreleased value, try using NS_RETURNS_NOT_RETAINED instead.

Related Articles

How do I access a return value from a jQuery function

I'm wondering how how access returned values from a jQuery function. I know the basic way with a javascript function like so: "var myVar=myFunction();" But can anyone please show me how I would do it with a jQuery function like this? If i was lo

Get the return value from a callback function -JQuery

I'm new to jQuery and I know this is probably super easy. I wanna get the returned value from a callback function in an event. Code is here: $('.hintItem').on('mouseenter', function(e){ changeItemStyle(e); var hintItemIndex = $(this).index(); return

Return JSON from a PHP function

I want to transform this PHP function.. that should return JSON data. <?php $query = 'SELECT * FROM `' . mix_player::table() . '` a'; if (isset($_GET['cat']) || isset($_GET['order'])) if (isset($_GET['cat'])) { $query .= ' INNER JOIN `' . mix_player:

How do I return jsx from an external function with callback?

I am trying to return jsx from outside my render method. It works when there is no api request, but as soon as I add the request and add a callback I can't return the jsx. How do I do this? renderLocations is being called in my render method. renderL

Char Array multidimensional return error from a C function

I have such a function in C: char **collect_character_distribution(char *buffer, long lSize) { printf("Collecting character distribution...\n"); long x; char distribution[256][2] = {0}; for (x = 0; x < lSize; x++) { distribution[(int)buffer[x

Returning data from my JavaScript function

I have been having issues getting the data I am requesting to display correctly it was being displayed as undefined. fetch(url) .then(res => res.json()) .then((manager) => { /* console.log(manager); */ for (i in manager.data){ var row = $('<div i

NodeJS: return data from an asynchronous function

I'm trying to write a function to create a new user on my database (mongodb) and then return that user as an object which I defined. However, since the call to insert the user is async, result.nInserted is always undefined because the async code does

Why can not I return responseText from an Ajax function?

This question already has an answer here: How to return the response from an asynchronous call? 25 answers Here is part of my Ajax function. For some reason that I cannot figure out, I am able to alert() responseText but not able to return responseTe

how to return value from this public function?

Examle below must return user.photo_100 (and user.photo_100 response String, I logged it), but var wallPostUserAvatar set null. Looks like I missed something, but I can't find it out. public class WallPostExtends { private String wallPostUserAvatar;

Is it possible to get a return type from a keyboard function?

My current code is this and what I'm trying to is see if I could get a return value after the key up is done. $("#confirm").keyup(function(event){ event.preventDefault(); ajax_pass_check(); }); so I would end up with something like this because

not returning anything from the postgresql function?

Is it possible for a PostgreSQL plpgsql function to not return anything? I've created a function, and I don't need it to return anything at all, as it performs a complex SQL query, and inserts the results of that query into another table (SELECT INTO

Return char * from the dllexported function

I'm creating a DLL which will be used by some external exe file. One of the exposed function is ... char *current_version = "1.1"; ... extern "C" _declspec(dllexport) char* version(){ return current_version; } Because the current versi

How to return null from a generic function in Scala?

I am writing my own simple javax.sql.DataSource implementation, the only method of it I need to work is getConnection: Connection, but the interface inherits many other methods (which I don't need) from javax.sql.CommonDataSource and java.sql.Wrapper

Can not return list items from the Python function

I have a function, table(), that reads a csv file and returns the rows in individual lists. I want to map these lists to create a dictionary, with field headers being the keys and the underlying rows being the values. I cannot seem to do this however

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK