iOS5 中的 RegexKitLite

发布于 2024-12-11 02:50:48 字数 251 浏览 0 评论 0原文

我的应用程序中需要 RegexKitlite 作为字符串验证的一部分。 还添加了 libicucore.A.dylib 。 目前使用 xcode 4.2、Base sdk iOS 5.0、Apple LLVM 编译器 3.0、架构 armv7。 将 regexkit 文件夹添加到我的应用程序中会导致太多错误,例如 自动引用计数错误, 将 Objective-C 指针类型“NSString *”转换为 C 指针类型“CFStringRef”等

请帮忙;我哪里出错了。

I need RegexKitlite in my App as a part of String validation.
Have also added libicucore.A.dylib .
Currently working with xcode 4.2,Base sdk iOS 5.0,Apple LLVM compiler 3.0,architechture armv7.
Adding the regexkit folder to my app, causes too many errors like
Automatic Reference Counting Errors ,
Cast of Objective-C pointer type 'NSString *' to C pointer type 'CFStringRef' etc

Please help;where have I gone wrong.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

寻梦旅人 2024-12-18 02:50:48

您还可以仅通过添加标志来禁用 RegexKitLite 的 ARC:

选择项目 ->您的目标 ->在“构建阶段”选项卡上,打开“编译源”并为“RegexKitLite.m”添加标志“-fno-objc-arc”。

更新:
如果您得到:

未定义的符号:
“_uregex_reset”,引用自:
RegexKitLite.o 中的 _rkl_splitArray
RegexKitLite.o 中的 _rkl_replaceAll
“_uregex_appendTail”,引用自:.......

然后您需要在“Build Settings”选项卡中添加 -> “链接”-> “其他链接器标志”“-licucore”

You can also disable the ARC for the RegexKitLite only by adding a flag:

select the project -> YOUR Target -> on the Tab the "Build Phases" and open the "Compile Sources" and add for "RegexKitLite.m" the flag "-fno-objc-arc".

Update:
If you get:

Undefined symbols:
"_uregex_reset", referenced from:
_rkl_splitArray in RegexKitLite.o
_rkl_replaceAll in RegexKitLite.o
"_uregex_appendTail", referenced from:.......

Then you need to add in the Tab "Build Settings" -> "Linking" -> "Other Linker Flags" the "-licucore"

┈┾☆殇 2024-12-18 02:50:48

你没有做错任何事。 Regexkit 只是还没有更新到 iOS 5。 iOS 5 中的重大变化是不再保留、发布或自动发布。每个内存事情都是自动的,就像 Java 一样。 (除了它发生在编译时而不是运行时。所以它在概念上类似于 Java。大多数情况下。)

无论如何,您可以使用 NSRegularExpression,而不是等待 Regexkit 更新。使用苹果产品也是面向未来的,因为他们不断更新自己的产品版本。

祝你好运!

You aren't doing anything wrong. Regexkit just hasn't been updated to iOS 5 yet. The big change in iOS 5 is there are no longer retains, releases, or autoreleases. Every memory thing is automatic like Java. (Except that it happens at compile time instead of run time. So it's conceptually like Java. Mostly.)

Anyway, instead of waiting for Regexkit to update you can use NSRegularExpression. Using Apple stuff is also future-proof since they keep their own stuff updated version to version.

Good luck!

天涯离梦残月幽梦 2024-12-18 02:50:48

CB格雷厄姆是对的。或者,您可以禁用自动引用计数(项目 > 构建设置 > 搜索“自动引用计数”)。

显然,您必须进行手动引用计数,但 RegexKitLite 现在应该构建......

CBGraham is right. Alternatively, you could disable automatic reference counting (Project > Build settings > search for 'automatic reference counting').

You will obviously have to do manual reference counting, but RegexKitLite should build now...

离去的眼神 2024-12-18 02:50:48

我用两种方法替换了 RegexKitLite。

字符串结果:

+(NSString*) regExString: (NSString *) pattern withString: (NSString *) searchedString {
    NSError  *error = nil;
    NSRegularExpression* regex = [NSRegularExpression regularExpressionWithPattern:pattern options:0 error:&error];
    NSTextCheckingResult *match = [regex firstMatchInString:searchedString options:0 range:  NSMakeRange(0, [searchedString length])];
    if ([searchedString substringWithRange:[match rangeAtIndex:1]]) {
        return [searchedString substringWithRange:[match rangeAtIndex:1]];
    } else {
        return @"";
    }
}

结果数组:

+(NSArray *) regExArray:(NSString *) pattern withString: (NSString *) searchedString {
    NSMutableArray *results = [[NSMutableArray alloc] init];
    NSError *error;
    NSRegularExpression* regex = [NSRegularExpression regularExpressionWithPattern:pattern options:0 error:&error];
    NSArray* matches = [regex matchesInString:searchedString options:0 range: NSMakeRange(0, searchedString.length)];

    for (NSTextCheckingResult* match in matches) {
        NSMutableArray *result = [NSMutableArray array];
        NSRange matchRange = [match range];
        NSString *numString = [searchedString substringWithRange:matchRange];
        [result addObject:numString];

        for (int i=1;i < (int)match.numberOfRanges;i++) {
            NSRange range = [match rangeAtIndex:i];
            @try {
                NSString *numString = [searchedString substringWithRange:range];
                [result addObject:numString];
            }
            @catch (NSException *exception) {
                [result addObject:[NSNull null]];
            }
        }
       [results addObject:result];
   }
   return results;
}

I replaced RegexKitLite with there two methods.

String Results:

+(NSString*) regExString: (NSString *) pattern withString: (NSString *) searchedString {
    NSError  *error = nil;
    NSRegularExpression* regex = [NSRegularExpression regularExpressionWithPattern:pattern options:0 error:&error];
    NSTextCheckingResult *match = [regex firstMatchInString:searchedString options:0 range:  NSMakeRange(0, [searchedString length])];
    if ([searchedString substringWithRange:[match rangeAtIndex:1]]) {
        return [searchedString substringWithRange:[match rangeAtIndex:1]];
    } else {
        return @"";
    }
}

Array of Results:

+(NSArray *) regExArray:(NSString *) pattern withString: (NSString *) searchedString {
    NSMutableArray *results = [[NSMutableArray alloc] init];
    NSError *error;
    NSRegularExpression* regex = [NSRegularExpression regularExpressionWithPattern:pattern options:0 error:&error];
    NSArray* matches = [regex matchesInString:searchedString options:0 range: NSMakeRange(0, searchedString.length)];

    for (NSTextCheckingResult* match in matches) {
        NSMutableArray *result = [NSMutableArray array];
        NSRange matchRange = [match range];
        NSString *numString = [searchedString substringWithRange:matchRange];
        [result addObject:numString];

        for (int i=1;i < (int)match.numberOfRanges;i++) {
            NSRange range = [match rangeAtIndex:i];
            @try {
                NSString *numString = [searchedString substringWithRange:range];
                [result addObject:numString];
            }
            @catch (NSException *exception) {
                [result addObject:[NSNull null]];
            }
        }
       [results addObject:result];
   }
   return results;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文