Questions tagged [nsvalue]

An NSValue object is a simple container for a single C or Objective-C data item. It can hold any of the scalar types such as int, float, and char, as well as pointers, structures, and object ids. The purpose of this class is to allow items of such data types to be added to collections such as instances of NSArray and NSSet, which require their elements to be objects. NSValue objects are always immutable.

64 questions
41
votes
3 answers

How to wrap a Struct into NSObject

this is supposed to be trivial… I think, but I can't find a way how to wrap a Struct variable into an NSObject. Is there a method to do so? If not, how would I go about adding a struct into an NSMutableArray? Thanks.
GeneCode
  • 7,545
  • 8
  • 50
  • 85
20
votes
5 answers

How to convert CGPoint in NSValue in swift?

As my question title says how can I convert CGPoint into NSValues so I can store then Into array In swift. In objective-C we can do it like this: // CGPoint converted to NSValue CGPoint point = CGPointMake(9, 9); NSValue *pointObj =…
Dharmesh Kheni
  • 71,228
  • 33
  • 160
  • 165
19
votes
7 answers

Converting a CGPoint to NSValue

In CABasicAnimation.fromValue I want to convert a CGPoint to a "class" so I used NSValue valueWithPoint but in device mode or simulator one is not working... need to use NSMakePoint or CGPointMake if in device or simulator.
CiNN
  • 9,752
  • 6
  • 44
  • 57
11
votes
2 answers

Converting an NSValue back to the struct type that was stored in it?

I'm storing Chipmunk Physics' cpShape objects in an NSMutableDictionary by way of NSValue objects and the following lines of code: NSValue *shapeValue = [[NSValue alloc] initWithBytes: shape objCType: @encode(cpShape)]; [staticBodiesInUse setObject:…
Luke
  • 9,512
  • 15
  • 82
  • 146
9
votes
5 answers

How do I animate opacity using swift?

Could someone please provide me with an example of animating the opacity of an Image View in swift?? I couldn't even find a good example in objective c func showCorrectImage(element: AnyObject){ var animation : CABasicAnimation =…
PugLvr28
  • 111
  • 1
  • 1
  • 6
8
votes
3 answers

Saving Swift CLLocation in CoreData

I am trying to save CLLocation data in Core Data. My property is set as a Transformable object. Some sample code out there indicates one can save the location data using this objc converted to an NSValue. CLLocationCoordinate2D myLocation; NSValue…
Tommie C.
  • 12,895
  • 5
  • 82
  • 100
8
votes
3 answers

Why can't I encode an NSValue in an NSKeyedArchiver?

I was trying to encode an MKMapView center and span into an NSKeyedArchiver for state preservation. I found a couple of handy new MapKit NSValue additions, valueWithMKCoordinate: and valueWithMKCoordinate:. Trying to encode these into the keyed…
nevan king
  • 112,709
  • 45
  • 203
  • 241
7
votes
1 answer

How do I convert a CMTime to an NSValue in Swift?

I was trying to make use of AVPlayer's addBoundaryTimeObserverForTimes method from swift and ran into a problem converting CMTimes to NSValues, which is what addBoundaryTimeObserverForTimes take as input. In the end I resorted to wrapping [NSString…
Mike Akers
  • 12,039
  • 14
  • 58
  • 71
7
votes
1 answer

How to get a value from NSValue in Swift?

Here's what I've tried so far func onKeyboardRaise(notification: NSNotification) { var notificationData = notification.userInfo var duration = notificationData[UIKeyboardAnimationDurationUserInfoKey] as NSNumber var frame =…
Tamby Kojak
  • 2,129
  • 1
  • 14
  • 25
6
votes
1 answer

How to animate zoomScale on a UIScrollView

I need to set zoomScale back to 1 on a UIScrollView, but I need it to be animated. I thought I could use CABasicAnimation for this, but NSValue doesn't seem to have a "valueForFloat" or "valueForNSNumber", so I'm not sure what to use for…
soleil
  • 12,133
  • 33
  • 112
  • 183
4
votes
2 answers

Convert/Wrap Swift struct as NSValue for CAAnimation purposes?

I have a custom CALayer subclass that draws a circular arc. It looks something like: class ArcLayer: CALayer { var strokeColor:UIColor = UIColor.blackColor() { didSet { self.setNeedsDisplay() }} var strokeWidth:CGFloat = 1.0 { didSet {…
Travis Griggs
  • 21,522
  • 19
  • 91
  • 167
3
votes
1 answer

Auto-boxing NSArray?

So, I use NSArrays a lot, so I decided to attempt to create a macro that will create an array from primitives passed in, based on the macros here: https://bitbucket.org/snej/myutilities/src/319441e240fa/CollectionUtils.h #define $array(values...)…
Richard J. Ross III
  • 55,009
  • 24
  • 135
  • 201
3
votes
2 answers

ObjC: differentiating between NSValue and NSNumber

I have some code where I will be receiving an object of unknown type. It could be a NSString, NSNumber, a scalar wrapped in a NSValue or some other class: -(void) doSomethingWith:(id) value { if ( ) { // Do something…
drekka
  • 20,957
  • 14
  • 79
  • 135
3
votes
3 answers

Performance - structs in NSValue vs container object

In a situation where I need to save all data members in a NSDictionary, does it make more sense to put structs (custom types, or even scalars i.e. CGPoint) in my own wrapper (not NSValue), so I can avoid the overhead of encoding/decoding it every…
Morrowless
  • 6,856
  • 11
  • 51
  • 81
3
votes
1 answer

how to get back a CGRect from an NSValue which is stored in a string

CGRect rect = Temp_3_Artwork_Big_Image.frame; NSLog(@"Rect : %.2f,%.2f,%.2f,%.2f",rect.origin.x,rect.origin.y,rect.size.width,rect.size.height); NSValue *value = [NSValue valueWithCGRect:rect]; NSLog(@"Value : %@",value); CGRect rect1 = [value…
Chirag Dj
  • 630
  • 2
  • 9
  • 27
1
2 3 4 5