ryanmaxwell / UIAlertView-Blocks

Category on UIAlertView to use inline block callbacks instead of delegate callbacks.
MIT License
425 stars 58 forks source link

NSArray firstObject is available only since iOS7. #9

Closed ClioMobile closed 10 years ago

ClioMobile commented 10 years ago

NSArray firstObject was used and is only available since iOS7. The change I propose doesn't use it and keeps compatibility with older SDKs (which according to the readme and the podspec are still supported).

Hope it helps.

ryanmaxwell commented 10 years ago

Thanks - according to the docs firstObject has been available since iOS4 (and lastObject since the beginning). I've merged your commit anyway, but could you extrapolate/provide a sample where you were seeing the issue?

ClioMobile commented 10 years ago

Sure I actually checked the doc as well and was confused. I just used UIAlertView+Blocks in a project using XCode 4.6 building with SDK 6.1 and I got an error for using firstObject.

So according to NSHipster and RayWenderlich firstObject was implemented since iOS4, but private until iOS7. If you still have an XCode 4 around you can check in NSArray's header that firstObject is not present. The reason they can state it is available since iOS4 in the docs, is that it is implemented since then and they just made it public in iOS7.

When building with SDK < 7 you can actually add firstObject in you own header extension and you to get access to it. But that would be using private APIs. So since Apple is not accepting apps build with XCode 4 anymore one could argue that you can use firstObject. But my app is for enterprise and we are still on SDK 6.1 and I'd like to avoid using private APIs. So actually it's your call if you want to support building apps with SDK < 7.

Hope that clears it up and thank you for sharing your code.

ryanmaxwell commented 10 years ago

I'm cool with it. I'm going to modernize the syntax though to use subscripting!