Creating Your First Mac App--Reviewing the Code 审查代码

本文提供了Objective-C应用程序的调试技巧,包括代码审查、处理编译器警告和代码清单对比。详细介绍了AppDelegate和Track类的接口及实现文件,帮助开发者解决应用运行不正确的问题。

Reviewing the Code

If you have trouble getting your app to work correctly, compare your code with the listings shown at the end of this chapter and review your action and outlet connections.

如果你的应用程序运行不正确,重新对照本章结尾处的代码列表,审查你的动作(action)和接口(outlet)连接是否正确。

Code and Compiler Warnings

代码 和编译器警告(Warnings)

Your code should compile without any warnings. If you do receive warnings, it’s recommended that you treat them as likely to be errors. Because Objective-C is a flexible language, sometimes the most you get from the compiler is a warning.

你的代码编译应该不会出现任何警告。如果出现了警告,我们推荐你像对待错误(errors)一样对待它们。因为Objective-C 是一种灵活的语言(flexible language), 有时候你从编译器得到最多的就是一条警告。

Code Listings

This section provides listings for the interface and implementation files of the AppDelegate and Track classes. These listings don’t show comments and other method implementations that are provided by the Xcode template.

本节提供AppDelegate 和 Track 类的 接口(interface)和实现文件(implementation files)代码。 这些代码不包括注释 和 由Xcode模板提供的其它实现方法。

The Interface File: AppDelegate.h

接口文件:AppDelegate.h

#import <Cocoa/Cocoa.h>
 
@class Track;
 
@interface AppDelegate : NSObject <NSApplicationDelegate>
 
@property (assign) IBOutlet NSWindow *window;
@property (weak) IBOutlet NSTextField *textField;
@property (weak) IBOutlet NSSlider *slider;
@property (strong) Track *track;
 
- (IBAction)mute:(id)sender;
- (IBAction)takeFloatValueForVolumeFrom:(id)sender;
- (void)updateUserInterface;
 
@end

The Implementation File: AppDelegate.m

实现文件:AppDelegate.m

#import "AppDelegate.h"
#import "Track.h"
 
@implementation AppDelegate
 
@synthesize textField = _textField;
@synthesize slider = _slider;
 
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    Track *aTrack = [[Track alloc] init];
    [self setTrack:aTrack];
    [self updateUserInterface];
}
 
- (IBAction)mute:(id)sender {
    [self.track setVolume:0.0];
    [self updateUserInterface];
}
 
- (IBAction)takeFloatValueForVolumeFrom:(id)sender {
    float newValue = [sender floatValue];
    [self.track setVolume:newValue];
    [self updateUserInterface];
}
 
- (void)updateUserInterface {
    float volume = [self.track volume];
    [self.textField setFloatValue:volume];
    [self.slider setFloatValue:volume];
}
 
@end

The Interface File: Track.h

#import <Foundation/Foundation.h>
 
@interface Track : NSObject
@property (assign) float volume;
 
@end

The Implementation File: Track.m

#import "Track.h"
 
@implementation Track
 
@end

 

转载于:https://www.cnblogs.com/patientAndPersist/archive/2013/06/03/3114117.html

### Ada-MSHyper Code Repository and Project Implementation For accessing the Ada-MSHyper code repository or project implementation, one can follow a similar approach as described for interacting with Git repositories. Assuming that Ada-MSHyper has its own GitHub repository, here is how operations would be conducted: To begin working on an existing clone of the Ada-MSHyper repository located at `D:\github\Ada-MSHyper`, changing directories into this location will allow further commands to act upon it specifically[^1]: ```bash cd D:\github\Ada-MSHyper ``` Pulling down any updates from the remote master branch ensures having the latest version of the source files locally available: ```bash git pull origin master ``` Listing all folders within the current directory helps verify what components are present after pulling changes: ```bash ls ``` If there exists a need to remove certain cached items like a folder named `target` without affecting their presence in the local file system but ensuring they won't be tracked by Git anymore, executing the following command accomplishes this task while preserving other modifications made outside of said folder: ```bash git rm -r --cached target ``` Committing these removals along with appropriate messages documents why such actions were taken, aiding future reference when reviewing history logs: ```bash git commit -m 'Removed target folder from tracking' ``` Finally, pushing committed alterations back up to the mainline (`master`) branch synchronizes personal contributions with those accessible publicly through platforms like GitHub: ```bash git push -u origin master ``` Regarding SSH permissions verification, which might pertain to authenticating access rights before performing git pulls/pushes over secure channels, checking configuration involves inspecting `.ssh/config` settings alongside public/private key pairs stored under typical user home directories.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值