Skip to content

Commit 1f5b96a

Browse files
committed
fix nullable issues
1 parent 53088f7 commit 1f5b96a

5 files changed

Lines changed: 18 additions & 12 deletions

File tree

Sources/SVGBezierPath.mm

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,24 @@ + (void)resetCache
2929
{
3030
NSArray<SVGBezierPath*> *paths = [self.class._svg_pathCache objectForKey:aURL];
3131
if (!paths) {
32-
paths = [self pathsFromSVGString:[NSString stringWithContentsOfURL:aURL
33-
usedEncoding:NULL
34-
error:NULL]];
35-
if (paths) {
36-
[self.class._svg_pathCache setObject:paths forKey:aURL];
32+
NSString * const svgString = [NSString stringWithContentsOfURL:aURL
33+
usedEncoding:NULL
34+
error:NULL];
35+
paths = [self pathsFromSVGString:svgString];
36+
if (!paths) {
37+
paths = @[];
3738
}
39+
[self.class._svg_pathCache setObject:paths forKey:aURL];
3840
}
39-
return [[NSArray alloc] initWithArray:paths copyItems:YES];
41+
NSArray<SVGBezierPath*> * const safePaths = paths ?: @[];
42+
return [[NSArray alloc] initWithArray:safePaths copyItems:YES];
4043
}
4144

4245
+ (NSArray<SVGBezierPath*> *)pathsFromSVGString:(NSString * const)svgString
4346
{
47+
if (svgString.length == 0) {
48+
return @[];
49+
}
4450
SVGAttributeSet *cgAttrs;
4551
NSArray * const pathRefs = CGPathsFromSVGString(svgString, &cgAttrs);
4652
NSMutableArray<SVGBezierPath*> * const paths = [NSMutableArray arrayWithCapacity:pathRefs.count];
@@ -67,7 +73,7 @@ - (instancetype)copyWithZone:(NSZone *)zone
6773
return copy;
6874
}
6975

70-
- (SVGBezierPath *)pathBySettingSVGAttributes:(NSDictionary *)attributes
76+
- (nullable SVGBezierPath *)pathBySettingSVGAttributes:(NSDictionary *)attributes
7177
{
7278
NSParameterAssert(attributes);
7379

Sources/SVGEngine.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ @interface SVGAttributeSet () {
442442
}
443443

444444
/// This parses a single isolated path. creating a cgpath from just a string formatted like the d element in a path
445-
CGPathRef CGPathFromSVGPathString(NSString *svgString) {
445+
CGPathRef CGPathFromSVGPathString(NSString *svgString) CF_RETURNS_RETAINED {
446446
CGPathRef const path = pathDefinitionParser(svgString).parse();
447447
if(!path) {
448448
NSLog(@"*** Error: Invalid path attribute");

Sources/include/SVGBezierPath.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ FOUNDATION_EXTERN void SVGDrawPathsWithBlock(NSArray<SVGBezierPath*> * const pat
6363
* @param attributes A dictionary of SVG attributes to set.
6464
*
6565
*/
66-
- (SVGBezierPath *)pathBySettingSVGAttributes:(NSDictionary *)attributes;
66+
- (nullable SVGBezierPath *)pathBySettingSVGAttributes:(NSDictionary *)attributes;
6767

6868
/*!
6969
* @brief The value of the SVG's viewBox attribute, expressed as a CGRect. If there is

Sources/include/SVGEngine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ NSArray *CGPathsFromSVGString(NSString *svgString, SVGAttributeSet **attributes)
3636
* @return A single CGPathRef object
3737
*
3838
*/
39-
CGPathRef CGPathFromSVGPathString(NSString *svgString);
39+
CGPathRef CGPathFromSVGPathString(NSString *svgString) CF_RETURNS_RETAINED;
4040

4141
/*!
4242
* @brief Returns SVG representing `paths`

Sources/include/SVGImageView.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ IB_DESIGNABLE
4242
* @discussion Setting this property solidly fills the shape formed by the SVG path with the given color.
4343
*
4444
*/
45-
@property(nonatomic, copy) IBInspectable PSVGColor *fillColor;
45+
@property(nonatomic, copy, nullable) IBInspectable PSVGColor *fillColor;
4646

4747

4848
/*!
4949
* @brief The color to stroke the path with.
5050
* @discussion Setting this property solidly colors the path generated by the SVG file.
5151
*
5252
*/
53-
@property(nonatomic, copy) IBInspectable PSVGColor *strokeColor;
53+
@property(nonatomic, copy, nullable) IBInspectable PSVGColor *strokeColor;
5454

5555

5656
/*!

0 commit comments

Comments
 (0)