Converting between types in Objective-C

Being a start-up developer of Objective-C and not having the patience to actually do some research, rather than just diving into things, I came across the following:

I have a CGFloat and I want to share it with something and use the result as an NSInteger.

Example:

CGPoint p = scrollView.contentOffset; //where p is a CGFloat by nature
NSInteger * myIndex = p.x/468.0;

During compilation, I get an error: "Incompatible types during initialization." I assume that due to a mismatch between CGFloat and NSInteger.

What should I know to get rid of this? Excuse for troubling.

+3
source share
2 answers

. NSInteger (NSInteger * myIndex). , float int. :

NSInteger myIndex = (int)(p.x / 468.0);
+7

NSInteger . typedef . *, . , , .

+4

Source: https://habr.com/ru/post/1709945/


All Articles