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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:31:05+00:00 2026-05-13T13:31:05+00:00

My previous question asked for a way to keep a text view and slider

  • 0

My previous question asked for a way to keep a text view and slider in sync with bindings when modifying a CGRect’s “x” value.

Following Peter Hosey’s advice on using the controller’s setter to propogate those changes to the CALayer, I came up with the following:

@interface WindowController : NSObject {
  CALayer *layer;
  float frameOriginX;
}
@end

@implementation WindowController
...
-(void)setFrameOriginX:(id)value {
  [layer setValue:[NSNumber numberWithFloat:[value floatValue]] 
       forKeyPath:@"frame.origin.x"];
  frameOriginX = [value floatValue];

}

-(float)frameOriginX {
 return [[layer valueForKeyPath:@"frame.origin.x"]floatValue];
}
@end

I used bindings to connect the text view and slider to “self.frameOriginX” and it’s all working–both controls update each other. However, I was wondering what a cleaner way to do this is.

Thank You,

Charles

  • 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-13T13:31:05+00:00Added an answer on May 13, 2026 at 1:31 pm

    First off, why does setFrameOriginX: take an id and frameOriginX return a float? KVC will not like this. Plus, you should use CGFloat, not float.

    Once you fix that, you’re in luck. Today, Colin Barrett released SSGeometryKVC. With that, your setter becomes:

    -(void)setFrameOriginX:(CGFloat)newX {
        frameOriginX = newX;
        [[layer mutableRectValueForKey:@"frame"].x = frameOriginX;
    }
    

    Note that neither this implementation nor your original implementation is thread-safe. This won’t be a problem as long as it’s only the controls that are calling it.

    I used bindings to connect the text view and slider to “self.frameOriginX”…

    Huh? If you bound them to the controller, you don’t need self. here.

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

Sidebar

Related Questions

From the previous question I asked, RemoveAll is the cleanest way to remove from
In a previous question, I asked how to send text to Notepad . It
So in a previous question I asked about whats the most RESTful way to
In a previous question I asked, the suggested answer was for me to partition
So in a previous question I asked about implementing a generic interface with a
In a previous question I asked about how to group XML elements logically, and
This stems from a previous question I asked - about a write conflict with
This is a follow up question to a previous question I asked about calculating
This is a related to a previous question I have asked here, see the
In a previous question, I asked what it meant when my program returned an

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.