我正在寻找代码,询问用户是否要对应用程序进行评级,之后他们已经使用了X时间.我在一些大型游戏应用程序中看到了这一点.
我在一本书中看到了一个显示此代码的示例:
@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
我阅读了所有关于新的Objective-C文字,并使用Xcode转换我的旧代码,但索引代码没有改变.我手动改变它,但它不会编译.我看到一篇帖子说我们要等到iOS 6,但我现在要索引!
有什么解决方案吗?
我遇到了以下情况:
NSArray *array = @[object1, object2];
Run Code Online (Sandbox Code Playgroud)
它似乎是在创建一个NSArray,但是这个数组实例是一个自动释放的对象,还是我必须释放它?
我正在尝试在Xcode6 beta(版本6.0(6A215l))上启动基于Xcode5构建的Objective C应用程序.尝试为除iPhone 5s以外的任何平台构建时,我收到以下消息:
Xcode cannot run using the selected device.
The selected device specifies an unsupported architecture.
甚至不明显如何开始麻烦这个因为我无法达到控制台被激活的程度.有什么指针吗?
我的应用程序使用NSTimerObject的多个线程.
在一个函数中(随机时间随机调用,而不是固定的延迟)我希望它暂停整个应用程序,暂停线程1 second.我有以下代码:
[self performSelector:@selector(subscribe) withObject:self afterDelay:3.0 ];
Run Code Online (Sandbox Code Playgroud)
哪个是客观C,我尝试将其翻译成Swift,如下所示:
self.performSelector(Selector:changeColourOfPage(), withObject: self, afterDelay: 1.0)
Run Code Online (Sandbox Code Playgroud)
但是我得到了错误Missing argument for parameter 'waitUntilDone' in call,当我把它放进去的时候,它说它想要这个论点,modes但是当我把它放进去的时候说Extra argument modes.
我无法弄清楚如何暂停应用程序及其所有线程几秒钟,然后像往常一样继续?
有任何想法吗?
在我的应用程序中,我使用以下代码保存密钥:
func saveKey(){
var xmineSpillere = mineSpillere
var defaults = NSUserDefaults.standardUserDefaults()
defaults.setObject(xmineSpillere, forKey: "YourKey")
}
Run Code Online (Sandbox Code Playgroud)
但是如何检查密钥是否存在?我希望代码是这样的:
if key("YourKey") exists {
println("key exists")
}
else {
println("does not exist")
}
Run Code Online (Sandbox Code Playgroud)
我如何在Swift中做这样的事情?
我想将我的故事板本地化为德语.Xcode在为我的故事板创建main.strings文件方面做得很好.但是,我正在为我的许多表视图使用原型单元格.这些单元格中的每一个都只是在UILabels中使用虚拟文本,因为我在以后加载数据以填充表格视图时替换文本.
原型细胞:
故事板字符串文件:
有没有办法告诉Xcode忽略某些字符串,以便它们甚至不显示在字符串文件中?我不想付翻译来翻译虚拟文本.
objective-c ×6
cocoa-touch ×4
ios ×3
cocoa ×2
swift ×2
xcode ×2
class ×1
constructor ×1
ios7 ×1
ios8 ×1
localization ×1
nsdictionary ×1
nstimer ×1
scope ×1
uistoryboard ×1
xcode4.4 ×1
xcode6 ×1