我有这门课:
@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
我正试图让一个自定义声音工作UILocalNotification,而我根本就没有声音.如果我使用UILocalNotificationDefaultSoundName,我确实得到默认声音,但是当指定自定义声音时,没有声音,只有消息.据我所知,声音不到30秒,而且格式正确.这是文件信息的屏幕截图:

我已经在XCode的DerivedData目录中检查了.app目录,并且alarm.caf文件位于应用程序的根目录,我相信这意味着它在捆绑包中(对吗?).
我很确定这是前一段时间了,我已经升级了Xcode.也许这是一个提示?
我也试过删除/重新安装/重启,如其他答案中所述.如你所见,我cancelAllLocalNotifications先打电话.
有谁知道什么可能是错的?
[[UIApplication sharedApplication] cancelAllLocalNotifications];
NSLog(@"installing alarm");
[arguments pop]; // name
[arguments pop]; // title
alarm.alertBody = [arguments pop];
alarm.fireDate = [[NSDate date] addTimeInterval:[[arguments pop] intValue]/1000];
//alarm.soundName = UILocalNotificationDefaultSoundName;
alarm.soundName = @"alarm.caf";
[[UIApplication sharedApplication] scheduleLocalNotification:alarm];
Run Code Online (Sandbox Code Playgroud) 我正在使用Clang的原始拳击功能来打包枚举成员 NSNumber
Clang doc 的Boxed Enums部分说明了编译器将成员枚举成整数,除非指定了类型.
有趣的是,我得到不同大小的整数,这取决于我将枚举成员传递给方法的方式.我已经能够将案例分解为以下代码
typedef enum _MyEnum {
MyEnumMember1 = 1000
} MyEnum;
- (void)testEnumerationBoxing
{
NSNumber *numberA = [self testA];
NSNumber *numberB = [self testB:MyEnumMember1];
CFNumberType numberTypeA = CFNumberGetType((__bridge CFNumberRef) numberA);
CFNumberType numberTypeB = CFNumberGetType((__bridge CFNumberRef) numberB);
NSLog(@"CF Number type for A: %lu; B: %lu", numberTypeA, numberTypeB);
}
- (NSNumber *)testA
{
return @(MyEnumMember1);
}
- (NSNumber *)testB:(MyEnum)enumMember
{
return @(enumMember);
}
Run Code Online (Sandbox Code Playgroud)
控制台输出是
CF编号类型为A:3; B:4
(第一个是kCFNumberSInt32Type,第二个是kCFNumberSInt64Type)
如果我改变声明,typedef enum _MyEnum …
我想用newBufferWithBytesNoCopy函数创建一个Metal缓冲区,让CPU和GPU共享内存并实现零拷贝数据传输.
newBufferWithBytesNoCopy函数采用UnsafeMutablePointer类型指针,指针需要与16K(16384)字节对齐.
任何人都可以提供有关如何在Swift中创建一定大小的对齐内存的建议吗?
没有文章清楚地解释我的查询,我在静态表中有三个单元格,我想在用户点击第一个单元格时隐藏第二个单元格.任何形式的帮助表示赞赏.
方法是否会变得混乱并且是同样的混合?如果没有,那么什么是混合?
我正在安排本地通知.它适用于iOS 9.x但是从iOS 10开始
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
Run Code Online (Sandbox Code Playgroud)
应用程序在iOS 10上运行时不会调用.
我知道iOS已经引入了新的UserNotifications框架,但不应该停止使用iOS 9 API.
我该如何解决这个问题?
我正在尝试计算StringSwift 中a的大小,但我不知道字符的大小是多少; 一个编码的字节数是多少?
假设我有一个字符串:
let str = "hello, world"
我想将它发送到我的服务器,但我的服务器只接受32字节以下的字符串.我如何控制弦乐的长度?
Swift具有模块化代码,可以分类为模块.
但您可以使用Swift Package Manager来获取和安装模块.
"Swift包"和"Swift模块"之间有什么区别吗?我应该何时使用一个短语或另一个短语?
ios ×6
objective-c ×5
swift ×4
cocoa-touch ×2
boxing ×1
clang ×1
cocoa ×1
constructor ×1
metal ×1
nsdictionary ×1
string ×1
swift3 ×1
swizzling ×1
uitableview ×1