Git Product home page Git Product logo

rzdatabinding's People

Contributors

chrisballinger avatar jvisenti avatar kingofbrian avatar zeveisenberg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rzdatabinding's Issues

Clearer documentation for binding

The documentation for bindings (both in the readme and in the header docs) is a little hard to follow, because it's hard to keep track of various receivers and keys and bindings in the abstract. A concrete example would be helpful.

Build on Travis

Since you have unit tests, pull requests should be built on Travis to ensure that tests and static analysis pass. I recommend editing the default Travis script to run on iPhone 4s and iPhone 6 to catch 32/64 issues.

callImmediately crashes if used with unresolvable key path

I'm subclassing NSLayoutConstraint, and I want to know when the firstItem’s font changes. So I set it up like this:

- (void)configureObservers
{
    NSString *firstItemFontKeyPath = [@[
                                        NSStringFromSelector(@selector(firstItem)),
                                        NSStringFromSelector(@selector(font)),
                                        ] componentsJoinedByString:@"."];

    [self rz_addTarget:self
                action:@selector(updateConstant)
      forKeyPathChange:firstItemFontKeyPath
       callImmediately:YES];
}

Notice that I'm building the key path myself. This is because firstItem is of type id, and depending on what type of view it is, it may not have a font property.

If I run this code as-is, I get a crash:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<DashedHairlineView 0x7fdaa492cbc0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key font.'

If I delete the callImmediately parameter and call the handler myself on the next line, it works fine, and subsequent changes successfully trigger the callback.

Misleading typo in documentation for `RZDB_AUTOMATIC_CLEANUP`

Misleading typo in documentation for RZDB_AUTOMATIC_CLEANUP

The comment preceding the definition of RZDB_AUTOMATIC_CLEANUP reads:
If enabled, it is safe to observe or bind to weak references, and there is need to call rz_removeTarget or rz_unbindKey before targets or observed objects are deallocated.

Expected: Text should read "… there is no need …"
Actual: Text reads "there is need"

Full comment below:

 *  Set this to 1 (recommended) to enable automatic cleanup of observers on object deallocation.
 *  If enabled, it is safe to observe or bind to weak references, and there is need to call rz_removeTarget
 *  or rz_unbindKey before targets or observed objects are deallocated. To achieve automatic cleanup,
 *  RZDB swizzles the dealloc method to ensure observers are properly invalidated. There are other ways of implementing similar
 *  behavior, but this has been found to be both the safest and most reliable in production.
 *
 *  If set to 0 (not recommended), objects MUST remove themselves as targets and unbind their keys from any observed objects before being deallocated.
 *  Failure to do so will result in crashes (just like standard KVO). Additionally, you should not add a target to or bind keys to 
 *  objects without first establishing a strong reference. Otherwise, the foreign object might be deallocated before the observer, causing in a crash.
 *  If you choose to disable global automatic cleanup by setting this to 0, you must cleanup observers manually.
 *
 *  @see rz_cleanupObservers
 */

Helper macro for `keyPathsForValuesAffecting`

I find myself writing this a lot:

+ (NSSet *)keyPathsForValuesAffectingMyKeyPath
{
    return [NSSet setWithObjects:
            RZDB_KP(ClassName, self.key.path.1),
            RZDB_KP(ClassNmae, self.key.path.2),
            nil];
}

It would be awesome to have a macro that would:

RZDB_KEYPATHS_AFFECTING( MyKeyPath, ClassName, self.key.path.1, self.key.path.2)

Binding UITextField.text to Model.property

I try make the binding like this:

[self.company rz_bindKey:RZDB_KP(MMCompanyItem, contractName) toKeyPath:RZDB_KP(UITextField, text) ofObject:self.txContractName];

Doesn't works when change the value of UITextField, the property contractName on the object self.company doesn't reflects the change.

Am I doing something wrong?

Crashes on [RZDBObserver invalidate]

Hi, thank you for a great library, I really enjoy using it.

Recently, I've been receiving tens of crashes on [RZDBObserver invalidate] with an exception *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 189 beyond bounds [0 .. 188]' (this reason keeps repeating, but with different numbers like index 605 beyond bounds [0 .. 604]'.

Last Exception Backtrace:
0   CoreFoundation                       0x27a29c1f 0x27924000 + 1072159
1   libobjc.A.dylib                      0x35210c8b 0x3520a000 + 27787
2   CoreFoundation                       0x2793e839 0x27924000 + 108601
3   CoreFoundation                       0x27956b77 0x27924000 + 207735
4   RZDataBinding                        0x00fbd0fd -[RZDBObserver invalidate] (NSObject+RZDataBinding.m:391)
5   CoreFoundation                       0x279512df 0x27924000 + 185055
6   CoreFoundation                       0x27951209 0x27924000 + 184841
7   RZDataBinding                        0x00fbc9ad -[NSObject(RZDataBinding_Private) rz_cleanupObservers] (NSObject+RZDataBinding.m:308)
8   RZDataBinding                        0x00fbd799 __rz_swizzleDeallocIfNeeded_block_invoke_2 (NSObject+RZDataBinding.m:496)
9   libobjc.A.dylib                      0x3522ad5f 0x3520a000 + 134495
10  CoreFoundation                       0x27930e5d 0x27924000 + 52829
11  CoreFoundation                       0x279444e7 0x27924000 + 132327
12  libobjc.A.dylib                      0x3522ad5f 0x3520a000 + 134495

Do you have any idea where the problem could be?

Thanks!

Blocks support needed

Thank you for your great work!
Is it possible to convert action-target usage to blocks?

Swizzling dealloc is, well, terrifying

I am super stoked about this library. Data binding is something that is sorely missing from Cocoa and I am thrilled that RZ is putting this out there.

That said, swizzling dealloc sort of scares me. I see why it's being done, and it's good that you made it optional via the preprocessor, but at the same time I think it should be strongly discouraged for production apps.

Is there any other way to clean up observers besides subclassing or swizzling dealloc for all NSObjects?

Colons in Readme code samples should be aligned

The let side of the parameters are all aligned, but if you let Xcode auto-indent the code, colons on subsequent lines will be aligned instead. I recommend using this style for the readme because it is more familiar.

rz_addTarget:action: should be smart about KVO options

Current rz_addTarget:action: always uses at least NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld. These options should only be used if the action's method signature has a changeDict parameter. In the case that the action takes no arguments, kNilOptions should be used to avoid this overhead.

Migrating to 2.0

I was using version 1.2, and just updated to 2.0. I noticed it included a breaking change, and won't compile now, but can't find any documentation on it.

The code I had looked like this

[self rz_addTarget:self action:@selector(reloadAppIntegrations) forKeyPathChange:RZDB_KP(self.tableDataSource.appIntegrations) callImmediately:NO];

It looks like the RZDB_KP was removed, so I'm wondering how do I pass in a keyPath (preferably not as a string?) to create the binding on.

Thanks a lot!

Demo can not run in X-code

Thanks for your contribution.I have a question.Do you delete some profile? I can not run it in my X-code

rz_addTarget:action:forKeyPathChange: is considered an unrecognised selector

I'm trying to use the RZDataBinding library to observe changes in a property of a NSObject. I have the following code:

[self rz_addTarget:self action:@selector(senderDidChange:) forKeyPathChange:RZDB_KP_SELF(sender)];

It compiles, but when it tries to run it throws an error of unrecognised selector being sent to the instance. The selfobject is a direct subclass of NSObject.

Any idea what is going wrong here?

Add RZDB_KP_PROTOCOL

I'd like to add this:

#if DEBUG
#define RZDB_KP_PROTOCOL(ProtocolName, keypath) ({\
id<ProtocolName> _rzdb_keypath_obj; \
__unused __typeof(_rzdb_keypath_obj.keypath) _rzdb_keypath_prop; \
@#keypath; \
})
#else
#define RZDB_KP_PROTOCOL(ProtocolName, keypath) (@#keypath)
#endif

I don't know if this belongs in RZDB directly, but it came up recently in a project that's using RZDB anyway, so I already have access to the other key path macros:

+ (void)abc_importResponse:(id)responseObject inContext:(NSManagedObjectContext *)context
{
    [self rzi_objectsFromArray:responseObject inContext:context];
    if ([self conformsToProtocol:@protocol(ABCDeletableStoredObject)]) {
        [self rzv_deleteAllWhere:[NSPredicate predicateWithFormat:@"%K == %@", RZDB_KP_PROTOCOL(ABCDeletableStoredObject, flaggedForDelete), @(YES)] inContext:context];
    }
}

__unused warning

Recommend using these warnings for the sample project:

-Weverything -Wno-objc-missing-property-synthesis -Wno-objc-property-synthesis -Wno-direct-ivar-access -Wno-assign-enum -Wno-float-equal -Wno-sign-compare -Wno-switch-enum -Wno-gnu -Wnewline-eof

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.