Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6374647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:30:51+00:00 2026-05-25T01:30:51+00:00

As part of learning Objective C I had an excerise where a a third

  • 0

As part of learning Objective C I had an excerise where a a third party library returns a random object . I then need to check if it is an instance of UIView and then check is it has back groundColor proprty . If it does then I set it to some random color.
Code below does that but I am curious that what if it was a mute object and even if you have this property you can not change it how would you test for that.

here is the code which run fine as such without problems but just curious also let me know any thing else you see I am doing wrong. Like I said end result is ok

id myView = [RandomObjectFactory randomNSObject];
    UIView* parentView =[self view];
    if ([myView isKindOfClass:[UIView class]])
    {
        UIView* uiView = (UIView*) myView;
        SEL sel = @selector(backgroundColor);
        if([uiView respondsToSelector:sel])
        {
            UIColor *textColour = [UIColor  colorWithRed:0.1 green:0.2 blue:0.1 alpha:1.0];
            [uiView setBackgroundColor:textColour];
        }

        [parentView addSubview:uiView];
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:30:52+00:00Added an answer on May 25, 2026 at 1:30 am

    You should check for selector

     setBackgroundColor: 
    

    as well, this would ensure that the property is not read only. You can then check the result of backgroundColor before and after you call setBackgroundColor, to ensure that the value has indeed been set. In this case you know it will be as you are aware of the properties of UIView but I imagine you are looking for a more general solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have had to start to learning C as part of a project that
As part of learning jQuery, I decided to do a simple tic-tac-toe game in
As part of my learning, i am developing a google maps V3 application, to
I just uploaded my first ASP.NET (as part of my learning of vb.net) and
I'm learning DirectX as part of a hobby project. I've been looking for some
I am learning to use LabVIEW as part of my honours project, and was
I just started learning C but I don't understand this part of the code.
I'm learning about change listeners and would like to find out why a part
I'm learning SharePoint development. I read some general how to build a web part,
I need to convert a string to a JSON object that gets returned from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.