在我的文件中添加一个(方便的)计算height属性会导致Swift编译器出现段错误......这里可能出现什么问题?UIViewUIViewExtension.swift
0 swift 0x00000001061e5608 llvm::sys::PrintStackTrace(__sFILE*) + 40
1 swift 0x00000001061e5af4 SignalHandler(int) + 452
2 libsystem_platform.dylib 0x00007fff894da5aa _sigtramp + 26
3 libsystem_platform.dylib 0xb03939841e997c88 _sigtramp + 2504775416
4 swift 0x00000001064c8bb9 swift::NominalTypeDecl::getMembers(bool) const + 41
5 swift 0x00000001055efab9 swift::irgen::ClassMetadataLayout<(anonymous namespace)::FindClassMethodIndex>::addClassMembers(swift::ClassDecl*) + 329
6 swift 0x00000001055e97b2 swift::irgen::emitVirtualMethodValue(swift::irgen::IRGenFunction&, llvm::Value*, swift::SILType, swift::SILDeclRef, swift::CanTypeWrapper<swift::SILFunctionType>, swift::ResilienceExpansion) + 434
7 swift 0x00000001056550d3 swift::SILVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::ValueBase*) + 42611
8 swift 0x000000010564a266 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 8678
9 swift 0x00000001055cb6f8 swift::irgen::IRGenModule::emitGlobalTopLevel() + 184
10 swift 0x00000001056376e3 performIRGeneration(swift::IRGenOptions&, swift::Module*, swift::SILModule*, …Run Code Online (Sandbox Code Playgroud) 我正在寻找类似于Objective-C的+(void)initialize类方法的行为,因为该方法在初始化类时被调用一次,之后再也不会被调用.
一个简单class init () {}的class关闭将是非常时尚!显然,当我们在结构封闭中使用" class vars"而不是" static vars"时,这一切都将很好地匹配!
我收到了错误......
Could not find an overload for 'init' that accepts the supplied arguments
......当我尝试使用......
extension UIFont {
func sizeOfString (string: String, constrainedToWidth width: Double) -> CGSize {
NSString(string).boundingRectWithSize(CGSize(width, DBL_MAX),
options: NSStringDrawingOptions.UsesLineFragmentOrigin,
attributes: [NSFontAttributeName: self],
context: nil).size
}
}
Run Code Online (Sandbox Code Playgroud)
难道NSString不支持这个方法了,还是我的语法搞乱?
比方说,我有一个weak var view: UIView?在我的class Button {}.有什么方法可以知道什么时候view失去它的参考并成为nil?
我尝试使用weak var view: UIView? {}(也称为计算属性)以覆盖set {},但这不起作用,因为现在它是一个计算属性,不能存储弱引用(多么烦人!).
编辑:
@fqdn的答案无法使用此代码...在Xcode Playground中尝试
import UIKit
class Test {
weak var target: UIView? {
willSet {
if !newValue { println("target set to nil") }
else { println("target set to view") }
}
}
}
class Button {
var view: UIView? = UIView()
}
var t = Test()
var b = Button()
t.target = b.view
b.view = …Run Code Online (Sandbox Code Playgroud) 此命令获取所有标记:
git fetch origin --tags
Run Code Online (Sandbox Code Playgroud)
此命令获取特定标记:
git fetch origin refs/tags/1.0.0
Run Code Online (Sandbox Code Playgroud)
但这不让我这样做:
git checkout tags/2.3.18
Run Code Online (Sandbox Code Playgroud)
如何获取单个标签然后执行结帐?
在Objective-C中,这很简单:
[NSString stringWithFormat:@"%p", objRef]
我怎么能在Swift中做到这一点?
在Xcode 6 Beta 5中,当我在构建之后尝试运行我的应用程序时,我收到一个错误对话框,其中显示:
应用安装失败
无法检查应用程序包.
这种情况发生在iOS 8 Beta 5上,但不适用于iOS 7.1.1!我没有测试任何其他东西.
关于如何解决这个问题的任何想法?
下面是我在构建应用程序时遇到的错误.有没有人有这个错误的经验?
ditto:无法获得源的真实路径'/Users/MyUsername/Library/Developer/Xcode/DerivedData/MyAppName-fwxrneawhopjkqcpeoykduytrgwv/Build/Intermediates/MyAppName.build/Debug-iphoneos/MyAppName.build/Objects-normal/arm64/ MyAppName-Swift.h"
命令/ usr/bin/ditto失败,退出代码为1
任何帮助都会很棒!
如果需要更多信息,请询问.:)
我收到错误:
Could not find an overload for 'init' that accepts the supplied arguments
当我输入:
var expr = NSRegularExpression(pattern: "test", options: 0, error: nil)
如果我通过NSRegularExpressionOptions会员,错误就会消失......
正如Apple 在Swift的文档中的Metatype Type部分中所说:
元类型类型是指任何类型的类型,包括类类型,结构类型,枚举类型和协议类型.
是否有基类来引用任何类,结构,枚举或协议(例如MetaType)?
我的理解是协议类型仅限于用作通用约束,因为Self或相关类型要求(嗯,这是Xcode错误告诉我的).
那么,考虑到这一点,也许有一个Class基类来识别类引用?或者是所有可构造类型(类,结构,枚举)的Type基类?其他可能性可能是Protocol,Struct,Enum和Closure.
如果你没有明白我的意思,请看这个例子.
func funcWithType (type: Type) {
// I could store this Type reference in an ivar,
// as an associated type on a per-instance level.
// (if this func was in a class, of course)
self.instanceType = type
}
funcWithType(String.self)
funcWithType(CGRect.self)
Run Code Online (Sandbox Code Playgroud)
虽然泛型在1-2个常量关联类型中运行良好,但我不介意能够将关联类型视为实例变量.
谢谢你的建议!