krzysztofzablocki/PropertyMapper — dự án mã nguồn mở — đang có 1.1k sao GitHub. Property mapping for Objective-C iOS apps.
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
Stop repeating your data parsing code in iOS apps.
Data parsing is one of most common tasks we need to do in our apps, yet still majority of people do this parsing by hand, always repeating the same code for each class they need to map.
Usual parsing requires this steps:
make sure you translate NSNull to nil and not crash
gracefully handle optional params
do type conversions
data format validation
Why Property Mapper?
There are libraries helping with that like Mantle, RESTKit and many more… But I wanted something that's self contained, easy to change / remove and requires minimal amount of code.
I've created Property Mapper as part of working on Foldify, a simple self contained solution that allows you to specify mapping between data you receive and data representation you have in your application... with some additional features, like type boxing, validation.
I don't like passing around JSON so I write parsing on top of native objects like NSDictionary/NSArray.
If you get data as JSON just write a simple category that transforms JSON to native objects using NSJSONSerialization.
Quite obvious what it does but in case you are confused, it will translate videoURL string to contentURL NSURL object, it will also grab title from sub_object and assign it to uniqueID. It also handles NSNull.
Advanced usage
Let's now change our mind and decide that we want our type property to be typedef enumeration, it's quite easy with KZPropertyMapper, change type mapping to following and add following method:
@"videoType" : KZCall(videoTypeFromString:, type),
//! implemented on instance you are parsing
- (id)videoTypeFromString:(NSString *)type
{
if ([type isEqualToString:@"shortVideo"]) {
return @(VideoTypeShort);
}
return @(VideoTypeLong);
}
If you need property name being passed while using selectors, just pass two-argument selector in KZCall. Second argument will be property name passed as NSString.
@"video" : KZCall(objectFromDictionary:forPropertyName:, type),
//! implemented on instance you are parsing
- (id)objectFromDictionary:(NSDictionary *)dictionary forPropertyName:(NSString *)propertyName
{
Class objectClass = [self classForProperty:propertyName];
id object = [objectClass new];
[object updateFromDictionary:dictionary];
return object;
}
Done. KVC should also take care of escaping NSNumber into int if your property uses primitive type. Same approach will work for sub-object instances or anything that you can assign to property.
Validations
You can also validate your server data before mapping it:
krzysztofzablocki/PropertyMapper có bao nhiêu sao?
krzysztofzablocki/PropertyMapper có 1.1k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/krzysztofzablocki/PropertyMapper. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
krzysztofzablocki/PropertyMapper có tag gì không?
Bản đồng bộ chưa ghi nhận topic GitHub nào cho krzysztofzablocki/PropertyMapper. GitHub topics hiển thị ở thanh bên phải trang repo — đó là nơi đáng kiểm tra nhất.
krzysztofzablocki/PropertyMapper còn đang phát triển không?
Commit gần nhất trên krzysztofzablocki/PropertyMapper là 5.9 năm trước (theo timestamp GitHub). Repo có 79 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
krzysztofzablocki/PropertyMapper là gì?
krzysztofzablocki/PropertyMapper (krzysztofzablocki/PropertyMapper) là dự án Objective-C trên GitHub. Theo mô tả gốc: Property mapping for Objective-C iOS apps.
krzysztofzablocki/PropertyMapper viết bằng ngôn ngữ gì?
krzysztofzablocki/PropertyMapper chủ yếu viết bằng Objective-C. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Đọc đầy đủ README ở tab phía trên.
PropertyMapper có đáng để bạn bỏ thời gian?
ChatGPT, Claude và Perplexity đều đọc được trang này. Hỏi thử xem họ nghĩ gì về PropertyMapper.