If I put an NSURL in a class declaration and set it to something in a method, when the method finishes the object it's pointing to is gone. Is there a way to have a non pointer version of an object in the declaration like you can in C++? XCode doesn't seem to want to let me.
Asked
Active
Viewed 94 times
1 Answers
0
Is there a way to have a non pointer version of an object in the declaration like you can in C++? XCode doesn't seem to want to let me.
NSObject types don't support this. Even creating your own root objc class is not supported with Clang (you could do it with GCC if you were geeky enough). Thus, the short answer is "No, you can't declare a NSObject type by value".
But that's not really important; the right solution is to figure out why your member is cleared -- using ref counted pointers works for everybody else.

justin
- 104,054
- 14
- 179
- 226
-
the imp I have is about 500 lines. here's the outline: using GCC, declare a root class, think up an initialization scheme which uses `object_setClass` to init the `isa` -- you don't want `alloc`+`init`, but something different. add a few more touches from objc runtime for the basic interfaces (e.g. property support). this won't work with clang or GC, btw. – justin Jan 31 '12 at 11:56
-
is there not a simpler way of being able to have a method set an NSURL that you can then access from another place and use to go to it? – Dollarslice Jan 31 '12 at 12:09
-
ehm - i'm not sure what exactly you're asking. do you mean "how do you declare an instance variable and use reference counting?" ? if so, it's as simple as an `int` in C++, but you need to do the reference counting if you're not using ARC or GC. – justin Jan 31 '12 at 12:16
-
well if I set my NSURL like this in a method `url = [match URL];` (got from an NSDataDetector, then try to use it in another method I get EXC_BAD_ACCESS. – Dollarslice Jan 31 '12 at 12:21
-
1you'll need memory management boot camp to use objc with manual reference counting. http://interfacelab.com/objective-c-memory-management-for-lazy-people/ (i've not read it, but it looks like a start) – justin Jan 31 '12 at 13:58