objective c - Non Bool in if statement / Obj-C closures in Swift -


i've been trying convert tutorial https://github.com/fastred/customscrollview objective-c swift i'm stuck in few places.

in objective-c has properties:

@property (nonatomic, weak) uidynamicitembehavior *decelerationbehavior; @property (nonatomic, weak) uiattachmentbehavior *springbehavior; 

and has if statement:

if self.decelerationbehavior && !self.springbehavior { ... } 

since these no bool's, mean in swift?


void(^solvefory)(cgpoint*) = ^(cgpoint *anchor) {     if (deltay != 0) {         anchor->y = * anchor->x + b;     } }; 

this 1 seems closure , i've tried converting swift using:

func solvefory(_ anchor: inout cgpoint) { if deltay != 0 { anchor.y = * anchor.x + b } } 

__weak typeof(self)weakself = self;  decelerationbehavior.action = ^{     cgrect bounds = weakself.bounds;     bounds.origin = weakself.dynamicitem.center;     weakself.bounds = bounds; }; 

but converted app doesn't behave original @ all. can tell me how convert swift?

if i'm interpreting correctly, here's how in swift:

var decelerationbehavior: uidynamicitembehavior? var springbehavior: uiattachmentbehavior?  // if statement in objective-c checking nil. in objective-c nil == 0 == false if let decelerationbehavior = decelerationbehavior, let springbehavior = springbehavior { ... }  let solvefory: (cgpoint) -> () = { (anchor) in     if deltay != 0 {         anchor.y = * anchor.x + b;     } }  decelerationbehavior.action = { [weak self] in     if let weakself = self {         cgrect bounds = weakself.bounds         bounds.origin = weakself.dynamicitem.center         weakself.bounds = bounds     } } 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -