为什么不使用指针变量

Mel*_*lon 0 cocoa-touch objective-c ios ios5 ios6

我是iOS应用程序开发的全新手.

我正在学习一个教程,它在BIDAppDelegate.m中有以下代码片段

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.switchViewController = [[BIDSwitchViewController alloc]
                                 initWithNibName:@"SwitchView" bundle:nil];


    UIView *switchView = self.switchViewController.view;

     /**** WHY here do not use pointer variable? ****/
    CGRect switchViewFrame = switchView.frame; 

    switchViewFrame.origin.y+=[UIApplication sharedApplication].statusBarFrame.size.height;
    switchView.frame = switchViewFrame;
    self.window.rootViewController=self.switchViewController;
    ...
    ...
    return YES;
    }
Run Code Online (Sandbox Code Playgroud)

我理解上面的代码做了什么,通常,当应用程序启动时,它会加载根控制器的视图(switchViewController)并进行一些视图调整.

我的问题是,在代码中为什么CGRect switchViewFrame = switchView.frame;不像这样使用指针变量:CGRect *switchViewFrame = switchView.frame;

===============更新==================

现在,我意识到原因是CGRect结构,而不是客观的c类.那么,我可以重新定义代码行:

struct CGRect switchViewFrame, *sViewFrame; 
sViewFrame = switchView.frame; 
Run Code Online (Sandbox Code Playgroud)

以上代码是否相同CGRect switchViewFrame = switchView.frame;

Pat*_*NLT 6

CGRect是C结构,而不是Objective-C对象.CGRect声明CGGeometry.h,它是Core Graphics框架的一部分,它具有C API.

  • 你为什么要做这样的事情?Objective-C是C的严格超集,你必须放心混合C和Objective-C. (2认同)