如何创建UIImageView代码,而不是在我的xib文件中创建它?
我在一本书中看到了一个显示此代码的示例:
@implementation ViewController
{
NSString *name;
}
Run Code Online (Sandbox Code Playgroud)
为什么不宣布这个@interface?在声明变量@implementation而不是@interface?中有什么区别?为什么NSString在范围内声明这个?
我有这门课:
@interface RSSEntry : NSObject{
NSString *blogTitle;
NSString *articleTitle;
NSString *articleUrl;
NSDate *articleDate;
}
@property (copy) NSString *blogTitle;
@property (copy) NSString *articleTitle;
@property (copy) NSString *articleUrl;
@property (copy) NSDate *articleDate;
@end
Run Code Online (Sandbox Code Playgroud)
现在,在创建对象时,如何使这些成员变量初始化,尤其是在Xcode项目中启用ARC时?我是Objective-C的新手; 我正在寻找类似C语言的构造函数.
我正在使用NSMutableDictionary并点击此错误:
'NSInternalInconsistencyException', reason: '-[__NSCFDictionary removeObjectForKey:]: mutating method sent to immutable object'
Run Code Online (Sandbox Code Playgroud)
这是代码:
// Turn the JSON strings/data into objects
NSError *error;
NSMutableDictionary *invoiceDictFromReq = [[NSMutableDictionary alloc] init];
// invoiceDictFromReq = (NSMutableDictionary *)[NSJSONSerialization JSONObjectWithData:[request responseData] options:kNilOptions error:&error];
invoiceDictFromReq = [NSMutableDictionary dictionaryWithDictionary:[NSJSONSerialization JSONObjectWithData:[request responseData] options:kNilOptions error:&error]];
NSLog(@"invoiceDictFromReq count: %i, key: %@, value: %@", [invoiceDictFromReq count], [invoiceDictFromReq allKeys], [invoiceDictFromReq allValues]);
// Get values and keys from JSON response
self.invoiceDict = [invoiceDictFromReq objectForKey:@"invoice"];
NSNumber *invoiceAmount = [self.invoiceDict objectForKey:@"amount"];
NSNumber *invoiceId = [self.invoiceDict …Run Code Online (Sandbox Code Playgroud) cocoa-touch objective-c nsdictionary nsmutabledictionary ios
我想知道如何评估方程的字符串表示,就好像它是一个真实的方程:
if(@"15+14==23")
{
//True statement...
}
else
{
//False statement....
}
Run Code Online (Sandbox Code Playgroud)
我想返回"假",因为15 + 14不等于23.我怎么能让它工作?
cocoa cocoa-touch objective-c expression-evaluation nsstring
我正在尝试将 rgba 缓冲区转换为 argb,是否有任何方法可以改进下一个算法,或者任何其他更快的方法来执行此类操作?考虑到 alpha 值在 argb 缓冲区中一次并不重要,并且应始终以 0xFF 结束。
int y, x, pixel;
for (y = 0; y < height; y++)
{
for (x = 0; x < width; x++)
{
pixel = rgbaBuffer[y * width + x];
argbBuffer[(height - y - 1) * width + x] = (pixel & 0xff00ff00) | ((pixel << 16) & 0x00ff0000) | ((pixel >> 16) & 0xff);
}
}
Run Code Online (Sandbox Code Playgroud) isFinished我的界面文件中有一个只读属性:
typedef void (^MyFinishedBlock)(BOOL success, NSError *e);
@interface TMSyncBase : NSObject {
BOOL isFinished_;
}
@property (nonatomic, readonly) BOOL isFinished;
Run Code Online (Sandbox Code Playgroud)
我想YES稍后在某个块中将它设置为一个块,而不创建一个保留周期self:
- (void)doSomethingWithFinishedBlock:(MyFinishedBlock)theFinishedBlock {
__weak MyClass *weakSelf = self;
MyFinishedBlock finishedBlockWrapper = ^(BOOL success, NSError *e) {
[weakSelf willChangeValueForKey:@"isFinished"];
weakSelf -> isFinished_ = YES;
[weakSelf didChangeValueForKey:@"isFinished"];
theFinishedBlock(success, e);
};
self.finishedBlock = finishedBlockWrapper; // finishedBlock is a class ext. property
}
Run Code Online (Sandbox Code Playgroud)
我不确定这是正确的做法.这段代码会泄漏,破坏,还是没问题?也许有一种我更容易被忽视的方式?
objective-c objective-c-blocks ivar automatic-ref-counting declared-property
我正在尝试在Xcode6 beta(版本6.0(6A215l))上启动基于Xcode5构建的Objective C应用程序.尝试为除iPhone 5s以外的任何平台构建时,我收到以下消息:
Xcode cannot run using the selected device.
The selected device specifies an unsupported architecture.
甚至不明显如何开始麻烦这个因为我无法达到控制台被激活的程度.有什么指针吗?
如何UNNotificationSettings在iOS 10中使用获取通知类型?
在以前的iOS上,我会使用这个:
UIUserNotificationSettings *notificationSettings = [[UIApplication sharedApplication] currentUserNotificationSettings];
Bool active = notificationSettings.types == UIUserNotificationTypeNone ? NO: YES;
Run Code Online (Sandbox Code Playgroud) objective-c ×6
cocoa-touch ×4
ios ×4
cocoa ×2
animation ×1
argb ×1
class ×1
constructor ×1
ios10 ×1
ios7 ×1
ios8 ×1
ivar ×1
nsdictionary ×1
nsstring ×1
performance ×1
rgba ×1
scope ×1
uiimageview ×1
xcode ×1
xcode6 ×1