Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-c: What does return type __strong const char * mean?

Tags:

objective-c

When reading the headers of Foundation I found this:

- (__strong const char *)UTF8String NS_RETURNS_INNER_POINTER;   
// Convenience to return null-terminated UTF8 representation

This is from NSString.h in the iOS 7.1 SDK, what does __strong const char * mean here?

I'm most confused about the "__strong" here.

like image 793
CarmeloS Avatar asked May 19 '14 07:05

CarmeloS


People also ask

What does const char* mean?

const char* is a mutable pointer to an immutable character/string. You cannot change the contents of the location(s) this pointer points to. Also, compilers are required to give error messages when you try to do so. For the same reason, conversion from const char * to char* is deprecated.

Can a char * be passed as const * argument?

In general, you can pass a char * into something that expects a const char * without an explicit cast because that's a safe thing to do (give something modifiable to something that doesn't intend to modify it), but you can't pass a const char * into something expecting a char * (without an explicit cast) because that's ...


1 Answers

Foundation is shared between iOS and Mac OS. On Mac OS, for a while there existed a garbage collection memory management system. It's now deprecated and not longer supported on Mac OS. It was never used on iOS.

GC used __strong as a modifier on plain pointer type declarations to make the pointed to memory collectible. This usage of __strong has no meaning in ARC or manual retain/release code. The fact that there's no warning for the declaration is probably only because clang issues no warnings in system headers.

like image 170
Nikolai Ruhe Avatar answered Oct 13 '22 10:10

Nikolai Ruhe