Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
lovekesh bhagat
1,572 PointsiOS code reusability
Hello everyone,
I am beginner to the iOS and want to ask a simple thing.
i have to check the height of the device , on which app is running for which i can use this code:-
"[[UIScreen mainScreen]bounds].size.height"
what i want to know that is there any way with which i can replace this long line of code with a single variable like :-
"CheckDeviceHeight"
i dont want to write the line again and again as it consumes a lot of time.Please suggest me a way to do it so that i can minimize my code.
thanks and regards Lovekesh bhagat iOS application developer
2 Answers
Gabe Nadel
Treehouse Guest TeacherYou could create a variable and assign it that value when the device launches and then pass that variable around in your code. I'm not sure if it will actually be fewer keystrokes, but that is an option.
lovekesh bhagat
1,572 PointsThanks Gabe Nadel , this solution which actually work in this case.