{"id":4899,"date":"2022-03-24T23:55:05","date_gmt":"2022-03-24T15:55:05","guid":{"rendered":"https:\/\/1989lifejourney.com\/?p=4899"},"modified":"2022-03-24T23:55:05","modified_gmt":"2022-03-24T15:55:05","slug":"anyobject-v-s-any-in-swift","status":"publish","type":"post","link":"https:\/\/1989lifejourney.com\/?p=4899","title":{"rendered":"AnyObject v.s. Any in Swift"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">AnyObject<\/h2>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">AnyObject can represent an instance of any class type.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1)<\/strong><br>AnyObject can be used as the concrete type for an instance of any <strong>class, class type, or class-only protocol<\/strong>.<br><strong>Example:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class TestB {}\nvar tmp1: AnyObject = TestB()\nvar tmp2: AnyObject = TestB.self\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2)<\/strong><br>AnyObject can also be used as the concrete type for <strong>an instance of a type that bridges to an Objective-C class.<\/strong> Many value types in Swift bridge to Objective-C counterparts, like String and Int.<br><strong>Example:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var tmp: AnyObject = \"This is a string\" as NSString\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Any<\/h2>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Any can represent an instance of any type at all, including function types, optional types.<br><strong>Example:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var closure: () -&gt; Void = {}\nvar tmp: Any = closure()<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Ref:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/medium.com\/@mimicatcodes\/any-vs-anyobject-in-swift-3-b1a8d3a02e00\">https:\/\/medium.com\/@mimicatcodes\/any-vs-anyobject-in-swift-3-b1a8d3a02e00<br><\/a><a href=\"https:\/\/developer.apple.com\/documentation\/swift\/anyobject\">https:\/\/developer.apple.com\/documentation\/swift\/anyobject<br><\/a><a href=\"https:\/\/docs.swift.org\/swift-book\/LanguageGuide\/TypeCasting.html\">https:\/\/docs.swift.org\/swift-book\/LanguageGuide\/TypeCasting.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>AnyObject AnyObject can represent an instance of any cl [&hellip;]<\/p>\n","protected":false},"author":139426785,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","_postgate_lock_override":"inherit","_postgate_lock_mode":"inherit","_postgate_preview_mode":"inherit","_postgate_preview_limit":0,"_postgate_product_ids":[],"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_seo_schema_type":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_wpcom_ai_launchpad_first_post":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"{title}\n\n{excerpt}\n\n{url}","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"_wpas_customize_per_network":false,"jetpack_post_was_ever_published":false},"categories":[37324612,1],"tags":[],"post_folder":[],"class_list":["post-4899","post","type-post","status-publish","format-standard","hentry","category-ios-development","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/paR5vw-1h1","jetpack-related-posts":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/1989lifejourney.com\/index.php?rest_route=\/wp\/v2\/posts\/4899","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/1989lifejourney.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/1989lifejourney.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/1989lifejourney.com\/index.php?rest_route=\/wp\/v2\/users\/139426785"}],"replies":[{"embeddable":true,"href":"https:\/\/1989lifejourney.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4899"}],"version-history":[{"count":4,"href":"https:\/\/1989lifejourney.com\/index.php?rest_route=\/wp\/v2\/posts\/4899\/revisions"}],"predecessor-version":[{"id":4903,"href":"https:\/\/1989lifejourney.com\/index.php?rest_route=\/wp\/v2\/posts\/4899\/revisions\/4903"}],"wp:attachment":[{"href":"https:\/\/1989lifejourney.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4899"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/1989lifejourney.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4899"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/1989lifejourney.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4899"},{"taxonomy":"post_folder","embeddable":true,"href":"https:\/\/1989lifejourney.com\/index.php?rest_route=%2Fwp%2Fv2%2Fpost_folder&post=4899"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}