Return NSString from a C function
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
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
Get the return value from a callback function -JQuery
Return JSON from a PHP function
How do I return jsx from an external function with callback?
Char Array multidimensional return error from a C function
Returning data from my JavaScript function
NodeJS: return data from an asynchronous function
Why can not I return responseText from an Ajax function?
how to return value from this public function?
Is it possible to get a return type from a keyboard function?
not returning anything from the postgresql function?
Return char * from the dllexported function
How to return null from a generic function in Scala?
Can not return list items from the Python function
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK