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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:09:51+00:00 2026-06-01T00:09:51+00:00

In C# I could do this: class RangeValidator<T> { public T MinValue { get;

  • 0

In C# I could do this:

class RangeValidator<T> {
    public T MinValue { get; set; }
    public T MaxValue { get; set; }
}

Where T could be any primitive type; int, float, double… or any “object”-type; String, DateTime etc.

If in Obj-C, I did it like this:

@interface RangeValidator {
    id minValue;
    id maxValue;
}
@property ...

It would work for let’s say a NSNumber or NSString, but if I assigned a NSInteger to minValue I’d get something like a

warning: initialization makes pointer from integer without a cast
// Since an id is a pointer to an object, not an integer. Correct?

The obvious solution here is maybe to use a NSNumber instead. I was just curious if there are any other solutions to this kind of problem?

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-01T00:09:52+00:00Added an answer on June 1, 2026 at 12:09 am

    The correct way would be to use a NSNumber and initialize from the integer with

    [NSNumber numberWithInt:someInt];
    

    This way the class does not need generics, you could easily perform validation by checking if minValue and maxValue e.g. understands intValue (or some comparison selector maybe, depending on what you want to do).

    if([minValue respondsToSelector:@selector(intValue)]) {
        return [minValue intValue];
    } else {
        ....
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

consider the following class and struct public class Entity { public IdType Id {get;set;}
//this class (or interface if you like) is set up as generic... public abstract
I didn't know methods could have floating blocks like this: class X { public
I could write myself a helper class that does this when given a functor,
I could do this in C#.. int number = 2; string str = Hello
My Parent class is : import java.io.IOException; public class Parent { int x =
I have an HttpModule, something like this: public class MyModule : IHttpModule { public
Suppose a construct like this: class Interface { public: template <typename T> virtual void
For example this class: class A{ public function __call($func, $args){ if($func == 'something') call_user_func_array($this->_some_magic,
I have a lot of classes in the App_Code directory could this be a

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.