在Swift 2.0中NSError符合ErrorType协议.
对于自定义错误,我们可以为某些情况指定关联对象,如下所示.
enum LifeError: ErrorType {
case BeBorn
case LostJob(job: String)
case GetCaughtByWife(wife: String)
...
}
Run Code Online (Sandbox Code Playgroud)
我们可以轻松地做到以下几点:
do {
try haveAffairWith(otherPerson)
} catch LifeError.GetCaughtByWife(let wife) {
...
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我们希望它作为一个传递到其他地方NSError,它就会丢失它的关联对象信息.
println("\(LifeError.GetCaughtByWife("Name") as NSError)")
Run Code Online (Sandbox Code Playgroud)
打印:
Error Domain=... Code=1 "The operation couldn't be completed". (... error 1)
Run Code Online (Sandbox Code Playgroud)
它userInfo是nil.
我wife和哪里有联系ErrorType?
我正在为iPad开发iOS应用程序.有没有办法旋转UIImage90º然后将其添加到UIImageView?我尝试了很多不同的代码,但都没有工作......
谢谢!
我想创建一个子类,NSMutableArray并需要覆盖该-initWithObjects:方法.
但如何调用[超级xxx];?
- (id) initWithObjects:(id)firstObj, ... {
[super initWithObjects:firstObj]; // Error: Missing sentinel in method dispatch
// Error: The result of a delegate init call must be immediately returned or assigned to "self"
}
Run Code Online (Sandbox Code Playgroud)
谢谢.
我有一个看起来像这样的课程:
public final class OrderedSetList<T extends Comparable<? super T>> implements OrderedSet<T> {
// Constructor definition in wrong order checkstyle error next line
public OrderedSetList() {
// Initializations
}
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以告诉我为什么在我的构造函数中有一个"错误顺序的构造函数定义"错误?
这是一项任务,我们有自己的checkstyle配置,不允许任何checkstyle错误.
我感谢你的帮助.
我在Swift中创建了一个名为RGB的结构,很简单:
struct PixelRGB {
var r: CUnsignedChar = 0
var g: CUnsignedChar = 0
var b: CUnsignedChar = 0
init(red: CUnsignedChar, green: CUnsignedChar, blue: CUnsignedChar) {
r = red
g = green
b = blue
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个指针var imageData: UnsafeMutablePointer<PixelRGB>!.
我希望为此指针malloc一些空间,但malloc返回UnsafeMutablePointer<Void>并且我不能像下面那样强制转换它:
imageData = malloc(UInt(dataLength)) as UnsafeMutablePointer<PixelRGB> // 'Void' is not identical to `PixelRGB`
Run Code Online (Sandbox Code Playgroud)
无论如何要解决这个问题?谢谢您的帮助!
我创建了UIImageView的子类,每当我调用initWithFrame或initWithImage或Init时,我想添加一些东西.
-(id) init {
[super init];
NSLog(@"Init triggered.");
}
Run Code Online (Sandbox Code Playgroud)
如果我打电话给-initWithFrame:方法,-init上面也会被触发吗?
我想让iPhone震动,我找到了代码
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
Run Code Online (Sandbox Code Playgroud)
但Xcode 4.3.2报告错误:未声明的标识符kSystemSoundID_Vibrate
有什么问题?
将状态栏设置为隐藏时
override var prefersStatusBarHidden: Bool {
return true
}
Run Code Online (Sandbox Code Playgroud)
并使用初始化普通 searchController
let searchController = UISearchController(searchResultsController: nil)
navigationItem.searchController = searchController
Run Code Online (Sandbox Code Playgroud)
如果未经编辑,它似乎正常,但是如果您单击搜索栏,导航标题将隐藏,搜索栏和顶部边缘之间几乎没有填充,这在视觉上非常破碎.
解决方案表示赞赏

UITextView缩进问题:
例如,我希望"测试"文本有点正确,我应该设置什么属性?
我希望我可以将一些 pod 编译成动态框架,同时将其他 pod 保留为静态框架。
use_frameworks!
pod 'A'
pod 'B'
pod 'C'
Run Code Online (Sandbox Code Playgroud)
默认情况下,该use_frameworks!选项是全或无方法。我想知道我们是否可以选择不动态编译某些框架。
例如,如何A在保留B和C静态库的同时将pod编译成动态框架?谢谢!
objective-c ×4
ios ×3
xcode ×3
subclass ×2
swift ×2
audio ×1
checkstyle ×1
cocoa ×1
cocoapods ×1
indentation ×1
init ×1
ios11 ×1
ios6 ×1
ipad ×1
iphone ×1
java ×1
nsarray ×1
swift2 ×1
uiimage ×1
uiimageview ×1
uisearchbar ×1
uitextfield ×1
vibration ×1