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 8771819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:53:10+00:00 2026-06-13T17:53:10+00:00

This question is pure curiosity. In Xcode, why does this work: if (view.class ==

  • 0

This question is pure curiosity.

In Xcode, why does this work:

if (view.class == [UITextView class]) {
    UITextView *tview = (UITextView *)view;
    tview.textColor = [UIColor colorWithRed:0.020 green:0.549 blue:0.961 alpha:1.];
}

But the following results in the error message Property 'textColor' not found on object of type 'UIView *':

if (view.class == [UITextView class]) {
    (UITextView *)view.textColor = [UIColor colorWithRed:0.020 green:0.549 blue:0.961 alpha:1.];
}

Intuitively, these should accomplish the exact same thing.

But then if I enclose the inline cast in parentheses, it works fine:

if (view.class == [UITextView class]) {
    ((UITextView *)view).textColor = [UIColor colorWithRed:0.020 green:0.549 blue:0.961 alpha:1.];
}

I suspect it just has to do with how C handles order of operations, but I would be curious to hear an explanation. Thanks!

  • 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-06-13T17:53:11+00:00Added an answer on June 13, 2026 at 5:53 pm
    if (view.class == [UITextView class]) {
        (UITextView *)view.textColor = [UIColor colorWithRed:0.020 green:0.549 blue:0.961 alpha:1.];
    }
    

    Due to order of precedence, the (UITextView*) will act as a cast on the result of view.textColor, meaning .textColor will be accessed within the UIView* first before it’s cast to a UITextView*

    if (view.class == [UITextView class]) {
        ((UITextView *)view).textColor = [UIColor colorWithRed:0.020 green:0.549 blue:0.961 alpha:1.];
    }
    

    In this, the extra parentheses will inform the compiler that sub-expression needs to be computed first, before the rest of the expression. As such, this is casting view to be a UITextView*. The side effect of that expression is a UITextView* instance, meaning that the .textColor property can be found on the instance it’s being used against.

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

Sidebar

Related Questions

This question is out of pure curiosity. How does Cocoa define the id type?
This question is for pure curiosity. Lets say I have lighttpd installed on my
This is a question that arose mostly of pure curiosity (and killing some time).
This question exist only because of pure curiosity. Not a homework. Find the fastest
does anyone know a pure-php implementation of rrdtool? I googled this question, but only
This is a question of pure curiosity, I don't think the answer could cause
This is not a pure programming question, however it impacts the performance of programs
NOTE: Perhaps this question could be answered by a pure Objective-C expert as well?
This question is about a general technique in SQL, that I can't quite work
Let's pretend this is happening inside of a class method (pure example): public function

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.