Is there a way to call a block with a primitive parameter after a delay, like using performSelector:withObject:afterDelay:
but with an argument like int
/double
/float
?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
- How can I add media attachments to my push notific
Here are my 2 cents = 5 methods ;)
I like encapsulate these details and have AppCode tell me how to finish my sentences.
Here's a handy helper to prevent making the annoying GCD call over and over again:
Now you simply delay your code on the Main thread like this:
If you want to delay your code to different thread:
If you prefer a Framework that also has some more handy features then checkout HandySwift. You can add it to your project via Carthage then use it exactly like in the examples above:
You can either wrap the argument in your own class, or wrap the method call in a method that doesn't need to be passed in the primitive type. Then call that method after your delay, and within that method perform the selector you wish to perform.
For Swift I've created a global function, nothing special, using the
dispatch_after
method. I like this more as it's readable and easy to use:Which you can use as followed:
Swift 3 & Xcode 8.3.2
This code will help you, i add an explanation too
The dispatch_after function dispatches a block object to a dispatch queue after a given period of time. Use below code to perform some UI related taks after 2.0 seconds.
In swift 3.0 :