Friday, April 15, 2016

Re: trying to get last object of all arrays in an array

-----BEGIN PGP SIGNATURE-----

iQIcBAEBAgAGBQJXEeEJAAoJEMDDf5BSWPLdATAP/AweZ1CnvsNpcNeRSnuGZI6V
NSfGPUNcvvHv6o6leGlVpfwS8PTZTLHGhUIVSqaVbxuBhTe1EWLE+yDBVT7iaU68
stDMx9EdL/U6IL1aUPye46rD3grPnMNO7teyZAk4+Wo1CS7IgO/4oDbtnmCC83Yf
+gndNFKwE/yIeYxc7ATRNFbbReI3Nh8F8csGWk6gMxHRhEmTA1lrF/5P9GiD9qtf
zBUhQNyFiG/+yAnW3+K02r8faurg9PXtdnbVHNEiDCtqlQDL1v2Mtw/V0S5fzZkQ
u2dDhVe1NqZrmaco9jaazOTLTrpOMnk3tuSsAXD+z9Vh7yMB1LD0YL0OPrqlQfnW
v3E78x5IaI4f9EiIwghkPWMkw86EHO533+5/ualX48RDmOQct07KuSI3tBZdO21k
g6XztgzEM6/2X+pbnt/HvWPSfHs+tJkkbPKxBup2IMqA3Uz5A5CWhaZ5RZA5TDJR
bfMJhjDZBAnXLtRgqBCaAaQa5iVhHtNLnbboN2/kfceVlEaEww2oj+zIxCRBOFtp
ZTk5rzjycbkG9soq73iTYfAEkivuAjFNv/YBmAnSkuFVMjeM48aucRGFjhMyC2BA
S/97QRgAZGKB92dR6V6EJAAxeKL7+BafgvIiZTIFRv6HBRuhHAlmOfwtyzNyrBi6
0BqL2yUZxLkgFYv4NdIG
=xfRc
-----END PGP SIGNATURE-----
-[NSArray valueForKey:] simply calls through to its members, so it makes sense that the lastObject would bubble down to the strings themselves.

You should probably be using a dictionary. If order matters; something like https://github.com/fjolnir/DatabaseKit/blob/master/Source/Utilities/DBOrderedDictionary.m should work.

—fjõlnir


On 16 Apr 2016, at 15:18, Patrick J. Collins wrote:

> If I have:
>
> NSArray *arr = @[
> @[@"lol", @"omg"],
> @[@"rofl", @"copter"],
> ...
> ];
>
> I want to be able to do:
>
> [arr valueForKey:@"lastObject"]
>
> and get back:
>
> @[@"omg", @"copter"]
>
> However, when I try this, I keep getting bad access saying that the
> object doesnt respond to lastObject... ?
>
> What am I doing wrong?
>
>
> Patrick J. Collins
> http://collinatorstudios.com
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Objc-language mailing list (Objc-language@lists.apple.com)
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/objc-language/fjolnir%40asgeirsson.is
>
> This email sent to fjolnir@asgeirsson.is

No comments:

Post a Comment