1

I used a framework Objective-C in my Project (Swift). But in the code have a Block, i cannot convert to swift (i'm newbie in swift) So the code is

[self.datePicker setDateHasItemsCallback:^BOOL(NSDate *date) {
    int tmp = (arc4random() % 30)+1;
    return (tmp % 5 == 0);
}];

Please help me. Thank you ,

1 Answer 1

1

Where you would use a block in Objective-C, you use a function in Swift. In Objective-C, the argument is a block that takes an NSDate and returns a BOOL:

[self.datePicker setDateHasItemsCallback:^BOOL(NSDate *date) {

So, in Swift the argument is a function that takes an NSDate and returns a Bool:

self.datePicker.setDateHasItemsCallback {
    (date:NSDate) -> Bool in
    return true // fix this up as desired
}
Sign up to request clarification or add additional context in comments.

1 Comment

And see my new Swift tutorial if you don't know about anonymous function syntax: apeth.com/swiftBook/ch02.html#_anonymous_functions

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.