当我设置navigationController.hidesBarOnSwipe = YES并尝试在显示的webView中滑动时,导航栏被隐藏,但当我尝试滑动以将其取回时,它将永远不会再出现.
我的ViewController正在监听滑动事件:
[self.navigationController.barHideOnSwipeGestureRecognizer addTarget:self action:@selector(swipe:)]?
Run Code Online (Sandbox Code Playgroud)
但是,由于滑动隐藏了导航栏,因此实际上从未再次调用此选择器.谁实施了hidesBarOnSwipe?它是一个已知的错误还是它的设计,它隐藏后不会显示导航栏.
之前:

后:

我有这个枚举:
typedef types {
HBIntineraryTypeVisited = 0,
HBIntineraryTypeUnvisited,
HBIntineraryTypeUnknown,
HBIntineraryTypeDeleted,
} HBIntineraryType;
Run Code Online (Sandbox Code Playgroud)
并希望使用nscoding协议将其与其他一些变量一起存储
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self) {
_name = [aDecoder decodeObjectForKey:@"name"];
// todo decode enum object
}
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeObject:_name forKey:@"name"];
// todo encode enum object
}
Run Code Online (Sandbox Code Playgroud)
我使用什么编码器方法来解码和编码这种枚举?
protocol Car {
static func foo()
}
struct Truck : Car {
}
extension Car {
static func foo() {
print("bar")
}
}
Car.foo() // Does not work
// Error: Car does not have a member named foo
Truck.foo() // Works
Run Code Online (Sandbox Code Playgroud)
Xcode Car.foo()正确地自动填充,所以我要问的是它是否是一个不能编译的错误(说它没有一个名为foo()的成员).如果在协议扩展中定义静态方法,可以直接在协议上调用静态方法吗?
protocol LazyUpdateable {
func waitToDoStuff()
func myMethodName()
}
extension LazyUpdateable where Self: NSObject {
func waitToDoStuff() {
self.performSelector(#selector(myMethodName), withObject: nil, afterDelay: 1.5)
}
func myMethodName() {
}
}
Run Code Online (Sandbox Code Playgroud)
有了这个更新,我得到了错误Argument of #selector refers to a method that is not exposed to objective c,但是如果我继续使用旧版本,Selector("myMethodName")我会收到警告,要求更改为更好的方法.#selector()在这种情况下是否可以使用?它不适用于设置@objc我的协议,我已经尝试过了.
这是一个你可以尝试的游乐场,它表明它不适用于设置 @objc
import Foundation
import UIKit
import XCPlayground
@objc protocol LazyUpdatable {
optional func waitToDoStuff()
optional func myMethodName()
}
extension LazyUpdatable where Self: UIViewController {
func waitToDoStuff() {
self.performSelector(#selector(myMethodName), withObject: …Run Code Online (Sandbox Code Playgroud) 我有一个方法的子集,需要获得当月的第一天.
NSDate *today = [NSDate date]; // returns correctly 28 february 2013
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *components = [[NSDateComponents alloc] init];
components.day = 1;
NSDate *dayOneInCurrentMonth = [gregorian dateByAddingComponents:components toDate:today options:0];
Run Code Online (Sandbox Code Playgroud)
dayOneInCurrentMonth然后打印出来2013-03-01 09:53:49 +0000,下个月的第一天.
我如何获得当月的第一天?
我在github上托管了一些开源代码,用于向UITextField添加基于块的类别.我添加了一个.travis.yml文件来让travis CI在每次推送时构建和运行代码.链接到Travis CI警告.它成功地构建了该项目.运行.travis.yml脚本时收到的警告是:
WARNING: Using Objective-C testing without specifying a scheme and either
a workspace or a project is deprecated.
Run Code Online (Sandbox Code Playgroud)
我想运行的示例项目位于文件夹/ UITextView Blocks示例/如何添加到.travis.yml文件以运行此项目?我的travis.yml文件现在由
language: objective-c
Run Code Online (Sandbox Code Playgroud) 我有一个包含AFHTTPSessionManager*fileTransferSessionManager的单例类.在其中我有时想要取消所有下载,在重新开始之前,这是通过downloadTasks运行并取消它们.问题是,当调用downloadtasks属性时,如果有正在运行的下载,则主线程会冻结.
// My method canceling download tasks:
NSArray *downloadTasks = self.fileTransferSessionManager.downloadTasks;
for (NSURLSessionDownloadTask *downloadTask in downloadTasks) {
[downloadTask cancel];
}
// In AFURLSessionManager.m
- (NSArray *)downloadTasks {
return [self tasksForKeyPath:NSStringFromSelector(_cmd)];
}
Run Code Online (Sandbox Code Playgroud)
调用冻结主线程的方法,因为从不调用带有dispatch_semaphore_signal(信号量)的getTasksWithCompletionHandler:
// In AFURLSessionManager.m
- (NSArray *)tasksForKeyPath:(NSString *)keyPath {
__block NSArray *tasks = nil;
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
[self.session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
if ([keyPath isEqualToString:NSStringFromSelector(@selector(dataTasks))]) {
tasks = dataTasks;
} else if ([keyPath isEqualToString:NSStringFromSelector(@selector(uploadTasks))]) {
tasks = uploadTasks;
} else if ([keyPath isEqualToString:NSStringFromSelector(@selector(downloadTasks))]) {
tasks …Run Code Online (Sandbox Code Playgroud) stringWithFormat应该返回一个字符串,为什么这个语句不能编译
NSAssert(YES, [NSString stringWithFormat:@"%@",@"test if compiles"]);
Run Code Online (Sandbox Code Playgroud)
什么时候
NSAssert(YES, @"test if compiles");
Run Code Online (Sandbox Code Playgroud)
编译?
class OAuthToken: NSObject, NSCoding {
var refreshToken: String?
var accessToken: String?
var scope: String?
convenience init?(refreshToken: String?, accessToken: String?, scope:String) {
self.init()
if let acutalRefreshToken = refreshToken as String? {
self.refreshToken = acutalRefreshToken
} else {
return nil
}
if let actualAccessToken = accessToken as String? {
self.accessToken = actualAccessToken
}else {
return nil
}
self.scope = scope
}
convenience init?(attributes: Dictionary<String,AnyObject>, scope: String) {
var aRefreshToken: String!
var anAccessToken: String?
aRefreshToken = attributes["refresh_token"] as String?
anAccessToken = attributes["access_token"] as …Run Code Online (Sandbox Code Playgroud) let expecation = expectationWithDescription("do tasks")
for i in 0...40 {
let afterTiming = 0.3 * Double(i)
let startTime = CFAbsoluteTimeGetCurrent()
let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(afterTiming * Double(NSEC_PER_SEC)))
dispatch_after(delayTime, dispatch_get_main_queue()) {
let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime
print("\(afterTiming) - \(timeElapsed) : \(i)")
}
}
waitForExpectationWithTimeout(14)
Run Code Online (Sandbox Code Playgroud)
在30执行它几乎一秒钟之后,控制台开始表现奇怪,同时显示两条和两条打印线
9.0 - 9.88806998729706 : 30
9.3 - 9.88832598924637 : 31
Run Code Online (Sandbox Code Playgroud)
有没有办法XCTest让我们更接近"在正确的时间"实际执行请求?就像在9.88秒后没有完成9秒后应该完成的请求一样.
ios ×4
swift ×3
objective-c ×2
protocols ×2
swift2 ×2
calendar ×1
cocoa ×1
cocoa-touch ×1
enums ×1
github ×1
nsassert ×1
nscalendar ×1
nscoding ×1
nsurlsession ×1
semaphore ×1
travis-ci ×1
xcode ×1