मेरे पास निम्न कोड है। मुझे कभी-कभी एक SIGSEGV मिलता है। मुझे एहसास है कि मुझे ब्लॉक का उपयोग कर स्मृति प्रबंधन के बारे में कुछ याद आ रहा है। क्या प्रतिस्थापित यूआरएल पास करना सुरक्षित है, जो इस ब्लॉक के लिए स्वत: बंद है? आवृत्ति चर स्वरूपित पाठ को संशोधित करने के बारे में क्या?ब्लॉक का उपयोग कर SIGSEGV का कारण क्या है?
NSMutableSet* replacedUrls = [[[NSMutableSet alloc] init] autorelease];
NSError *error = nil;
NSDataDetector *detector = [NSDataDetector dataDetectorWithTypes:
(NSTextCheckingTypeLink | NSTextCheckingTypePhoneNumber)
error:&error];
if (error) {
return;
}
[detector enumerateMatchesInString:self.formattedText
options:0
range:NSMakeRange(0, [self.formattedText length])
usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {
@try {
if (result.resultType == NSTextCheckingTypePhoneNumber) {
if (!result.phoneNumber) {
// not sure if this is possible
return;
}
self.formattedText = [self.formattedText stringByReplacingOccurrencesOfString:result.phoneNumber
withString:[NSString stringWithFormat:@"<a href=\"tel://%@\">%@</a>", result.phoneNumber, result.phoneNumber]];
}
else if (result.resultType == NSTextCheckingTypeLink) {
if (!result.URL) {
// not sure if this is possible
return;
}
NSString* fullUrl = [result.URL absoluteString];
if (!fullUrl) {
return;
}
if ([replacedUrls containsObject:fullUrl]) {
return;
}
// not sure if this is possible
if ([result.URL host] && [result.URL path]) {
NSString* urlWithNoScheme = [NSString stringWithFormat:@"%@%@", [result.URL host], [result.URL path]];
// replace all http://www.google.com to www.google.com
self.formattedText = [self.formattedText stringByReplacingOccurrencesOfString:fullUrl
withString:urlWithNoScheme];
// replace all www.google.com with http://www.google.com
NSString* replaceText = [NSString stringWithFormat:@"<a href=\"%@\">%@</a>", fullUrl, fullUrl];
self.formattedText = [self.formattedText stringByReplacingOccurrencesOfString:urlWithNoScheme
withString:replaceText];
[replacedUrls addObject:fullUrl];
}
}
}
@catch (NSException* ignore) {
// ignore any issues
}
}];
कुछ पढ़ने के बाद, मैं निश्चित रूप से देख रहा हूं कि मैं एक बरकरार चक्र बना रहा हूं क्योंकि स्वयं को बनाए रखा जाएगा। फिर भी यह सुनिश्चित नहीं है कि यह वास्तविक समस्या कैसे बनाएगा, हालांकि। – tjg184
डोडेस्टेस्ट लाइन 'अगर (त्रुटि) {वापसी;} है, लेकिन मुझे यकीन नहीं है कि यह आपकी समस्या का कारण बनता है (यदि आप इस बिंदु पर वापस आते हैं तो आपका कोड शानदार ढंग से ठीक हो जाता है?)। स्वयं को बनाए रखना जरूरी नहीं है कि एक बनाए रखने वाले चक्र का कारण बनता है, और एक बनाए रखने वाला चक्र SIGSEGV का कारण नहीं बनता है; – hooleyhoop
हाँ, वह रेखा अजीब है। मुझे यकीन भी नहीं है कि यह जरूरी है। मुझे लगता है कि मैंने इसे एक सैनिटी चेक के रूप में जोड़ा है। इससे पहले कि हम उस लाइन को जोड़ लें, उसे एसआईजीएसईजीवी मिल रही थी। उनमें से अधिकतर अगर कथन जोड़े गए थे क्योंकि क्रैश रिपोर्ट ने सामान्य ब्लॉक की ओर इशारा किया था, न कि एक विशिष्ट रेखा। इस मुद्दे को ट्रैक करने के लिए परेशान करने की तरह। क्या इसमें स्वरूपित पाठ को संशोधित करना सुरक्षित है? – tjg184