nsvalue

Converting a CGPoint to NSValue

早过忘川 提交于 2019-11-29 05:34:34
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. ashcatch There is a UIKit addition to NSValue that defines a function + (NSValue *)valueWithCGPoint:(CGPoint)point See iPhone doc DanSkeel @ashcatch 's answer is very helpful, but consider that those methods from addition copy values, when native NSValue methods store pointers! Here is my code checking it: CGPoint point = CGPointMake(2, 4); NSValue *val = [NSValue

How to convert CGPoint in NSValue in swift?

混江龙づ霸主 提交于 2019-11-28 11:55:04
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 = [NSValue valueWithCGPoint:point]; But can anybody tell me that how can I do this in swift? Thanks In Advance. Try something like that: let point = CGPointMake(9, 9) var pointObj = NSValue(CGPoint: point) Exactly as you'd imagine: let point = CGPoint(x: 9.0, y: 9.0) let pointObj = NSValue(CGPoint: point) let newPoint = pointObj.CGPointValue() Abizern If you aren't

How to convert CGPoint in NSValue in swift?

霸气de小男生 提交于 2019-11-27 19:22:58
问题 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 = [NSValue valueWithCGPoint:point]; But can anybody tell me that how can I do this in swift? Thanks In Advance. 回答1: Try something like that: let point = CGPointMake(9, 9) var pointObj = NSValue(CGPoint: point) 回答2: Exactly as you'd imagine: let point = CGPoint(x:

How to wrap a Struct into NSObject

风格不统一 提交于 2019-11-27 06:27:37
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. Rpranata Hm, try to look at the NSValue at https://developer.apple.com/documentation/foundation/nsvalue You can use it like struct aStruct { int a; int b; }; typedef struct aStruct aStruct; Then sort of "wrap" it to an NSValue object like: aStruct struct; struct.a = 0; struct.b = 0; NSValue *anObj = [NSValue value:&struct withObjCType:@encode(aStruct)]; NSArray *array = @[anObj]

How to wrap a Struct into NSObject

戏子无情 提交于 2019-11-26 12:00:44
问题 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. 回答1: Hm, try to look at the NSValue at https://developer.apple.com/documentation/foundation/nsvalue You can use it like struct aStruct { int a; int b; }; typedef struct aStruct aStruct; Then sort of "wrap" it to an NSValue object like: aStruct struct; struct.a = 0; struct.b =