I have this property in my class:
var currentPage: Int
{
set
{
self.currentPage = min(max(0, newValue), self.numberOfPages - 1)
self.setNeedsDisplay()
}
get
{
return self.currentPage
}
}
I know the problem is in the get, but if I have only:
get
{
return currentPage
}
The compiler will give me a warning and advises me to add "self" in the front.
Basically, I want to refactor this code from Objective-C:
@interface MyClass
@property (nonatomic, assign) NSInteger currentPage;
@end
@implementation MyClass
- (void)setCurrentPage:(NSInteger)pageNumber
{
_currentPage = min(max(0, pageNumber), self.numberOfPages - 1);
[self setNeedsDisplay];
}
- (NSInteger)currentPage
{
return _currentPage;
}
@end