小编zap*_*aph的帖子

如何将对象数组添加到nsmutabledictionary,并将另一个数组作为键

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)

iphone objective-c nsmutablearray nsmutabledictionary

4
推荐指数
1
解决办法
2万
查看次数

在Swift中使用NSURLSession下载文件

我在这里有两个问题,首先我不能用一个快速项目设置NSURLSessionDownloadDelegate,编译说

Type 'ViewController' does not conform to protocol 'NSURLSessionDownloadDelegate'
Run Code Online (Sandbox Code Playgroud)

第二个问题是我无法找到NSURLSession方法来下载一个简单的文件

这是我用来下载简单文件的方式

    var url:NSURL = NSURL.URLWithString(fileURL)
    var request:NSURLRequest = NSURLRequest(URL: url)
    var downloadTask:NSURLSessionDownloadTask = sessionManager.downloadTaskWithRequest(request)
    downloadTask.resume()
Run Code Online (Sandbox Code Playgroud)

这些是我想在swift中制作的方法

URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didWriteData:(int64_t)bytesWritten totalBytesWritten:(int64_t)totalBytesWritten totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite
Run Code Online (Sandbox Code Playgroud)

..

URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location
Run Code Online (Sandbox Code Playgroud)

..

URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error
Run Code Online (Sandbox Code Playgroud)

..如果有一种新方法可以下载NSURLSession的文件我想知道,并且在NSURLSession中有什么新内容在swift中

ios nsurlsession nsurlsessiondownloadtask swift

4
推荐指数
1
解决办法
2万
查看次数

iOS7和iOS8返回不同的UIScreen界限

我为部署目标> = 7.1创建应用程序.我看到了"bug"......应用程序只在横向模式下运行!

码:

CGSize frameSize = [[UIScreen mainScreen] bounds].size;
Run Code Online (Sandbox Code Playgroud)

在iOS 7(iPhone 4)中,返回CGSize (width=320, height=480),但必须返回480x320(因为在横向模式下运行应用程序).在iOS 8(iPhone 4S)中,返回CGSize (width=480, height=320)- 正确的结果.

iOS 7在没有检查横向/纵向模式的情况下返回帧的印象,以及纵向模式的返回尺寸.

谢谢.

iphone objective-c ios ios7 ios8

4
推荐指数
2
解决办法
1786
查看次数

更新到Xcode 7.0.1和Project现在有问题

所以我将我的Xcode 6.1版本上传到iTunes Connect,该应用程序获得批准.现在我正在尝试更新应用程序,我更新到Xcode 7.0.1和Xcode给我的问题说明:

(对于app我使用了故事板和Objective-C)

警告:除非应用程序需要全屏,否则必须支持所有界面方向.

警告:除非应用程序需要全屏,否则必须提供启动故事板或xib.

- (NSUInteger)supportedInterfaceOrientations {

return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
}
Run Code Online (Sandbox Code Playgroud)

iOS 9支持的新界面是什么?

objective-c storyboard orientation ios ios9

4
推荐指数
1
解决办法
3308
查看次数

CoreData,多对多关系和NSPredicate

我有一个包含多对多关系的CoreData数据模型.事实证明,NSPredicate不支持多对多关系.来自CoreData.pdf:"在谓词的键路径中只能有一对多元素."

作为食谱的例子:许多食谱和许多成分.配方可以有许多成分,其中"盐"可以是一种,而"盐"则用于许多配方中.这是一种自然的多对多关系.

建议的解决方法是什么?
CoreData是个坏主意我应该回到SQLite吗?

iphone core-data

3
推荐指数
1
解决办法
2702
查看次数

无法使用索引类型int下标[CLPlacemark]类型的值

我想检索当前位置.我在swift Xcode 7上工作.我看了PLUSIEUR教程,但每次使用相同的方法.这是我的代码和我的错误:!

错误:无法使用索引类型int下标[CLPlacemark]类型的值

import UIKit
import CoreLocation

class ViewController: UIViewController, CLLocationManagerDelegate {

    let LocationManager = CLLocationManager()

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    self.LocationManager.delegate = self
    self.LocationManager.desiredAccuracy = kCLLocationAccuracyBest
    self.LocationManager.requestWhenInUseAuthorization()
    self.LocationManager.startUpdatingLocation()

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}



func locationManager(manager: CLLocationManager, didUpdateLocations locations: [AnyObject]) {
    CLGeocoder().reverseGeocodeLocation(manager.location!, completionHandler: { (placemarks, error) -> Void in

        if (error != nil) {
            print("Error") …
Run Code Online (Sandbox Code Playgroud)

xcode ios swift ios8 xcode7

3
推荐指数
1
解决办法
2588
查看次数

AES128 CTR 加密与 iv

我想用 iv 和 key 实现 AES128 CTR。我正在寻找如何以最好的方式做到这一点而不是重新发明轮子的建议。

我找到了这个RNCryptor的好库,但看起来那里不支持这个 aes。

我也测试了这种方法,但看起来这不是点击率。

编辑


我使用了 @zaph 的 zpproach

NSData *result = [NSData cryptData:dataStr
                         operation:kCCEncrypt
                              mode:kCCModeCTR
                         algorithm:kCCAlgorithmAES128
                           padding:ccNoPadding
                         keyLength:kCCKeySizeAES128
                                iv:ivHex
                               key:keyHex
                             error:&error];
Run Code Online (Sandbox Code Playgroud)

但收到CCCryptorCreate status: -4305

刚刚在源码中找到的

@constant kCCUnimplemented Function not implemented for the current algorithm.

关联

encryption aes ios commoncrypto

3
推荐指数
1
解决办法
3147
查看次数

如何找到两次之间的差异?

我有这个代码:

-(IBAction)startTime:(id)sender {
    NSDate *myDateTime1 = [[NSDate alloc] init];
    NSLog(@"%@", myDateTime1);
    [myDateTime1 release];
}

-(IBAction)stopTime:(id)sender {
    NSDate *myDateTime2 = [[NSDate alloc] init];
    NSLog(@"%@", myDateTime2);
    [myDateTime2 release];
}
Run Code Online (Sandbox Code Playgroud)

我想找到两次之间的区别.我怎么能做到这一点?

iphone objective-c ios

2
推荐指数
1
解决办法
2874
查看次数

使用带有unichar和String的二元运算符

我试图使用二元运算符来比较两个值:

character = (xxx as NSString).characterAtIndex(2)
if character == "1" {
    //do this thingy   
}
Run Code Online (Sandbox Code Playgroud)

现在我收到失败消息Binary Operator'=='不能应用于unichar或String类型的操作数.我也试图转换角色:

if String(character) == "1" 
Run Code Online (Sandbox Code Playgroud)

不起作用......

binary-operators unichar ios swift

2
推荐指数
1
解决办法
1428
查看次数

路由应用程序覆盖文件可选,不包括在内,但现在我无法保存

我想在iTunes Connect中保存我的应用程序.我以前做了很多次,但现在我收到一个错误,提醒我路由应用程序覆盖文件.它说我需要包含它,但我不会也从来没有.我的应用程序不使用任何映射功能等.

说:"您的路由应用程序覆盖文件必须采用geoJSON格式".但我没有路由文件,也没有任何需要,因为我的应用程序没有使用任何路由功能

我不确定为什么会这样.

xcode itunesconnect ios

2
推荐指数
1
解决办法
490
查看次数

使用从测试方法调用的方法的类的OCMock

我试图测试一个实例化实例的方法MFMailComposeViewController.被测试的方法调用的多种方法MFMailComposeViewController,包括setSubject:.

我想测试setSubject是否发送了一个特定的NSString,在本例中是@"Test Message".
无论我为模拟存根中的预期字符串指定什么,都没有失败.

在单元测试类中:

#import <OCMock/OCMock.h>

- (void)testEmail {
    TestClass *testInstance = [[TestClass alloc] init];

    id mock = [OCMockObject mockForClass:[MFMailComposeViewController class]];
    [[mock stub] setSubject:@"Test Message"];

    [testInstance testMethod];
}
Run Code Online (Sandbox Code Playgroud)

在TestClass中:

- (void)testMethod {
    MFMailComposeViewController *mailComposeVC = [[MFMailComposeViewController alloc] init];
    [mailComposeVC setSubject:@"Bad Message"];
}

Test Suite 'Email_Tests' started at 2011-09-17 18:12:21 +0000
Test Case '-[Email_Tests testEmail]' started.
Test Case '-[Email_Tests testEmail]' passed (0.041 seconds).
Run Code Online (Sandbox Code Playgroud)

测试应该失败.

我在iOS模拟器中对此进行测试,并在设备上获得相同的结果.

我究竟做错了什么?有没有办法实现这个目标?

unit-testing objective-c ocunit ocmock ios

1
推荐指数
1
解决办法
3169
查看次数

在if语句中设置子类

我有两个子类SubClassA和SubClassB,它们都是ClassA的子类,它有一个名为someProperty的属性.我想在if语句里面决定使用哪些子类,然后才能使用这个对象.

if(conditionA){
    SubClassA *myObject;
}
else{
    SubClassB *myObject;
}    

myObject.someProperty=someValue;
Run Code Online (Sandbox Code Playgroud)

这不起作用,因为我不能在if-else语句之外使用myObject.我怎么解决这个问题?是否可以首先创建父对象然后将其更改为属于子类?

subclass objective-c

0
推荐指数
1
解决办法
121
查看次数

Objective-C算法的障碍

这段代码是震动事件的范围,

if(i % 3) {
    self.Label.text = [NSString stringWithFormat:@"%d", y];
    y += 1;        
}
Run Code Online (Sandbox Code Playgroud)

每当我达到3,
y + = 1就会执行.

当我再摇一摇时,

y值再加1,
i现在等于4

所以现在i = 4,y = 2,我明白为什么y又添加了1,但我无法弄清楚如何避免它,请帮忙.

objective-c

-7
推荐指数
1
解决办法
72
查看次数