我正在阅读有关内存管理的一些内容,他们不建议在初始化方法中使用访问器方法.
问题:为什么我们不应该在initilizer方法中使用访问器方法
我正在stackoverflow和其他网站上搜索有关此问题的引用.但是,我并不是很困惑.
任何人都可以就这个问题向我提出建议,或者你是否可以向我提出一个例子或一个好的参考资料,以便我可以自己去做.谢谢
叹了口气,整个下午我一直在努力......这是我的噩梦:
我正在尝试使用Apple制作的KeychainItemWrapper.但我将其Objective-C代码"翻译"为Swift:
import Foundation
import Security
class MyKeychainItemWrapper: NSObject {
var keychainItemData: NSMutableDictionary?
var genericPasswordQuery: NSMutableDictionary = NSMutableDictionary()
init(identifier: String, accessGroup: String?) {
super.init()
// Begin Keychain search setup. The genericPasswordQuery leverages the special user
// defined attribute kSecAttrGeneric to distinguish itself between other generic Keychain
// items which may be included by the same application.
genericPasswordQuery.setObject(kSecClassGenericPassword, forKey: kSecClass)
genericPasswordQuery.setObject(identifier, forKey: kSecAttrGeneric)
// The keychain access group attribute determines if this item can be shared
// amongst multiple apps whose …Run Code Online (Sandbox Code Playgroud) 所以基本上我试图在2个标签中分配2个随机数,最多20个,用户必须找到正确的结果.如果答案是否正确,将出现不同的视图,这将发生10次.问题是我在我使用的计数器"i"上出现错误,即使我将其声明为变量,但我得到一个错误,说它是一个常量.
@IBAction func submit(sender: AnyObject) {
//declarations
var i: Int //counter for 10 repetitions
var result = 0
for i in 0..<10 {
//generate 2 random numbers up to 20
var rn1 = arc4random_uniform(20)
var rn2 = arc4random_uniform(20)
//assign the rundom numbers to the labels
n1.text = String(rn1)
n2.text = String(rn2)
result = Int((rn1) + (rn2))
//show respective view based on if answer is correct or not
if answer.text == String(result) {
i = i + 1 //here i get …Run Code Online (Sandbox Code Playgroud) 下面的代码不会删除实体.控制台上出现"删除成功"消息,因此找到了实体.我使用的所有其他操作都成功.
我正在使用RestKit 0.20.
NSManagedObjectContext *context = [RKManagedObjectStore defaultStore].mainQueueManagedObjectContext;
NSError *error = nil;
NSFetchRequest * fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity: [NSEntityDescription entityForName:@"Auction" inManagedObjectContext:context]];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"AuctionID = %d", auctionID];
[fetchRequest setPredicate:predicate];
NSArray *result = [context executeFetchRequest:fetchRequest error:&error];
if(result.count) {
Auction *block = result[0];
[context deleteObject:block];
BOOL status = [context save:&error];
if (status == NO) {
NSLog(@"delete falied for AuctionID:%d, error: %@", auctionID, error);
}
else {
[context processPendingChanges];
NSLog(@"delete was successful for AuctionID:%d", auctionID);
}
}
Run Code Online (Sandbox Code Playgroud)
为什么删除操作不成功以及使其工作的解决方案是什么.
我有使用我的母语(英语)工作的SpeechSynthesisUtterance,但我需要将语言设置为意大利语以获得正确的发音.
该代码在Mac Safari中正常工作,但在iOS Safari中,发音是英语而非意大利语.
一个简单的测试是意大利语:"Ho i soldi","h"在意大利语中保持沉默.
<!DOCTYPE html><html lang='en' class=''>
<head><meta charset='UTF-8'></head>
<body>
<button id="Ho una prenotazione." onclick=speak(id)>Ho una prenotazione.</button>
I have a reservation
<script >
function speak(text) {
var msg = new SpeechSynthesisUtterance(text);
msg.lang = 'it-IT';
window.speechSynthesis.speak(msg);
}
</script>
</body></html>
Run Code Online (Sandbox Code Playgroud)
以下是上述代码的测试示例.
我已经下载了意大利语"Luca"并将其设置为默认设置:常规:可访问性:语音:语音:意大利语; Luca
我于2018年7月26日向Apple Safari和Web开发论坛发布了一个查询,结果是对日期没有回复:(422次,0篇回复).
我还提交了2018年8月16日的Apple开发人员技术支持(DTS)请求,该请求被拒绝,并建议发布到Web开发论坛.
虽然这可能被视为偏离主题,但请考虑我已尝试调试并请求Apple提供的帮助,但这些帮助已被忽略并被拒绝.
因此,似乎是iOS测试版问题,即使Chrome和Firefox应用程序都有英文发音.我有关于此问题的Beta bug报告.
我有一个要求,我有一个使用的视频MPMediaPlayerController.除了视频我还有两个按钮,我需要在点击按钮时捕获当前的播放时间并单独存储所有相关的点击.我可以使用返回的"currentPlaybackTime"属性获取视频的当前播放时间NSTimeInterval.但有人可以帮助我如何将所有NSTimeInterval值存储到一个NSMutableDictionary.我尝试了以下方法:
-(void)onClickOfGood {
NSLog(@"The current playback time in good:%g",moviePlayerController.currentPlaybackTime);
currentPlaybackTime = moviePlayerController.currentPlaybackTime;
//NSArray *arrayContainsGoodClicks = [[NSArray alloc]initWithObjects:currentPlaybackTime, nil ];
NSNumber *goodTimeIntervals = [NSNumber numberWithDouble:currentPlaybackTime];
NSMutableArray *arrayContainsGoodClicks = [[NSMutableArray alloc]initWithObjects:goodTimeIntervals,nil ];
NSLog(@"The total count of Array is: %i",[arrayContainsGoodClicks count]);}
Run Code Online (Sandbox Code Playgroud)
但是每次点击好按钮后我都会将阵列计数仅为1.有人可以点亮我出错的地方吗?
我的MKPointAnnotation应该使用此代码进行自定义:
-(MKPointAnnotation*)setAnnotation: (NSString*) title atLocation:(CLLocationCoordinate2D)Location withImage:(UIImage*) LocationImage{
Pin = [[MKPointAnnotation alloc] init];
Pin.title = title;
[Pin setCoordinate:Location];
[self mapView:mapView viewForAnnotation:Pin].annotation = Pin;
return Pin;
}
-(MKAnnotationView *)mapView: (MKMapView *)mapView viewForAnnotation: (id<MKAnnotation>) annotation{
MKPinAnnotationView* pinView = (MKPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:@"CustomPinAnnotationView"];
if(!pinView){
pinView = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:@"CustomPinAnnotationView"];
pinView.animatesDrop = YES;
pinView.canShowCallout = YES;
pinView.enabled = YES;
UIButton *PicButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[PicButton addTarget:self action:@selector(showLocationPicture) forControlEvents:UIControlEventTouchUpInside];\
pinView.rightCalloutAccessoryView = PicButton;
}
else{
pinView.annotation = annotation;
}
return pinView;
}
Run Code Online (Sandbox Code Playgroud)
然而,出于某种原因,Pin仍然是默认的,任何人都可以帮助我吗?谢谢
我正在开发一个用Objective-C和C++编写的iOS应用程序.在C++部分,我需要加密安全的随机数.
据我了解iOS安全模型,无法/dev/random直接访问.那是对的吗?
获得安全随机数的官方方法是SecRandomCopyBytes.遗憾的是,这是一个Objective-C接口.有没有办法从C++使用这个接口,理想情况下不使用Objective-C++?
还有arc4random,但我现在不愿意使用任何基于RC4的东西......
for(Attribute* attribute in appDelegate.attributeArray) {
attribute = [appDelegate.attributeArray objectAtIndex:z];
attri = attribute.zName;
int y = 0;
for(Row* r in appDelegate.elementsArray) {
r = [appDelegate.elementsArray objectAtIndex:y];
NSString *ele = r.language;
if([attri isEqualToString:ele]) {
NSLog(@"=================+++++++++++++++++%@ %@",attri, r.user);
[aaa insertObject:r atIndex:y]; //here i am adding the value to array
[dict setObject:aaa forKey:attri]; //here i am adding the array to dictionary
}
y++;
}
z++;
NSLog(@"============$$$$$$$$$$$$$$$$$$$$$$$++++++++++ %@",dict);
}
Run Code Online (Sandbox Code Playgroud)
键入一个数组,另一个数组中的值和值数组是对象格式.
我需要为单个键存储多个对象.在attributeArray有键值和elementsArray拥有的对象.例如,attributeArray可能具有值
" English, French, German..."
Run Code Online (Sandbox Code Playgroud)
而elementsArray可能具有对象值
"<Row: 0x4b29d40>, <Row: 0x4b497a0>, <Row: …Run Code Online (Sandbox Code Playgroud) 我想设计它,以便如果用户单击主页按钮然后返回到应用程序,应用程序将识别该操作并生成消息供用户查看(例如,欢迎回来).我想我应该为此修改appdelegate,但我不知道如何编写它...任何人都可以伸出援手吗?
ios ×5
objective-c ×5
iphone ×4
swift ×2
c++ ×1
core-data ×1
cryptography ×1
html ×1
ios5 ×1
ios8 ×1
javascript ×1
random ×1
restkit ×1
restkit-0.20 ×1
safari ×1
security ×1
xcode6-beta6 ×1