0

I'm looking for a compiler setting that will allow me to do this:

[imageGraphEraserIcon imageByResampling:{20, 20} zoom:3]; without throwing a warning. Now I have to do this all the time and the casting seems pointless since the compiler should know the type to expect:

[imageGraphEraserIcon imageByResampling:(CGSize){20, 20} zoom:3];

I know about "CGSizeMake", I'm looking for a shorter way, more pleasant to the eye to do it.

Rad'Val
  • 8,895
  • 9
  • 62
  • 92
Meda
  • 2,776
  • 4
  • 20
  • 31
  • 2
    Are you really getting a warning? What you are trying should produce a compiler *error*, not a warning. – Sven Mar 09 '13 at 22:16

1 Answers1

2

while what you have constructed will work but the correct Objective-C pattern is:

[imageGraphEraserIcon imageByResampling:CGSizeMake(20, 20) zoom:3];

The fact is Apple make the compiler, if you're getting a warning you're "doing it wrong". The compiler expects you to write CGSizeMake for its type checking. Therefore that is the convention. There is no reason to prefer the anonymous struct. It makes your code less standard and harder for others to understand your intent.

jackslash
  • 8,550
  • 45
  • 56
  • 2
    Sorry, not interested in that. I don't know why you consider it to be the "correct Objective-C pattern" either. {20, 20} is anonymous and shorter. – Meda Mar 09 '13 at 21:53
  • 2
    Well its the correct objective-c pattern because the compiler can check the type is correct and also because its what everyone in the objective-c community does. objective-c is all about conventions – jackslash Mar 09 '13 at 21:55
  • 2
    I don't think this is a convention. Also, the compiler can verify the types and number of the struct fields. As for you edit, I obviously don't want to access the fields afterwards (maybe only inside the image method, but that's a different story, since it comes out casted, so no problem there. – Meda Mar 09 '13 at 22:02
  • @Meda You could opt to disable the compiler warning for that file: http://stackoverflow.com/a/6921972/620197 – Mike D Mar 09 '13 at 22:06
  • 1
    @MikeD Disabling all warnings would be foolish. – Rad'Val Mar 09 '13 at 22:14
  • @ValentinRadu I made no judgement on its usefulness, just showing the option is there. – Mike D Mar 09 '13 at 22:15
  • 2
    The second comment in @MikeD's link shows how to disable specific warnings with `-Wno-"name-of-warning"`. – wquist Mar 09 '13 at 22:19
  • @wquist Good catch, I hadn't read all the comments and was trying to an answer in the LLVM docs. – Mike D Mar 09 '13 at 22:20
  • you could also `clang diagnostic push` instead of dicking around in the build settings but this is totally the wrong answer to the OP problem. http://stackoverflow.com/a/7897467/801956 – jackslash Mar 09 '13 at 22:22
  • @MikeD And I only try to combat bad practice and disable all the warnings is not a good advice in that matter. Didn't saw the comment either. – Rad'Val Mar 09 '13 at 22:23
  • @MikeD even tho the comment doesn't help much the OP, since I don't see a flag specific for his problem. – Rad'Val Mar 09 '13 at 22:26
  • 1
    @ValentinRadu I agree, and if I was reviewing that code, I would reject it. Mostly because if `CGSize` is changed, it will not work in the future (unlikely, but I think you get my point). Also, the OP never provided the specific warning. – Mike D Mar 09 '13 at 22:29