开发者

With and Without Dot Notation?

开发者 https://www.devze.com 2023-01-03 12:24 出处:网络
I am trying to write the following without using dot notation ... [scrollView setMinimumZoomScale: scrollView.bounds.size.width / image.size.width];

I am trying to write the following without using dot notation ...

[scrollView setMinimumZoomScale: scrollView.bounds.size.width / image.size.width];

Is this right?

[scroll开发者_StackOverflow社区View setMinimumZoomScale: [scrollView bounds].size.width / [image size].width];

cheers Gary.


There actually is something wrong with dot notation. It can get really ugly and hard to read in objective-c. While you'll get differing opinions and flame wars (which I probably just started), I'll be glad to share with you my rule of thumb. Use dot notation for structs. Use brackets for everything else. Read Joe Conway's (of Big Nerd Ranch) blog post on the subject.

Money quote from Joe:

It is my belief, after teaching roughly 300 students Objective-C, that dot-notation is confusing. It hinders the main goal of software development: writing maintainable, effective, efficient, easy to read and bug-free code.

In answer to your question, YES! Looks perfect. You're accessing a struct with your dots.

Stick to your guns on the dot notation. Don't let anyone bully you into using them. ;-)

-Matt

0

精彩评论

暂无评论...
验证码 换一张
取 消