Skip to content

Instantly share code, notes, and snippets.

@rraallvv
Created June 22, 2012 12:54
Show Gist options
  • Save rraallvv/2972592 to your computer and use it in GitHub Desktop.
Save rraallvv/2972592 to your computer and use it in GitHub Desktop.
Storing integer into NSValue
int theInt = 123;
// storing value
NSValue* valObj;
valObj = [NSValue value:&myVal withObjCType:@encode(int*)];
// retrieving value
[valObj getValue:&valPtr];
@walkingbrad
Copy link

I came here because I needed to return an NSValue containing an NSUInteger within OCMock (to stub a method that returns an NSUInteger).

OCMock wants me to specify @encode(NSUInteger) not @encode(NSUInteger *) so perhaps that is the "correct" way to do it? I dunno.

NSUInteger count = 3;
NSValue *countValue = [NSValue value:&count withObjCType:@encode(NSUInteger)];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment