{"id":4557,"date":"2012-03-26T12:15:42","date_gmt":"2012-03-26T17:15:42","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=4557"},"modified":"2012-03-30T13:30:47","modified_gmt":"2012-03-30T18:30:47","slug":"isequal-vs-isequaltostring-vs-compare","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2012\/03\/26\/isequal-vs-isequaltostring-vs-compare\/","title":{"rendered":"isEqual: vs. isEqualToString: vs. compare:"},"content":{"rendered":"<p><a href=\"http:\/\/weblog.bignerdranch.com\/?p=334\">Mark Dalrymple<\/a>:<\/p>\n<blockquote cite=\"http:\/\/weblog.bignerdranch.com\/?p=334\"><p>The conclusion I draw at this point is that your choice of <code>isEqual:<\/code> and <code>isEqualToString:<\/code> is purely stylistic.  If you have a lot of <code>isEqual:<\/code> calls in a method comparing other objects, go ahead and use <code>isEqual:<\/code>.  If you want to tell the reader that you&#8217;re only expecting strings to be involved, use <code>isEqualToString:<\/code>.  I believe that the demonstrated corner case makes any safety benefits moot in choosing which method to use.<\/p><\/blockquote>\n<p>The main point I would emphasize is the need to check for <code>nil<\/code> before using <code>compare:<\/code>, because if the receiver is <code>nil<\/code> you&rsquo;ll always get <code>NSOrderedSame<\/code>. I like to use category methods such as <code>mjtCaseInsensitiveIsEqual:<\/code> where the result from a <code>nil<\/code> receiver will be what you expect.<\/p>\n<p>Update (2012-03-30): Dalrymple has a <a href=\"http:\/\/weblog.bignerdranch.com\/?p=439\">follow-up post<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<p>Mark Dalrymple: The conclusion I draw at this point is that your choice of isEqual: and isEqualToString: is purely stylistic. If you have a lot of isEqual: calls in a method comparing other objects, go ahead and use isEqual:. If you want to tell the reader that you&#8217;re only expecting strings to be involved, use [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-4557","post","type-post","status-publish","format-standard","hentry","category-programming-category"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/4557","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=4557"}],"version-history":[{"count":6,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/4557\/revisions"}],"predecessor-version":[{"id":4587,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/4557\/revisions\/4587"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=4557"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=4557"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=4557"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}