mattt / transformerkit Goto Github PK
View Code? Open in Web Editor NEWA block-based API for NSValueTransformer, with a growing collection of useful examples.
License: MIT License
A block-based API for NSValueTransformer, with a growing collection of useful examples.
License: MIT License
How would you provide a transformer for an NSPoint or NSRect?
Hi Matt,
I saw that you added cryptographic transformers to the TransformerKit – would be super useful for something I'm working on. Is it possible to create a new release so that they're available or aren't they fit for public consumption yet?
Best regards
Jan
Not a big deal, but would be nice to be able to point at a 0.0.2 in our Podfile instead of :head or a specific commit.
The project doesn't compile for MacOS. The constant TKTIFFRepresentationImageTransformer is missing.
diff --git a/TransformerKit/TKImageTransformers.m b/TransformerKit/TKImageTransformers.m
index 24e6450..c4e41a2 100644
--- a/TransformerKit/TKImageTransformers.m
+++ b/TransformerKit/TKImageTransformers.m
@@ -81,7 +81,7 @@ static inline NSData * NSImageRepresentationWithType(NSImage *image, NSBitmapIma
return [[imageClass alloc] initWithData:value];
}];
- [NSValueTransformer registerValueTransformerWithName:TKTIFFRepresentationImageTransformer transformedValueClass:imageClass returningTransformedValueWithBlock:^id(id value) {
+ [NSValueTransformer registerValueTransformerWithName:TKTIFFRepresentationImageTransformerName transformedValueClass:imageClass returningTransformedValueWithBlock:^id(id value) {
return NSImageRepresentationWithType(value, NSTIFFFileType, nil);
} allowingReverseTransformationWithBlock:^id(id value) {
return [[imageClass alloc] initWithData:value];
In podspec says:
s.ios.deployment_target = '5.0'
But TransformerKit cannot be compiled for iOS because security framework is required for data transformers for some reason. Security framework on iOS lacks required functions.
Currently the image transformers always assume the image has a scale of 1, whereas I want them to have a scale of 2 on retina devices.
I’m currently working around this by overriding my Core Data accessor and creating a new UIImage
instance based on the result of the ‘primitive’ reader:
- (UIImage *)thumbnail;
{
UIImage *thumbnail = self.primitiveThumbnail;
thumbnail = [UIImage imageWithCGImage:thumbnail.CGImage
scale:[UIScreen mainScreen].scale
orientation:thumbnail.imageOrientation];
return thumbnail;
}
I wonder if you’ve already thought of a solution, I wasn’t able to quickly figure one out, without resorting to a global scale property on the transformer class.
On iOS 7 the following line...
...throws this error:
no class for metaclass 0xc3370e0
Both from the built in transformers' load methods as well as when I try to register one of my own transformers.
"2013-12-10T17:58:08.203Z" parses into local time due to a hardcoded offset at https://github.com/mattt/TransformerKit/blob/master/TransformerKit/TTTDateTransformers.m#L59
in theory, the decimal part could be arbitrarily long...
I have been using NSDateFormatter
to handle dates in this format: @"2014-02-10T14:57:46.025479"
.
I recently ran into the issue that sometimes milliseconds are omitted, like so: @"2014-02-28T17:46:24"
and decided to try and leverage TransformerKit to handle this.
While it appears to accept the varying ISO 8601 formats I need, I'm now having the issue that the results are shifted by 5 hours.
Perhaps I'm approaching this the wrong way or testing things incorrectly.
Below is an example. Thanks in advance.
Interface:
#import <Foundation/Foundation.h>
@interface MyClass : NSObject
+ (NSDate *)dateFromString:(NSString *)string;
+ (NSString *)stringFromDate:(NSDate *)date;
@end
Implementation:
#import "MyClass.h"
#import <TransformerKit/TransformerKit.h>
@implementation MyClass
+ (NSDate *)dateFromString:(NSString *)string
{
return [[self sharedDateTransformer] reverseTransformedValue:string];
}
+ (NSString *)stringFromDate:(NSDate *)date
{
return [[self sharedDateTransformer] transformedValue:date];
}
+ (NSValueTransformer *)sharedDateTransformer
{
static NSValueTransformer *_dateTransformer = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_dateTransformer = [NSValueTransformer valueTransformerForName:TTTISO8601DateTransformerName];
});
return _dateTransformer;
}
@end
Tests, which all fail:
#import "Specta.h"
#define EXP_SHORTHAND
#import "Expecta.h"
#import "MyClass.h"
SpecBegin(MyClass)
describe(@"MyClass", ^{
describe(@"formatting dates", ^{
context(@"converting dates to strings", ^{
it(@"should parse the date correctly", ^{
NSString *dateStringFixture = @"1970-01-01T00:00:00Z";
NSDate *dateFixture = [NSDate dateWithTimeIntervalSince1970:0];
NSString *dateString = [MyClass stringFromDate:dateFixture];
// expected: 1970-01-01T00:00:00Z, got: 1969-12-31T19:00:00-0500
expect(dateString).to.equal(dateStringFixture);
});
});
context(@"converting strings to dates", ^{
context(@"with milliseconds", ^{
it(@"should parse the date correctly", ^{
NSString *dateStringFixture = @"1970-01-01T00:00:00.000000";
NSDate *dateFixture = [NSDate dateWithTimeIntervalSince1970:0];
NSDate *date = [MyClass dateFromString:dateStringFixture];
// expected: 0, got: -18000
expect([dateFixture timeIntervalSinceDate:date]).to.equal(0);
});
});
context(@"without milliseconds", ^{
it(@"should parse the date correctly", ^{
NSString *dateStringFixture = @"1970-01-01T00:00:00";
NSDate *dateFixture = [NSDate dateWithTimeIntervalSince1970:0];
NSDate *date = [MyClass dateFromString:dateStringFixture];
// expected: 0, got: -18000
expect([dateFixture timeIntervalSinceDate:date]).to.equal(0);
});
});
});
});
});
SpecEnd
I have noticed that mktime
returns -1 for a date after 03:14:07 UTC on Tuesday, 19 January 2038 on iOS.
Perhaps you could add a GitHub milestone for 24 years' time?
App crashes running Xcode 5 DP5/DP6,
file: NSValueTransformer+TransformerKit.m
line: 81
allowsReverseTransformationMethod = class_getClassMethod(class, allowsReverseTransformationSelector);
output message:
EXC_BAD_INSTRUCTION: (code=EXC_I386_INVOP)
This might be a silly question, but why do you need a copy
call here?
https://github.com/mattt/TransformerKit/blob/master/TransformerKit/NSValueTransformer%2BTransformerKit.m#L68
It seems like imp_implementationWithBlock
already does it for you.
The dependency in the pod file:
ss.osx.frameworks = "CommonCrypto"
causes a linker failure on OS X 10.9 mavericks:
ld: framework not found CommonCrypto
clang: error: linker command failed with exit code 1 (use -v to see invocation)
removing that dependency from the pod spec seems to solve it. Also the example app doesn't need that framework on OS X, so I suspect it's an older-OS requirement? What's odd is that the libCommonCrypto is there in the 10.9 SDK.
I use TransformerKit in my iOS app with a Rails server:
[[NSValueTransformer valueTransformerForName:TTTISO8601DateTransformerName] transformedValue:[representation valueForKey:@"updated_at"]]
...but the above statement returns (null) on date strings e.g. 2012-09-14T11:00:00+02:00
.
Just upgraded from 0.3.1 and noticed that 0.4.0 no longer links properly on iOS due to the requirement for the CommonCrypto framework, which does not exist in iOS. Is there a way around this?
It appears that date transformers implementation contains an OSX only api (initWithDateFormat:allowNaturalLanguage:
) which breaks building on iOS.
Hi,
The 0.2.2 tag hasn't been created so CocoaPods breaks.
$ pod install
Analyzing dependencies
Downloading dependencies
Installing AFIncrementalStore (0.4.0)
Installing AFNetworking (1.2.1)
Installing InflectorKit (0.0.1)
Installing TransformerKit (0.2.2)
[!] Pod::Executable fetch origin tags/0.2.2 2>&1
fatal: Couldn't find remote ref tags/0.2.2
fatal: The remote end hung up unexpectedly
Regards,
Kevin
I use CocoaPods for managing libraries. TransformerKit was added to my workspace as another library (not sure which one) depends on it.
I have this instruction in my Podfile header.
platform :ios, '7.0'
When I tried to compile my application I was getting the linker error code -1 because linker could not find the CommonCrypto framework.
Either the TransformerKit was incorrectly added by the Pod manager or it is not for iOS development.
I have removed the reference from the TransformerKit pod target and I could compile the app.
I'm storing video in CoreData as NSData...how can I use TransformKit to transform this data back into video when I retrieve it?
The example outputs "TTTISO8601DateTransformerName (Timestamp): %2013-%39-%29%" for me.
From the looks of it, you are using strftime format patterns, while NSDateFormatter uses patterns from the Unicode Technical Standard.
The Cocoapod podspec references git tag '0.0.2', but no such tag exists.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.