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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:59:31+00:00 2026-05-26T10:59:31+00:00

I use a category, and some variable stored in a UIView. but only stored

  • 0

I use a category, and some variable stored in a UIView.

but only stored id type, so I really want none id type (int, float, double, char… and so on)

How to write a code?

#import <UIKit/UIKit.h>
#import <objc/runtime.h>

@interface UIView (CountClip)
@property (nonatomic, copy) NSString *stringTag;
@property (nonatomic) float offsetY;
@end

#import "UIView+CountClip.h"

@implementation UIView (CountClip)

static NSString *kStringTagKey = @"StringTagKey";

- (NSString *)stringTag
{
    return (NSString *)objc_getAssociatedObject(self, kStringTagKey);
}
- (void)setStringTag:(NSString *)stringTag
{
    objc_setAssociatedObject(self, kStringTagKey, stringTag, OBJC_ASSOCIATION_COPY_NONATOMIC);
}

- (float)offsetY
{
    // how to write a correct code?
    return objc_getAssociatedObject(self, <#what is a code?#>);
}

- (void)setOffsetY:(float)offsetY
{
    // how to write a correct code?
    objc_setAssociatedObject(self, <#what is a code?#>,...);
}

@end
  • 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-26T10:59:31+00:00Added an answer on May 26, 2026 at 10:59 am

    You need to convert floats to NSNumber instances and vice versa:

    static NSString *kOffsetYTagKey = @"OffsetYTagKey";
    
    - (float)offsetY
    {
        // Retrieve NSNumber object associated with self and convert to float value
        return [objc_getAssociatedObject(self, kOffsetYTagKey) floatValue];
    }
    
    - (void)setOffsetY:(float)offsetY
    {
        // Convert float value to NSNumber object and associate with self
        objc_setAssociatedObject(self, kOffsetYTagKey, [NSNumber numberWithFloat:offsetY],  OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use a category to make a method on the original class
i use such code, but it renders with error <li class=dd0><div id=dt1<a href=http://localhost:1675/Category/29-books.aspx>Books</a></div></li> there
I am especially interested in Google search results. Some web-sites use category IDs in
We're trying to use HTML code in some category names, i.e. to show quarter
I use NSXMLParser but i have some elements that they have the same name.
I am using wordpress and use custom permalink structure: /%category%/%postname%/ My problem is that
I have many sites that use the same root category of the Main Site.
We use this Log4J config to display JTA info: <category name=org.springframework.transaction> <priority value=DEBUG/> </category>
I get the error Ambiguous type variable `p0' in the constraints: (Show p0) arising
I'm really struggling to figure out how to iterate through some data and then

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.