Add Resource Loader for iOS
This commit is contained in:
25
doric-iOS/Pod/Classes/Resource/DoricBase64Resource.h
Normal file
25
doric-iOS/Pod/Classes/Resource/DoricBase64Resource.h
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright [2021] [Doric.Pub]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
//
|
||||
// Created by pengfei.zhou on 2021/10/25.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "DoricResource.h"
|
||||
|
||||
@interface DoricBase64Resource : DoricResource
|
||||
@end
|
35
doric-iOS/Pod/Classes/Resource/DoricBase64Resource.m
Normal file
35
doric-iOS/Pod/Classes/Resource/DoricBase64Resource.m
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright [2021] [Doric.Pub]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
//
|
||||
// Created by pengfei.zhou on 2021/10/25.
|
||||
//
|
||||
|
||||
#import "DoricBase64Resource.h"
|
||||
|
||||
|
||||
@implementation DoricBase64Resource
|
||||
- (DoricAsyncResult <NSData *> *)fetchRaw {
|
||||
DoricAsyncResult *result = [DoricAsyncResult new];
|
||||
NSString *inString = nil;
|
||||
if ([self.identifier hasPrefix:@"data:image"]) {
|
||||
inString = [self.identifier componentsSeparatedByString:@","].lastObject;
|
||||
}
|
||||
NSData *data = [[NSData alloc] initWithBase64EncodedString:inString
|
||||
options:NSDataBase64DecodingIgnoreUnknownCharacters];
|
||||
[result setupResult:data];
|
||||
return result;
|
||||
}
|
||||
@end
|
25
doric-iOS/Pod/Classes/Resource/DoricBase64ResourceLoader.h
Normal file
25
doric-iOS/Pod/Classes/Resource/DoricBase64ResourceLoader.h
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright [2021] [Doric.Pub]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
//
|
||||
// Created by pengfei.zhou on 2021/10/25.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "DoricResourceLoader.h"
|
||||
|
||||
@interface DoricBase64ResourceLoader : NSObject <DoricResourceLoader>
|
||||
@end
|
31
doric-iOS/Pod/Classes/Resource/DoricBase64ResourceLoader.m
Normal file
31
doric-iOS/Pod/Classes/Resource/DoricBase64ResourceLoader.m
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright [2021] [Doric.Pub]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
//
|
||||
// Created by pengfei.zhou on 2021/10/25.
|
||||
//
|
||||
|
||||
#import "DoricBase64ResourceLoader.h"
|
||||
#import "DoricBase64Resource.h"
|
||||
|
||||
@implementation DoricBase64ResourceLoader
|
||||
- (NSString *)resourceType {
|
||||
return @"base64";
|
||||
}
|
||||
|
||||
- (__kindof DoricResource *)load:(NSString *)identifier withContext:(DoricContext *)context {
|
||||
return [[DoricBase64Resource alloc] initWithContext:context identifier:identifier];
|
||||
}
|
||||
@end
|
26
doric-iOS/Pod/Classes/Resource/DoricBundleResource.h
Normal file
26
doric-iOS/Pod/Classes/Resource/DoricBundleResource.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright [2021] [Doric.Pub]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
//
|
||||
// Created by pengfei.zhou on 2021/10/25.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "DoricResource.h"
|
||||
#import "DoricContext.h"
|
||||
|
||||
@interface DoricBundleResource : DoricResource
|
||||
@property(nonatomic, strong) NSBundle *bundle;
|
||||
@end
|
31
doric-iOS/Pod/Classes/Resource/DoricBundleResource.m
Normal file
31
doric-iOS/Pod/Classes/Resource/DoricBundleResource.m
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright [2021] [Doric.Pub]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
//
|
||||
// Created by pengfei.zhou on 2021/10/25.
|
||||
//
|
||||
|
||||
#import "DoricBundleResource.h"
|
||||
|
||||
@implementation DoricBundleResource
|
||||
- (DoricAsyncResult <NSData *> *)fetchRaw {
|
||||
DoricAsyncResult *result = [DoricAsyncResult new];
|
||||
NSString *path = [self.bundle bundlePath];
|
||||
NSString *fullPath = [path stringByAppendingPathComponent:self.identifier];
|
||||
NSData *imgData = [[NSData alloc] initWithContentsOfFile:fullPath];
|
||||
[result setupResult:imgData];
|
||||
return result;
|
||||
}
|
||||
@end
|
26
doric-iOS/Pod/Classes/Resource/DoricBundleResourceLoader.h
Normal file
26
doric-iOS/Pod/Classes/Resource/DoricBundleResourceLoader.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright [2021] [Doric.Pub]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
//
|
||||
// Created by pengfei.zhou on 2021/10/25.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "DoricResourceLoader.h"
|
||||
|
||||
@interface DoricBundleResourceLoader : NSObject <DoricResourceLoader>
|
||||
- (instancetype)initWithResourceType:(NSString *)resourceType bundle:(NSBundle *)bundle;
|
||||
@end
|
45
doric-iOS/Pod/Classes/Resource/DoricBundleResourceLoader.m
Normal file
45
doric-iOS/Pod/Classes/Resource/DoricBundleResourceLoader.m
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright [2021] [Doric.Pub]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
//
|
||||
// Created by pengfei.zhou on 2021/10/25.
|
||||
//
|
||||
|
||||
#import <DoricExtensions.h>
|
||||
#import "DoricBundleResourceLoader.h"
|
||||
#import "DoricBundleResource.h"
|
||||
|
||||
@interface DoricBundleResourceLoader ()
|
||||
@property(nonatomic, strong) NSBundle *bundle;
|
||||
@property(nonatomic, copy) NSString *resourceType;
|
||||
@end
|
||||
|
||||
@implementation DoricBundleResourceLoader
|
||||
- (instancetype)initWithResourceType:(NSString *)resourceType bundle:(NSBundle *)bundle {
|
||||
if (self = [super init]) {
|
||||
_resourceType = resourceType;
|
||||
_bundle = bundle;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (__kindof DoricResource *)load:(NSString *)identifier withContext:(DoricContext *)context {
|
||||
return [[[DoricBundleResource alloc] initWithContext:context identifier:identifier]
|
||||
also:^(DoricBundleResource *it) {
|
||||
it.bundle = self.bundle;
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
24
doric-iOS/Pod/Classes/Resource/DoricLocalResource.h
Normal file
24
doric-iOS/Pod/Classes/Resource/DoricLocalResource.h
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright [2021] [Doric.Pub]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
//
|
||||
// Created by pengfei.zhou on 2021/10/25.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "DoricResource.h"
|
||||
|
||||
@interface DoricLocalResource : DoricResource
|
||||
@end
|
30
doric-iOS/Pod/Classes/Resource/DoricLocalResource.m
Normal file
30
doric-iOS/Pod/Classes/Resource/DoricLocalResource.m
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright [2021] [Doric.Pub]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
//
|
||||
// Created by pengfei.zhou on 2021/10/25.
|
||||
//
|
||||
|
||||
#import "DoricLocalResource.h"
|
||||
|
||||
|
||||
@implementation DoricLocalResource
|
||||
- (DoricAsyncResult <NSData *> *)fetchRaw {
|
||||
DoricAsyncResult *result = [DoricAsyncResult new];
|
||||
NSData *imgData = [[NSData alloc] initWithContentsOfFile:self.identifier];
|
||||
[result setupResult:imgData];
|
||||
return result;
|
||||
}
|
||||
@end
|
24
doric-iOS/Pod/Classes/Resource/DoricLocalResourceLoader.h
Normal file
24
doric-iOS/Pod/Classes/Resource/DoricLocalResourceLoader.h
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright [2021] [Doric.Pub]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
//
|
||||
// Created by pengfei.zhou on 2021/10/25.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "DoricResourceLoader.h"
|
||||
|
||||
@interface DoricLocalResourceLoader : NSObject <DoricResourceLoader>
|
||||
@end
|
32
doric-iOS/Pod/Classes/Resource/DoricLocalResourceLoader.m
Normal file
32
doric-iOS/Pod/Classes/Resource/DoricLocalResourceLoader.m
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright [2021] [Doric.Pub]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
//
|
||||
// Created by pengfei.zhou on 2021/10/25.
|
||||
//
|
||||
|
||||
#import "DoricLocalResourceLoader.h"
|
||||
#import "DoricLocalResource.h"
|
||||
|
||||
@implementation DoricLocalResourceLoader
|
||||
- (NSString *)resourceType {
|
||||
return @"local";
|
||||
}
|
||||
|
||||
- (__kindof DoricResource *)load:(NSString *)identifier withContext:(DoricContext *)context {
|
||||
return [[DoricLocalResource alloc] initWithContext:context identifier:identifier];
|
||||
}
|
||||
|
||||
@end
|
24
doric-iOS/Pod/Classes/Resource/DoricRemoteResource.h
Normal file
24
doric-iOS/Pod/Classes/Resource/DoricRemoteResource.h
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright [2021] [Doric.Pub]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
//
|
||||
// Created by pengfei.zhou on 2021/10/25.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "DoricResource.h"
|
||||
|
||||
@interface DoricRemoteResource : DoricResource
|
||||
@end
|
33
doric-iOS/Pod/Classes/Resource/DoricRemoteResource.m
Normal file
33
doric-iOS/Pod/Classes/Resource/DoricRemoteResource.m
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright [2021] [Doric.Pub]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
//
|
||||
// Created by pengfei.zhou on 2021/10/25.
|
||||
//
|
||||
|
||||
#import "DoricRemoteResource.h"
|
||||
|
||||
|
||||
@implementation DoricRemoteResource
|
||||
- (DoricAsyncResult <NSData *> *)fetchRaw {
|
||||
DoricAsyncResult *result = [DoricAsyncResult new];
|
||||
NSURL *url = [NSURL URLWithString:self.identifier];
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
NSData *urlData = [NSData dataWithContentsOfURL:url];
|
||||
[result setupResult:urlData];
|
||||
});
|
||||
return result;
|
||||
}
|
||||
@end
|
25
doric-iOS/Pod/Classes/Resource/DoricRemoteResourceLoader.h
Normal file
25
doric-iOS/Pod/Classes/Resource/DoricRemoteResourceLoader.h
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright [2021] [Doric.Pub]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
//
|
||||
// Created by pengfei.zhou on 2021/10/25.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "DoricResourceLoader.h"
|
||||
|
||||
@interface DoricRemoteResourceLoader : NSObject <DoricResourceLoader>
|
||||
@end
|
31
doric-iOS/Pod/Classes/Resource/DoricRemoteResourceLoader.m
Normal file
31
doric-iOS/Pod/Classes/Resource/DoricRemoteResourceLoader.m
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright [2021] [Doric.Pub]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
//
|
||||
// Created by pengfei.zhou on 2021/10/25.
|
||||
//
|
||||
|
||||
#import "DoricRemoteResourceLoader.h"
|
||||
#import "DoricRemoteResource.h"
|
||||
|
||||
@implementation DoricRemoteResourceLoader
|
||||
- (NSString *)resourceType {
|
||||
return @"remote";
|
||||
}
|
||||
|
||||
- (__kindof DoricResource *)load:(NSString *)identifier withContext:(DoricContext *)context {
|
||||
return [[DoricRemoteResource alloc] initWithContext:context identifier:identifier];
|
||||
}
|
||||
@end
|
32
doric-iOS/Pod/Classes/Resource/DoricResource.h
Normal file
32
doric-iOS/Pod/Classes/Resource/DoricResource.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright [2021] [Doric.Pub]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
//
|
||||
// Created by pengfei.zhou on 2021/10/22.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "DoricAsyncResult.h"
|
||||
|
||||
@class DoricContext;
|
||||
|
||||
@interface DoricResource : NSObject
|
||||
@property(nonatomic, weak) DoricContext *context;
|
||||
@property(nonatomic, copy) NSString *identifier;
|
||||
|
||||
- (instancetype)initWithContext:(DoricContext *)context identifier:(NSString *)identifier;
|
||||
|
||||
- (DoricAsyncResult <NSData *> *)fetchRaw;
|
||||
@end
|
33
doric-iOS/Pod/Classes/Resource/DoricResource.m
Normal file
33
doric-iOS/Pod/Classes/Resource/DoricResource.m
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright [2021] [Doric.Pub]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
//
|
||||
// Created by pengfei.zhou on 2021/10/22.
|
||||
//
|
||||
|
||||
#import "DoricResource.h"
|
||||
|
||||
@implementation DoricResource
|
||||
- (instancetype)initWithContext:(DoricContext *)context identifier:(NSString *)identifier {
|
||||
if (self = [super init]) {
|
||||
_context = context;
|
||||
_identifier = identifier;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
- (DoricAsyncResult<NSData *> *)fetchRaw {
|
||||
return nil;
|
||||
}
|
||||
@end
|
27
doric-iOS/Pod/Classes/Resource/DoricResourceLoader.h
Normal file
27
doric-iOS/Pod/Classes/Resource/DoricResourceLoader.h
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright [2021] [Doric.Pub]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
//
|
||||
// Created by pengfei.zhou on 2021/10/22.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "DoricResource.h"
|
||||
|
||||
@protocol DoricResourceLoader
|
||||
@property(nonatomic, readonly) NSString *resourceType;
|
||||
|
||||
- (__kindof DoricResource *)load:(NSString *)identifier withContext:(DoricContext *)context;
|
||||
@end
|
31
doric-iOS/Pod/Classes/Resource/DoricResourceLoaderManager.h
Normal file
31
doric-iOS/Pod/Classes/Resource/DoricResourceLoaderManager.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright [2021] [Doric.Pub]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
//
|
||||
// Created by pengfei.zhou on 2021/10/22.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "DoricResourceLoader.h"
|
||||
|
||||
@interface DoricResourceLoaderManager : NSObject
|
||||
- (void)registerLoader:(id <DoricResourceLoader>)loader;
|
||||
|
||||
- (void)unRegisterLoader:(id <DoricResourceLoader>)loader;
|
||||
|
||||
- (__kindof DoricResource *)load:(NSString *)identifier
|
||||
withResourceType:(NSString *)resourceType
|
||||
withContext:(DoricContext *)context;
|
||||
@end
|
49
doric-iOS/Pod/Classes/Resource/DoricResourceLoaderManager.m
Normal file
49
doric-iOS/Pod/Classes/Resource/DoricResourceLoaderManager.m
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright [2021] [Doric.Pub]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
//
|
||||
// Created by pengfei.zhou on 2021/10/22.
|
||||
//
|
||||
|
||||
#import "DoricResourceLoaderManager.h"
|
||||
|
||||
@interface DoricResourceLoaderManager ()
|
||||
@property(nonatomic, strong) NSMutableDictionary <NSString *, id <DoricResourceLoader>> *loaders;
|
||||
@end
|
||||
|
||||
@implementation DoricResourceLoaderManager
|
||||
- (instancetype)init {
|
||||
if (self = [super init]) {
|
||||
_loaders = [NSMutableDictionary new];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)registerLoader:(id <DoricResourceLoader>)loader {
|
||||
self.loaders[loader.resourceType] = loader;
|
||||
}
|
||||
|
||||
- (void)unRegisterLoader:(id <DoricResourceLoader>)loader {
|
||||
[self.loaders removeObjectForKey:loader.resourceType];
|
||||
}
|
||||
|
||||
- (__kindof DoricResource *)load:(NSString *)identifier
|
||||
withResourceType:(NSString *)resourceType
|
||||
withContext:(DoricContext *)context {
|
||||
id <DoricResourceLoader> loader = self.loaders[resourceType];
|
||||
return [loader load:identifier withContext:context];
|
||||
}
|
||||
|
||||
@end
|
Reference in New Issue
Block a user