我如何获得下面的行编译?
UIView.setAnimationCurve(userInfo[UIKeyboardAnimationCurveUserInfoKey].integerValue)
Run Code Online (Sandbox Code Playgroud)
现在,它给出了编译错误:
'NSNumber' is not a subtype of 'UIViewAnimationCurve'
Run Code Online (Sandbox Code Playgroud)
为什么编译器认为userInfo[UIKeyboardAnimationCurveUserInfoKey].integerValue是NSNumber什么时候integerValue被声明为Int?
class NSNumber : NSValue {
// ...
var integerValue: Int { get }`?
// ...
}
Run Code Online (Sandbox Code Playgroud)
我与其他枚举类型有类似的问题.什么是一般解决方案?
为什么人们有这个问题?
$ git clone --recursive git@github.com:acani/Chats.git克隆到'聊天'...权限被拒绝(公钥).致命:无法从远程存储库读取.
请确保您具有正确的访问权限并且存储库存在.
https://github.com/acani/Chats/issues/53#issuecomment-118014684
我已经阅读了一些答案,说要将子模块URL从SSH更改为HTTP,但为什么我必须这样做.我不想那样做.我想保留SSH,这样如果我想推送,我就不必在终端输入我的用户名和密码.每个人都可以很好地克隆SSH URL,那么他们为什么不能将它作为子模块递归克隆呢?
当我定义一个UIAlertController便利初始化器时:
extension UIAlertController {
convenience init(message: String?) {
self.init(title: nil, message: message, preferredStyle: .Alert)
self.addAction(UIAlertAction(title: "OK", style: .Cancel, handler: nil))
}
}
Run Code Online (Sandbox Code Playgroud)
并在我的子类中的按钮操作中使用它UIViewController:
func buttonAction(button: UIButton) {
let alert = UIAlertController(dictionary: nil, error: nil, handler: nil)
presentViewController(alert, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
然后单击模拟器上的那个按钮,我收到一个警告:
尝试在取消分配时加载视图控制器的视图是不允许的,并且可能导致未定义的行为(UIAlertController)
但是,如果不使用便利初始化程序,我不会收到警告,我使用全局函数:
func UIAlertControllerWithDictionary(message: String?) -> UIAlertController {
let alert = UIAlertController(title: nil, message: message, preferredStyle: .Alert)
alert.addAction(UIAlertAction(title: "OK", style: .Cancel, handler: nil))
return alert
}
Run Code Online (Sandbox Code Playgroud)
我已将此报告给Apple作为iOS SDK错误.
在它修复之前,可以忽略警告并使用便利初始化程序吗?
在Xcode的UI测试,我怎么insertText了UIView符合UIKeyInput?
我创建了一个CodeInputView符合的UIKeyInput。
当我记录自己手动输入代码时,Xcode会写app.typeText("1234")。
但是,当我尝试播放该错误时,出现错误UI Testing Failure-元素和任何后代都不具有键盘焦点。而且,该问题的解决方案均无效。
在viewDidLoad我的自定义子类的UITableViewController,我已经设置navigationItem.titleView到searchBar的UISearchController,我与初始化nil了searchResultsController。
当我点击搜索栏时,输入文本,然后点击暗淡的基础内容,然后UISearchController将停用(按预期方式),并且清除输入的搜索文字(出乎意料)。
当我明确地(以编程方式)将搜索控制器设置为非活动状态时,搜索文本也被清除(也意外地)。为了解决这个问题,我先存储了搜索文本,然后在关闭搜索控制器后将其重新设置。尽管很hack,但它可以工作。
let searchText = searchBar.text // #hack
searchController.isActive = false
searchBar.text = searchText // #hack
Run Code Online (Sandbox Code Playgroud)
对于自动关闭搜索控制器的情况,我尝试使用UISearchControllerDelegate方法进行类似的操作,即将搜索文本存储在中willDismissSearchController(_:)并将其重新设置为didDismissSearchController(_:)。但是,此解决方案仍显示已清除搜索文本,然后将其设置回之前的状态。
自动关闭搜索控制器后,如何无缝保留搜索栏文本?
给定 的一个实例,在 之前UnsafeMutablePointer调用有什么意义?deinitialize(count:)deallocate(capacity:)
你就不能打电话吗deallocate(capacity:)?
我在raywenderlich.com上阅读Unsafe Swift:Using Pointers And Interacting With C文章的“Using Typed Pointers”部分时看到了这一点。
本文包含以下代码,您可以将其添加到 Xcode 中的新 Playground 中。
Run Code Online (Sandbox Code Playgroud)let count = 2 let stride = MemoryLayout<Int>.stride let alignment = MemoryLayout<Int>.alignment let byteCount = stride * count do { print("Typed pointers") let pointer = UnsafeMutablePointer<Int>.allocate(capacity: count) pointer.initialize(to: 0, count: count) defer { pointer.deinitialize(count: count) pointer.deallocate(capacity: count) } pointer.pointee = 42 pointer.advanced(by: 1).pointee = 6 pointer.pointee pointer.advanced(by: 1).pointee let bufferPointer = UnsafeBufferPointer(start: pointer, …
这些Xcode构建阶段之间的区别是:标头和复制文件?
当我向项目中添加Cocoa Touch静态库(iOS)时,它带有“复制文件”构建阶段,而当我添加“普通静态库”(macOS)时,它具有标题构建阶段。
我要添加的目标的源代码完全是用C编写的。而且,我希望能够将此项目包含在其他包含iOS和macOS应用程序目标的项目中。
在 Swift 中,我想将data类型为 的数据缓冲区(名为 )传递给采用类型为指针的DataC 函数(名为) 。do_somethingUnsafePointer<UInt8>
下面的代码示例正确吗?如果是这样,在这种情况下可以使用assumingMemoryBound(to:)代替 吗bindMemory(to:capacity:)?
data.withUnsafeBytes { (unsafeBytes) in
let bytes = unsafeBytes.baseAddress!.assumingMemoryBound(to: UInt8.self)
do_something(bytes, unsafeBytes.count)
}
Run Code Online (Sandbox Code Playgroud) 场景1:对于UIViewController,最好是(1)为UIView创建一个ivar,我在1或2个函数之外再次访问loadView?或者,(2)我应该只将其标记loadView,然后- (UIView *)viewWithTag:(NSInteger)tag再用于在其他功能中再次访问它?我猜测,选项1个增加通过指针的大小的存储器,所以64分之32位,并创建存取方法(假设我声明@property&@synthesize),然后需要释放所述的ivar dealloc并将其设置为nil在viewDidUnload...并且该选项2节省了内存,设置代码较少,但是花费了一些处理时间和一些额外的代码来通过其标记查找视图.我对这一切是对的吗?
在这种情况下,最好使用ivar,但我不确定.
场景2:UIView的自定义子类有5个子视图怎么样?请记住,在给定时间内,我将在内存中有大约30个此自定义子类的实例(它们将是tableViewCells的子视图),我应该使用5个ivars作为子视图,还是应该将它们全部标记?
在这种情况下,我认为通过标记它们所节省的内存将值得用它来搜索它们的小性能- (UIView *)viewWithTag:(NSInteger)tag.
思考?
谢谢!
马特