我是Obj-C的新手,所以我的第一个问题是:
之间有什么区别strong
,并weak
在@property
对象的指针的声明?
还有什么nonatomic
意思呢?
我创建了下一个词典:
var postJSON = [ids[0]:answersArray[0], ids[1]:answersArray[1], ids[2]:answersArray[2]] as Dictionary
Run Code Online (Sandbox Code Playgroud)
我得到:
[2: B, 1: A, 3: C]
Run Code Online (Sandbox Code Playgroud)
那么,我怎样才能将它转换为JSON?
我想将核心数据添加到现有的iPhone项目中,但我仍然遇到很多编译错误:
- NSManagedObjectContext undeclared
- Expected specifier-qualifier-list before 'NSManagedObjectModel'
- ...
Run Code Online (Sandbox Code Playgroud)
我已经将核心数据框架添加到目标(右键单击我的项目"Targets","Add" - "Existing Frameworks","CoreData.framework").
我的头文件:
NSManagedObjectModel *managedObjectModel;
NSManagedObjectContext *managedObjectContext;
NSPersistentStoreCoordinator *persistentStoreCoordinator;
[...]
@property (nonatomic, retain, readonly) NSManagedObjectModel *managedObjectModel;
@property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext;
@property (nonatomic, retain, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator;
Run Code Online (Sandbox Code Playgroud)
我错过了什么?开始一个新项目不是一个选择......
非常感谢!
编辑
对不起,我确实有这些实现...但似乎缺少库...实现方法已满,编译错误如" managedObjectContext undeclared
"," NSPersistentStoreCoordinator undeclared
",但也有"预期")'之前NSManagedObjectContext
"(虽然它似乎括号是正确的)...
#pragma mark -
#pragma mark Core Data stack
/**
Returns the managed object context for the application.
If the context doesn't already exist, it is created and …
Run Code Online (Sandbox Code Playgroud) 我是iOS5开发新手并使用objective-c.我无法理解强存储和弱存储之间的区别.我已经阅读了文档和其他SO问题,但它们听起来与我完全相同,没有进一步的见解.
我阅读了文档:Transitioning To ARC - 它引用了iOS4的retain,assign和release条件; 这让我很困惑.然后我看看Open U CS193p,它区分强弱:
强者:"把它保持在堆中,直到我不再指向它为止"
弱:"只要别人强烈地指出它就保持这种状态"
是不是两个定义相同=如果指针不再指向一个对象,那么释放持有该对象的内存?我理解指针,堆,分配或释放内存的概念 - 但强弱之间有什么区别?
有没有办法为a设置autocapitalizationType,UITextField
以便默认情况下每个单词的首字母大写?
这是我想要的一个例子
我想知道如何使用该UIView
属性clipsToBounds
.
官方文档说明如下:
clipsToBounds
属性一个布尔值,用于确定子视图是否仅限于视图的边界.
讨论
设置此值会YES
导致子视图被剪切到接收器的边界.如果设置为NO
,则不会剪切其帧超出接收器可见边界的子视图.默认值为NO
.
但我不清楚这究竟意味着什么.我该怎么用clipsToBounds
?将此属性设置为YES
完全有什么后果?或者NO
?
我试图弄清楚如何声明一个静态变量,只在本地作用于Swift中的函数.
在C中,这可能看起来像这样:
int foo() {
static int timesCalled = 0;
++timesCalled;
return timesCalled;
}
Run Code Online (Sandbox Code Playgroud)
在Objective-C中,它基本相同:
- (NSInteger)foo {
static NSInteger timesCalled = 0;
++timesCalled;
return timesCalled;
}
Run Code Online (Sandbox Code Playgroud)
但我似乎无法在Swift中做这样的事情.我试过用以下方式声明变量:
static var timesCalledA = 0
var static timesCalledB = 0
var timesCalledC: static Int = 0
var timesCalledD: Int static = 0
Run Code Online (Sandbox Code Playgroud)
但这些都会导致错误.
static
)和"预期模式"(在哪里timesCalledB
)static
)和"预期类型"(在哪里static
)Int
和static
)和"预期声明"(等号下签)我有以下代码集:
#import <UIKit/UIKit.h>
IB_DESIGNABLE
@interface CustomView : UIView
@property (nonatomic) IBInspectable UIColor *borderColor;
@property (nonatomic) IBInspectable CGFloat borderWidth;
@property (nonatomic) IBInspectable CGFloat cornerRadius;
@end
Run Code Online (Sandbox Code Playgroud)
#import "CustomView.h"
@implementation CustomView
- (void)setBorderColor:(UIColor *)borderColor {
_borderColor = borderColor;
self.layer.borderColor = borderColor.CGColor;
}
- (void)setBorderWidth:(CGFloat)borderWidth {
_borderWidth = borderWidth;
self.layer.borderWidth = borderWidth;
}
- (void)setCornerRadius:(CGFloat)cornerRadius {
_cornerRadius = cornerRadius;
self.layer.cornerRadius = cornerRadius;
}
@end
Run Code Online (Sandbox Code Playgroud)
(对于Swift参考,Swift代码也出现了这个问题)
@IBDesignable
class CustomView : UIView {
override init(frame: CGRect) {
super.init(frame: frame)
}
required init(coder aDecoder: …
Run Code Online (Sandbox Code Playgroud) ios ×4
objective-c ×2
swift ×2
bounds ×1
cocoa ×1
core-data ×1
frame ×1
function ×1
ibdesignable ×1
ios5 ×1
json ×1
static ×1
terminology ×1
uikit ×1
uitextfield ×1
uiview ×1