- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
CGFloat ageInYears = self.user.age;
if (ageInYears < 1) {
CGFloat ageInSeconds = [[NSDate date] timeIntervalSinceDate:self.user.birthday];
ageInYears = floorf(ageInSeconds / (365.25 * 24.0 * 60.0 * 60.0));
}
// ...
profileInfoCell.schoolLabel.text = [NSString stringWithFormat:@"%.0f", ageInYears];
Аптимизацыя?
typedef float CGFloat; // 32-bit
typedef double CGFloat; // 64-bit
>These types were introduced to make it easier to write code that works on both 32-bit and 64-bit without modification.
>Floating point quantities in the Core Graphics framework (Quartz), which are float on 32-bit architectures, are being expanded to double to provide a wider range and accuracy for graphical quantities. Core Graphics declares a new type for floating-point quantities, CGFloat, and declares it conditionally for both 32-bit and 64-bit. This change affects Cocoa because of its close dependency on Core Graphics. Where a parameter or return value in the Cocoa frameworks is a graphical quantity, CGFloat now replaces float
Например, это известная жизненная мудрость, что для того, чтобы отрендерить красиво анимацию изменения ширины прямоугольника, лучше самому рассчитать изменения ширины и отрисовать его вместо того, чтобы использовать примитивы прямоугольника и изменять им ширину. Во втором случае изменения будут скачками разной высоты.
Школоло что ли?