nsvalue

Does NSValue free its value when freed?

╄→尐↘猪︶ㄣ 提交于 2021-01-28 06:33:15
问题 Have a look at this pseudocode: void* magicpointer = malloc(OVER_NINE_THOUSAND); NSValue* v = [NSValue valueWithPointer:magicpointer]; [v release]; When v is released, does magicpointer get freed as well, or do I have to do that manually? I am using manual reference counting. 回答1: It doesn't get freed - NSValue is just a wrapper so you can treat arbitrary values as objects. It doesn't do anything with the wrapped pointer. 回答2: No, NSValue won't. Sounds like you might want to use NSData , it

How to get a value from NSValue in Swift?

谁说胖子不能爱 提交于 2020-01-03 11:03:06
问题 Here's what I've tried so far func onKeyboardRaise(notification: NSNotification) { var notificationData = notification.userInfo var duration = notificationData[UIKeyboardAnimationDurationUserInfoKey] as NSNumber var frame = notificationData[UIKeyboardFrameBeginUserInfoKey]! as NSValue var frameValue :UnsafePointer<(CGRect)> = nil; frame.getValue(frameValue) } But I always seem to crash at frame.getValue(frameValue) . It's a little bit confusing because the documentation for

How to get a value from NSValue in Swift?

不问归期 提交于 2020-01-03 11:02:02
问题 Here's what I've tried so far func onKeyboardRaise(notification: NSNotification) { var notificationData = notification.userInfo var duration = notificationData[UIKeyboardAnimationDurationUserInfoKey] as NSNumber var frame = notificationData[UIKeyboardFrameBeginUserInfoKey]! as NSValue var frameValue :UnsafePointer<(CGRect)> = nil; frame.getValue(frameValue) } But I always seem to crash at frame.getValue(frameValue) . It's a little bit confusing because the documentation for

How do I animate opacity using swift?

北城余情 提交于 2019-12-19 18:28:46
问题 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 = CABasicAnimation(keyPath: "opacity"); animation.delegate = self animation.fromValue = NSValue(nonretainedObject: 0.0) animation.toValue = NSValue(nonretainedObject: 1.0) animation.duration = 1.0 element.layer?.addAnimation(animation, forKey: nil) } I think I have

Converting a CGPoint to NSValue

本小妞迷上赌 提交于 2019-12-18 04:34:43
问题 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. 回答1: There is a UIKit addition to NSValue that defines a function + (NSValue *)valueWithCGPoint:(CGPoint)point See iPhone doc 回答2: @ashcatch 's answer is very helpful, but consider that those methods from addition copy values, when native NSValue methods store pointers!

Swift compile error, subclassing NSValue, using super.init(nonretainedObject:)

与世无争的帅哥 提交于 2019-12-12 18:20:18
问题 This code class ID<T: AnyObject> : NSValue { init(baseObject: T) { super.init(nonretainedObject: baseObject) } } gives this compiler error: error: must call a designated initializer of the superclass 'NSValue' super.init(nonretainedObject: baseObject) ^ How do I get rid of this? Things I thought of I thought the error might be because the NSValue initializer has an AnyObject? type ( Note well: postfix ? ). I tried various flavors of casting and [?!] postfixing in places, and it fixed nothing.

Convert/Wrap Swift struct as NSValue for CAAnimation purposes?

人盡茶涼 提交于 2019-12-10 15:12:47
问题 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 { self.setNeedsDisplay() }} var strokeCap:CGLineCap = .Butt { didSet { self.setNeedsDisplay() }} var startRadians:CGFloat = 0.0 { didSet { self.setNeedsDisplay() }} var sweepRadians:CGFloat = Tau { didSet { self.setNeedsDisplay() }} // other init's omitted for

How do I animate opacity using swift?

不羁的心 提交于 2019-12-01 18:01:07
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 = CABasicAnimation(keyPath: "opacity"); animation.delegate = self animation.fromValue = NSValue(nonretainedObject: 0.0) animation.toValue = NSValue(nonretainedObject: 1.0) animation.duration = 1.0 element.layer?.addAnimation(animation, forKey: nil) } I think I have most of this right (not completely sure though), could someone please help me? element = an Image View

Saving Swift CLLocation in CoreData

那年仲夏 提交于 2019-11-30 13:06:05
问题 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 *locationValue = [NSValue valueWithBytes:&myLocation objCType:@encode(CLLocationCoordinate2D)] // then put locationValue into storage - maybe an ObjC collection class or core data etc. Retrieving the object from the data store is supposed to work

Saving Swift CLLocation in CoreData

只愿长相守 提交于 2019-11-30 05:24:59
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 *locationValue = [NSValue valueWithBytes:&myLocation objCType:@encode(CLLocationCoordinate2D)] // then put locationValue into storage - maybe an ObjC collection class or core data etc. Retrieving the object from the data store is supposed to work using this paradigm. CLLocationCoordinate2D myLocation; NSValue *locationValue = // restored from your