通常我发现几乎所有我最重要的iPhone开发测试用例都围绕UI测试而不是业务逻辑或数据测试.我对XCode环境中的自动UI测试不是很熟悉.有人能指点我一本好的教程或书吗?
更新
这个问题是几年前写的,UI测试从那时起已经走了很长一段路.使用UI自动化仍然是一种选择,但KIF框架现在是一个更好的功能测试解决方案,IMO.
来自KIF的github页面:
KIF代表Keep It Functional,是一个iOS集成测试框架.通过利用操作系统为视障人士提供的辅助功能属性,它可以轻松实现iOS应用程序的自动化.
KIF使用标准XCTest测试目标构建并执行测试.测试在主线程中同步进行(运行运行循环以强制通过时间),允许更复杂的逻辑和组合.这也允许KIF利用Xcode 5 Test Navigator,命令行构建工具和Bot测试报告.
是否可以在UIView中获取当前活动的UITextField或UITextView,这样我可以隐藏键盘[text resignFirstResponder];?
有没有办法检测用户何时更改键盘类型,特别是在这种情况下更改为表情符号键盘?
我想围绕UINavigationBar的右上角和左上角.
我知道有更改视角半径的功能,但是可以做一些类似于标准UINavigationBar的操作吗?
如果您不知道我在说什么,请查看以下内容:

谢谢!
iphone cocoa-touch objective-c rounded-corners uinavigationbar
我想在两个日期之间生成一个随机日期 - 例如从今天到现在60天之间的随机日期.我怎么做?
UPDATE
使用答案中的信息,我想出了这个方法,我经常使用它:
// Generate a random date sometime between now and n days before day.
// Also, generate a random time to go with the day while we are at it.
- (NSDate *) generateRandomDateWithinDaysBeforeToday:(NSInteger)days
{
int r1 = arc4random_uniform(days);
int r2 = arc4random_uniform(23);
int r3 = arc4random_uniform(59);
NSDate *today = [NSDate new];
NSCalendar *gregorian =
[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *offsetComponents = [NSDateComponents new];
[offsetComponents setDay:(r1*-1)];
[offsetComponents setHour:r2];
[offsetComponents setMinute:r3];
NSDate *rndDate1 = [gregorian dateByAddingComponents:offsetComponents
toDate:today options:0]; …Run Code Online (Sandbox Code Playgroud) 我正在将下面的Objective C类重写为Swift:
@implementation UIImage (Extra)
+ (UIImage *)validImageNamed:(NSString *)name
{
UIImage *image = [self imageNamed:name];
NSAssert(image, @"Unable to find image named '%@'", name);
return image;
}
Run Code Online (Sandbox Code Playgroud)
这要求作为一个方便的init实现,但是如何检查指定的初始化程序self.init(命名:)是否成功?
extension UIImage {
convenience init(validateAndLoad name: String!) {
self.init(named: name)
// need to assert here if self.init fails
}
Run Code Online (Sandbox Code Playgroud)
当self.init(named :)调用失败时,扩展的init停止执行.
我已经尝试创建一个UIImage实例并将其分配给自己,但这不会编译.
当然,可以像ObjC版本一样使用辅助方法:
extension UIImage {
class func validImage(named name: String) -> UIImage {
var image = UIImage(named: name)
assert(image == nil, "Image doesn't exist")
return image
}
Run Code Online (Sandbox Code Playgroud)
但有没有办法使用初始化程序实现这一点?
是否有可能使用Apple的WatchKit开发第三方应用程序,其中包含用于心跳/速率数据访问/原始数据访问的API?
WatchKit SDK现在是否可供开发人员公开使用?
任何人都可以指出我在正确的方向上如何在录制使用iPhone SDK Core Audio讲话的人时最大限度地减少环境噪音?我猜测一个带通滤波器可以消除人类声音范围之上和之下的任何频率.我不知道如何在SDK中实现音频带过滤器.最佳解决方案是在将流写入内存/磁盘之前消除流中的噪声.
我总是看到UITableViewController申报的样板
static NSString *CellIdentifier
Run Code Online (Sandbox Code Playgroud)
在
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
Run Code Online (Sandbox Code Playgroud)
静电为什么?我在很多地方改变了这个,因为我CellIdentifier根据这个部分进行了更改?这是静态背后的原因吗?我会影响表现吗?
我有一个实体只在一个部分中显示在表视图中.该实体有两个属性,workoutName和trainingLevel.两者都是字符串类型.训练水平由3种类型组成:1,2,3(trainingLevel =(整数16或字符串类型?哪个是理想的?)我想将表分成三个部分,每个部分包含相应训练级别的条目.
我该怎么做呢?我目前使用的代码如下:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return self.workoutType.workouts.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell =
[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
WorkoutSet *workoutSet = [self.fetchedResultsController objectAtIndexPath:indexPath];
cell.textLabel.text = workoutSet.workoutName;
cell.detailTextLabel.text = [NSString …Run Code Online (Sandbox Code Playgroud) ios ×7
cocoa-touch ×6
iphone ×4
objective-c ×3
apple-watch ×1
cocoa ×1
core-audio ×1
core-data ×1
emoji ×1
swift ×1
tableview ×1
uikeyboard ×1
uitableview ×1
uiview ×1
watchkit ×1
xcode ×1