我有一些数据(如NSDictionarya NSMutableArray),样本数据是这样的,

考虑每一行NSDictionary,整个表是一个NSMutableArray包含事件.
我想在两个日期之间产生结果,所以我NSPredicate用来过滤我的数据.
这是我的代码片段,
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"Date >= %@ AND
Date <= %@", startDate,endDate];
NSArray *filter = [arrayEvents filteredArrayUsingPredicate:predicate];
Run Code Online (Sandbox Code Playgroud)
测试过滤:
情况1:
NSString *startDate = @"01/07/14";
NSString *endDate = @"31/07/2014";
Run Code Online (Sandbox Code Playgroud)
输出: 所有事件(行).
案例2:
NSString *startDate = @"20/07/14";
NSString *endDate = @"31/07/2014";
Run Code Online (Sandbox Code Playgroud)
输出: 最后四个事件(行).
案例3:
NSString *startDate = @"11/07/14";
NSString *endDate = @"20/07/2014";
Run Code Online (Sandbox Code Playgroud)
输出: 仅第二个事件(行).
案例4:
NSString *startDate = @"01/08/14";
NSString *endDate = @"31/08/2014";
Run Code Online (Sandbox Code Playgroud)
输出: 所有事件(行).
结论:
案例1,2和3是正确的,案例4不正确.
笔记: …
我知道这是一个非常基本的问题,但我现在陷入困境.
我从电话簿中取出联系电话号码并将它们放在一个数组中.
然后从NSString中的数组中获取特定的一个
我试图从数字中删除空格,但实际上并没有使用以下编写的代码:
NSString *num = @"+44 123 456 7890";
num = [num stringByReplacingOccurrencesOfString:@" " withString:@"0"];
**OR**
num = [num stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
Run Code Online (Sandbox Code Playgroud)
请让我知道我需要做些什么来删除这个空间.
谢谢
编辑
NSString *num = [contactNumbers objectAtIndex:i];
num = [num stringByReplacingOccurrencesOfString:@"-" withString:@""];
num = [num stringByReplacingOccurrencesOfString:@" " withString:@""];
num = [num substringFromIndex:[num length]-10];
Run Code Online (Sandbox Code Playgroud) 大家好,我想使用iOS8的新APN来处理通知操作.在这个方法中:
- (void)application:(UIApplication *)application
handleActionWithIdentifier:(NSString *)identifier
forRemoteNotification:(NSDictionary *)notification
completionHandler:(void (^)())completionHandler {
if ([identifier isEqualToString:@"ACCEPT_IDENTIFIER"]) {
[self handleAcceptActionWithNotification:notification];
}
else if([identifier isEqualToString:@"MAYBE_IDENTIFIER"]) {
[self handleMaybeActionWithNotification:notification];
}
else if ([identifier isEqualToString:@"REJECT_IDENTIFIER"]) {
[self handleRejectActionWithNotification:notification];
}
else if....blah blah blah..
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我可能不得不在将来用NSString编写太多if-else语句,并且我知道某种方法可以避免使用过多的if-else语句,例如使用switch,但它不适用于字符串或NSString情况.
是避免在此字符串或NSString情况下编写过多if-else语句的解决方案吗?提前致谢.
我有
NSstring *str = @"Existing applications can be improved or extended on 11-01-2014 at 4 PM for 120$ ";
Run Code Online (Sandbox Code Playgroud)
从上面的字符串我想得到日期,时间和金额.上面的字符串我试图动态..
我试过的是
NSArray *arySeperator = [result componentsSeparatedByString:@" "];
for(int i=0;i< [arySeperator count];i++)
{
}
Run Code Online (Sandbox Code Playgroud)
无法继续......
关于如何进一步的任何帮助或建议?
在我的iOS应用程序中,我有以下代码:
case SASpeechSubCase03:
{
SAActivity currentActivity = self.mediator.selectedActivity;
NSString *sActivity = NSLocalizedString(@"activity", @"activity");
NSString *sActivity2 = NSLocalizedString(@"another activity", @"another activity");
if(currentActivity == SAActivityWalk)
{
sActivity = NSLocalizedString(@"walk", @"walk");
sActivity2 = NSLocalizedString(@"walking", @"walking");
}
else
{
sActivity = NSLocalizedString(@"run", @"run");
sActivity2 = NSLocalizedString(@"jogging", @"jogging");
}
return [NSString stringWithFormat:speech.text, sActivity, sActivity2];
break;
}
Run Code Online (Sandbox Code Playgroud)
当我在它上面运行机器人时,它给了我以下警告:
机器人问题:analyzerWarning.死店.问题:永远不会读取在初始化期间存储到'sActivity'的值.文件:SAAnnouncementService.m.积分编号:42.说明:永远不会读取在初始化期间存储到'sActivity'的值.
机器人问题:analyzerWarning.死店.问题:永远不会读取在初始化期间存储到'sActivity2'的值.文件:SAAnnouncementService.m.积分编号:42.说明:永远不会读取在初始化期间存储到'sActivity2'的值.
有人能说出问题可能在这里吗?
任何形式的帮助都非常感谢!
我只是想知道一个文本文件是否等于另一个.当然我可以将文件加载到NSString并进行比较,但是有更好的方法吗?
我的字符串是 @"Hello, I am working as an ios developer"
现在我想要删除所有字符 "ios"
最后我想删除最后一个空格字符后的所有字符.
我怎样才能做到这一点?
我有一个包含我在字符串中允许的字符的集合:
var characterSet:NSCharacterSet = NSCharacterSet(charactersInString: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLKMNOPQRSTUVWXYZ")
Run Code Online (Sandbox Code Playgroud)
我想从字符串中去掉任何其他字符,这样两个未格式化的数据就可以被认为是相等的,如下所示:
"American Samoa".lowercaseString == "american_samoa1".lowercaseString
Run Code Online (Sandbox Code Playgroud)
这些转换后的字符串的小写版本将是 "americansamoa"
我在NSMutableDictionary中有以下值 - 请参阅图像

我试图得到"a"因此:
let a = dictionary.objectForKey("a") as! String
Run Code Online (Sandbox Code Playgroud)
应用程序此时崩溃了
无法将'__NSCFNumber'(0x ...)类型的值转换为'NSString'(0x ...).
""内的其他数字被视为字符串,因为字符串之外的数字被转换为字符串而没有任何问题.
任何人都可以让我知道发生了什么事吗?以及如何轻松获得这些价值?
我正在尝试从字符串"5小时10分钟"获取整数变量中的小时和分钟.可以任何人给我解决方案.
NSString *duration =@"5 hours 10 min";
int hours = 5
int min = 10
Run Code Online (Sandbox Code Playgroud) nsstring ×10
ios ×8
objective-c ×5
iphone ×2
swift ×2
arrays ×1
if-statement ×1
nsarray ×1
nsnumber ×1
nspredicate ×1
regex ×1
string ×1
text ×1
xcode ×1