Flutterby™! : More about the platform than I wanted to know

Next unread comment / Catchup all unread comments User Account Info | Logout | XML/Pilot/etc versions | Long version (with comments) | Weblog archives | Site Map | | Browse Topics

More about the platform than I wanted to know

2024-06-03 19:41:40.181065+02 by Dan Lyke 5 comments

So, in Objective-C, if you do:

self.itemsDataNew = [@[] copy];
self.itemsDataFeed = [@[] copy];

Do they point to the same empty array object, or different ones?

Damn it, Apple...

[ related topics: Apple Computer Interactive Drama ]

comments in ascending chronological order (reverse):

#Comment Re: More about the platform than I wanted to know made: 2024-06-03 19:51:46.119226+02 by: markd

I'd say they point to the same empty array object. The empty set is the empty set, and since it's an immutable copy, it can't be changed, so why pay the price of another malloc. In general, I believe a copy to an immutable array (not a mutable one hidden behind an immutable type) returns `self` as an optimization.

Identity checks on Foundation objects are always slippery, given the class cluster(fuck) architecture of the fundamental collection and string types.

From a test, it looks like `copy` has a common empty array that it uses. doing [@[] mutableCopy] will give you a different address, but if you(immutable) copy that[Wiki], you'll get the same address as @[] and [@[] copy]. I imagine the `copy` implementation starts with if (source.count == 0) return SharedSingletonCommonEmptyArray;

#Comment Re: More about the platform than I wanted to know made: 2024-06-04 01:56:08.718655+02 by: Dan Lyke [edit history]

And you've clearly done more Objective-C than anyone else who responded on Mastodon.... Moved to mutable arrays and everything works like I'd expect (because I'm using these arrays in an NSOutlineView and using their relationship to those member pointers for additional information about them).

#Comment Re: More about the platform than I wanted to know made: 2024-06-04 01:56:30.499723+02 by: Dan Lyke [edit history]

Whoops. Double post.

#Comment Re: More about the platform than I wanted to know made: 2024-06-04 02:03:47.936171+02 by: TheSHAD0W

I mean, that's something testable. If you insert something into itemsDataNew and it shows up in itemsDataFeed you know you have an issue. Of course, you'll have to hope a code change doesn't screw that up.

#Comment Re: More about the platform than I wanted to know made: 2024-06-04 16:57:17.157457+02 by: Dan Lyke

It's made a little harder by the fact that Objective-C managed arrays are by default read-only. So, yeah, the solution was to make them mutable arrays.

Add your own comment:

(If anyone ever actually uses Webmention/indie-action to post here, please email me)




Format with:

(You should probably use "Text" mode: URLs will be mostly recognized and linked, _underscore quoted_ text is looked up in a glossary, _underscore quoted_ (http://xyz.pdq) becomes a link, without the link in the parenthesis it becomes a <cite> tag. All <cite>ed text will point to the Flutterby knowledge base. Two enters (ie: a blank line) gets you a new paragraph, special treatment for paragraphs that are manually indented or start with "#" (as in "#include" or "#!/usr/bin/perl"), "/* " or ">" (as in a quoted message) or look like lists, or within a paragraph you can use a number of HTML tags:

p, img, br, hr, a, sub, sup, tt, i, b, h1, h2, h3, h4, h5, h6, cite, em, strong, code, samp, kbd, pre, blockquote, address, ol, dl, ul, dt, dd, li, dir, menu, table, tr, td, th

Comment policy

We will not edit your comments. However, we may delete your comments, or cause them to be hidden behind another link, if we feel they detract from the conversation. Commercial plugs are fine, if they are relevant to the conversation, and if you don't try to pretend to be a consumer. Annoying endorsements will be deleted if you're lucky, if you're not a whole bunch of people smarter and more articulate than you will ridicule you, and we will leave such ridicule in place.


Flutterby™ is a trademark claimed by

Dan Lyke
for the web publications at www.flutterby.com and www.flutterby.net.