Commits

José Manuel Sánchez Peñarroja  committed 35a9145

Fixed some issues. Added option to remove all behaviors, all aspects and such

  • Participants
  • Parent commits c4dc00b

Comments (0)

Files changed (15)

File Example/Example.xcworkspace/xcuserdata/josanchez.xcuserdatad/UserInterfaceState.xcuserstate

Binary file modified.

File Example/Example.xcworkspace/xcuserdata/josanchez.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

             endingColumnNumber = "9223372036854775807"
             startingLineNumber = "73"
             endingLineNumber = "73"
-            landmarkName = "-setLoaderView:"
-            landmarkType = "5">
+            landmarkName = "@implementation BMFViewController"
+            landmarkType = "3">
          </BreakpointContent>
       </BreakpointProxy>
       <BreakpointProxy
             endingColumnNumber = "9223372036854775807"
             startingLineNumber = "86"
             endingLineNumber = "86"
-            landmarkName = "-addLoaderView"
+            landmarkName = "-setLoaderView:"
             landmarkType = "5">
          </BreakpointContent>
       </BreakpointProxy>
             endingColumnNumber = "9223372036854775807"
             startingLineNumber = "44"
             endingLineNumber = "44"
-            landmarkName = "-initWithCoder:"
-            landmarkType = "5">
+            landmarkName = "@implementation BMFViewController"
+            landmarkType = "3">
          </BreakpointContent>
       </BreakpointProxy>
       <BreakpointProxy
             endingColumnNumber = "9223372036854775807"
             startingLineNumber = "35"
             endingLineNumber = "35"
-            landmarkName = "-initWithNibName:bundle:"
+            landmarkName = "-initWithParameters:nibName:"
             landmarkType = "5">
          </BreakpointContent>
       </BreakpointProxy>
             endingColumnNumber = "9223372036854775807"
             startingLineNumber = "27"
             endingLineNumber = "27"
-            landmarkName = "-initWithParameters:nibName:"
+            landmarkName = "-init"
             landmarkType = "5">
          </BreakpointContent>
       </BreakpointProxy>
             endingColumnNumber = "9223372036854775807"
             startingLineNumber = "19"
             endingLineNumber = "19"
-            landmarkName = "-init"
-            landmarkType = "5">
+            landmarkName = "@implementation BMFViewController"
+            landmarkType = "3">
          </BreakpointContent>
       </BreakpointProxy>
       <BreakpointProxy
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "../bmf/shared/stats/BMFAverageStats.m"
-            timestampString = "423066312.076342"
+            timestampString = "423661641.770185"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "102"
-            endingLineNumber = "102"
+            startingLineNumber = "112"
+            endingLineNumber = "112"
             landmarkName = "-removeAllValuesForKey:"
             landmarkType = "5">
          </BreakpointContent>
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "../bmf/shared/stats/BMFAverageStats.m"
-            timestampString = "423066313.700975"
+            timestampString = "423661641.770185"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "105"
-            endingLineNumber = "105"
+            startingLineNumber = "115"
+            endingLineNumber = "115"
             landmarkName = "@implementation BMFAverageStats"
             landmarkType = "3">
          </BreakpointContent>
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "../bmf/shared/stats/BMFAverageStats.m"
-            timestampString = "423068018.805176"
+            timestampString = "423661641.770185"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "112"
-            endingLineNumber = "112"
+            startingLineNumber = "122"
+            endingLineNumber = "122"
             landmarkName = "-addValue:forKey:"
             landmarkType = "5">
          </BreakpointContent>
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "../bmf/shared/stats/BMFAverageStats.m"
-            timestampString = "423067235.141878"
+            timestampString = "423661641.770185"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "101"
-            endingLineNumber = "101"
+            startingLineNumber = "111"
+            endingLineNumber = "111"
             landmarkName = "-removeAllValuesForKey:"
             landmarkType = "5">
          </BreakpointContent>
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "../bmf/shared/stats/BMFAverageStats.m"
-            timestampString = "423068018.805176"
+            timestampString = "423661641.770185"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "108"
-            endingLineNumber = "108"
+            startingLineNumber = "118"
+            endingLineNumber = "118"
             landmarkName = "-addValue:forKey:"
             landmarkType = "5">
          </BreakpointContent>
             ignoreCount = "0"
             continueAfterRunningActions = "No"
             filePath = "../bmf/shared/stats/BMFAverageStats.m"
-            timestampString = "423067682.154555"
+            timestampString = "423661641.770185"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "93"
-            endingLineNumber = "93"
+            startingLineNumber = "103"
+            endingLineNumber = "103"
             landmarkName = "-setDefaultValue:forKey:"
             landmarkType = "5">
          </BreakpointContent>
             landmarkType = "6">
          </BreakpointContent>
       </BreakpointProxy>
-      <BreakpointProxy
-         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
-         <BreakpointContent
-            shouldBeEnabled = "No"
-            ignoreCount = "0"
-            continueAfterRunningActions = "No"
-            filePath = "../bmf/shared/values/BMFAverageValue.m"
-            timestampString = "423069146.458782"
-            startingColumnNumber = "9223372036854775807"
-            endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "55"
-            endingLineNumber = "55"
-            landmarkName = "-addValue:"
-            landmarkType = "5">
-         </BreakpointContent>
-      </BreakpointProxy>
    </Breakpoints>
 </Bucket>

File bmf/ios/view controllers/BMFMatrixFlowLayoutDelegate.m

     self = [super init];
     if (self) {
 		self.numColumns = [[BMFDeviceValue alloc] initWithDefaultValue:@2];
-		[self.numColumns setValue:@3 forFamily:BMFDeviceFamilyIPhone orientationAxis:BMFDeviceOrientationAxisLandscape];
-		[self.numColumns setValue:@3 forFamily:BMFDeviceFamilyIPad];
-		[self.numColumns setValue:@4 forFamily:BMFDeviceFamilyIPad orientationAxis:BMFDeviceOrientationAxisLandscape];
+//		[self.numColumns setValue:@3 forFamily:BMFDeviceFamilyIPhone orientationAxis:BMFDeviceOrientationAxisLandscape];
+//		[self.numColumns setValue:@3 forFamily:BMFDeviceFamilyIPad];
+//		[self.numColumns setValue:@4 forFamily:BMFDeviceFamilyIPad orientationAxis:BMFDeviceOrientationAxisLandscape];
 		
 //        self.numColumns = 2;
 //		self.numColumnsIPad = 3;
 		self.verticalMode = BMFMatrixFlowLayoutDelegateVerticalModeRows;
 		
 		self.numRows = [[BMFDeviceValue alloc] initWithDefaultValue:@4];
-		[self.numRows setValue:@2 forFamily:BMFDeviceFamilyIPhone orientationAxis:BMFDeviceOrientationAxisLandscape];
-		[self.numRows setValue:@6 forFamily:BMFDeviceFamilyIPad];
-		[self.numRows setValue:@4 forFamily:BMFDeviceFamilyIPad orientationAxis:BMFDeviceOrientationAxisLandscape];
+//		[self.numRows setValue:@2 forFamily:BMFDeviceFamilyIPhone orientationAxis:BMFDeviceOrientationAxisLandscape];
+//		[self.numRows setValue:@6 forFamily:BMFDeviceFamilyIPad];
+//		[self.numRows setValue:@4 forFamily:BMFDeviceFamilyIPad orientationAxis:BMFDeviceOrientationAxisLandscape];
 
 		self.itemHeight = [[BMFDeviceValue alloc] initWithDefaultValue:@120];
-		[self.itemHeight setValue:@70 forFamily:BMFDeviceFamilyIPhone orientationAxis:BMFDeviceOrientationAxisLandscape];
-		[self.itemHeight setValue:@150 forFamily:BMFDeviceFamilyIPad];
-		[self.itemHeight setValue:@120 forFamily:BMFDeviceFamilyIPad orientationAxis:BMFDeviceOrientationAxisLandscape];
+//		[self.itemHeight setValue:@70 forFamily:BMFDeviceFamilyIPhone orientationAxis:BMFDeviceOrientationAxisLandscape];
+//		[self.itemHeight setValue:@150 forFamily:BMFDeviceFamilyIPad];
+//		[self.itemHeight setValue:@120 forFamily:BMFDeviceFamilyIPad orientationAxis:BMFDeviceOrientationAxisLandscape];
 
 		
 		// self.numRows = 4;

File bmf/ios/view controllers/BMFViewController.h

 
 - (void) addBehavior: (id<BMFViewControllerBehaviorProtocol>) behavior;
 - (void) removeBehavior: (id<BMFViewControllerBehaviorProtocol>) behavior;
+- (void) removeAllBehaviors;
 
 /// Allows to know the navigation direction when appearing.
 @property (nonatomic, assign) enum BMFViewControllerNavigationDirection navigationDirection;

File bmf/ios/view controllers/BMFViewController.m

 	[self BMF_removeAspect:behavior];
 }
 
+- (void) removeAllBehaviors {
+	[self BMF_removeAllAspects];
+}
+
 #pragma mark View life cycle
 
 - (void)viewDidLoad {
     [super viewDidLoad];
 	
-	if (self.didLoadBlock) self.didLoadBlock(self);
 	UIView *view = [UIView BMF_cast:self.loaderView];
 	if (!view.superview) [self addLoaderView];
 	
 	if ([self.BMF_proxy respondsToSelector:@selector(viewDidLoad)]) [self.BMF_proxy viewDidLoad];
+	
+	if (self.didLoadBlock) self.didLoadBlock(self);
 }
 
 - (void) viewWillAppear:(BOOL)animated {

File bmf/shared/base/BMFArrayProxy.h

 
 - (void) addDestinationObject:(id) object;
 - (void) removeDestinationObject:(id) object;
+- (void) removeAllDestinationObjects;
 
 - (instancetype)init;
 + (instancetype)new;

File bmf/shared/base/BMFArrayProxy.m

 - (void) addDestinationObject:(id) object {
 	
 	BMFAssertReturn(object);
+		
 	
 	#if TARGET_OS_IPHONE
 
 		[object setViewController:self.viewController];
 	}
 	
-#endif
+	#endif
+	
+	if ([self.destinationObjects containsObject:object]) return;
 	
 	[self.destinationObjects addObject:object];
 	
 	[(RACSubject *)self.destinationsSignal sendNext:_destinationObjects];
-	
-//	if (self.destinationsChangedBlock) self.destinationsChangedBlock(self);
 }
 
 - (void) removeDestinationObject:(id) object {
 	if (object) [self.destinationObjects removeObject:object];
 	
 	[(RACSubject *)self.destinationsSignal sendNext:_destinationObjects];
+}
+
+- (void) removeAllDestinationObjects {
+	[self.destinationObjects removeAllObjects];
 
-//	if (self.destinationsChangedBlock) self.destinationsChangedBlock(self);
+	[(RACSubject *)self.destinationsSignal sendNext:_destinationObjects];
 }
 
 - (BOOL)respondsToSelector:(SEL)aSelector {

File bmf/shared/base/BMFDeviceValue.m

 
 @implementation BMFDeviceValue
 
-//- (instancetype) initWithDefaultValue:(id) value {
-//	BMFAssertReturnNil(value);
-//	
-//	self = [super init];
-//    if (self) {
-//        self.defaultValue = value;
-//		self.valuesDic = [NSMutableDictionary dictionary];
-//    }
-//    return self;
-//}
-//
-//- (instancetype)init {
-//	[NSException raise:@"BMFDeviceValue needs at least one value" format:@"Use initWithDefaultValue instead"];
-//	return nil;
-//}
-
 - (void) setValue:(id)value forFamily:(BMFDeviceFamily) family {
-	[self addValue:@(family) conditions:@[ [[BMFBlockCondition alloc] initWithBlock:^BOOL(id param) {
+	[self addValue:value conditions:@[ [[BMFBlockCondition alloc] initWithBlock:^BOOL(id param) {
 		return ([BMFDevice currentDeviceFamily]==family);
 	}] ]];
 }
 
 - (void) setValue:(id)value forFamily:(BMFDeviceFamily) family orientationAxis:(BMFDeviceOrientationAxis) orientation {
 	
-	[self addValue:@(family) conditions:@[
+	[self addValue:value conditions:@[
 										[[BMFBlockCondition alloc] initWithBlock:^BOOL(id param) {
 											return ([BMFDevice currentDeviceFamily]==family);
 										}],
 											return ([BMFDevice currentDeviceOrientationAxis]==orientation);
 										}],
 										   ]];
-	
-//	NSMutableString *key = [[NSString BMF_stringWithInteger:family] mutableCopy];
-//	[key appendString:@"_"];
-//	[key appendString:[NSString BMF_stringWithInteger:orientation]];
-//	
-//	self.valuesDic[key] = value;
 }
 
 - (void) setValue:(id)value forFamily:(BMFDeviceFamily) family orientationAxis:(BMFDeviceOrientationAxis) orientation batteryState:(BMFDeviceBatteryState)batteryState {
 	
 	
-	[self addValue:@(family) conditions:@[
+	[self addValue:value conditions:@[
 										  [[BMFBlockCondition alloc] initWithBlock:^BOOL(id param) {
 		return ([BMFDevice currentDeviceFamily]==family);
 	}],
 	}],
 
 										  ]];
-
-	
-//	NSMutableString *key = [[NSString BMF_stringWithInteger:family] mutableCopy];
-//	[key appendString:@"_"];
-//	[key appendString:[NSString BMF_stringWithInteger:orientation]];
-//	[key appendString:@"_"];
-//	[key appendString:[NSString BMF_stringWithInteger:batteryState]];
-//	
-//	self.valuesDic[key] = value;
 }
 
 - (void) setValue:(id)value forFamily:(BMFDeviceFamily) family orientationAxis:(BMFDeviceOrientationAxis) orientation batteryState:(BMFDeviceBatteryState)batteryState model:(NSString *)model {
 	
 	
-	[self addValue:@(family) conditions:@[
+	[self addValue:value conditions:@[
 										  [[BMFBlockCondition alloc] initWithBlock:^BOOL(id param) {
 		return ([BMFDevice currentDeviceFamily]==family);
 	}],
 		return ([BMFDevice currentDeviceModel]==model);
 	}],
 										  ]];
-	
-//	NSMutableString *key = [[NSString BMF_stringWithInteger:family] mutableCopy];
-//	[key appendString:@"_"];
-//	[key appendString:[NSString BMF_stringWithInteger:orientation]];
-//	[key appendString:@"_"];
-//	[key appendString:[NSString BMF_stringWithInteger:batteryState]];
-//	[key appendString:@"_"];
-//	[key appendString:model];
-//	
-//	self.valuesDic[key] = value;
 }
 
-/*- (id) currentValue {
-	
-	NSString *familyKey = [NSString BMF_stringWithInteger:[BMFDevice currentDeviceFamily]];
-	NSString *orientationKey = [NSString BMF_stringWithInteger:[BMFDevice currentDeviceOrientationAxis]];
-	NSString *batteryKey = [NSString BMF_stringWithInteger:[BMFDevice currentDeviceBatteryState]];
-	NSString *modelKey = [BMFDevice currentDeviceModel];
-	
-	id finalValue = self.defaultValue;
-	
-	NSMutableString *key = [familyKey mutableCopy];
-	if (self.valuesDic[key]) finalValue = self.valuesDic[key];
-	
-	[key appendString:@"_"];
-	[key appendString:orientationKey];
-	if (self.valuesDic[key]) finalValue = self.valuesDic[key];
-	
-	[key appendString:@"_"];
-	[key appendString:batteryKey];
-	if (self.valuesDic[key]) finalValue = self.valuesDic[key];
-	
-	[key appendString:@"_"];
-	[key appendString:modelKey];
-	if (self.valuesDic[key]) finalValue = self.valuesDic[key];
-	
-	return finalValue;
-}*/
-
-
 @end

File bmf/shared/base/NSObject+BMFAspects.h

 
 - (void) BMF_addAspect:(id<BMFAspectProtocol>) aspect;
 - (void) BMF_removeAspect:(id<BMFAspectProtocol>) aspect;
+- (void) BMF_removeAllAspects;
 
 @end

File bmf/shared/base/NSObject+BMFAspects.m

 }
 
 - (void) BMF_removeAspect:(id<BMFAspectProtocol>) aspect {
-	if (!aspect) return;
+	BMFAssertReturn(aspect);
 	
 	[self.BMF_proxy removeDestinationObject:aspect];
 }
 
+- (void) BMF_removeAllAspects {
+	[self.BMF_proxy removeAllDestinationObjects];
+}
+
 @end

File bmf/shared/stats/BMFAverageStats.h

 
 - (instancetype) initWithFileUrl:(NSURL *) fileUrl;
 
+- (void) setPonderation:(double) ponderation forKey:(NSString *) key;
 - (void) setDefaultValue:(double) value forKey:(NSString *) key;
+
 - (void) removeAllValuesForKey:(NSString *) key;
 - (void) addValue:(double) value forKey:(NSString *) key;
 - (double) averageValueForKey:(NSString *) key;

File bmf/shared/stats/BMFAverageStats.m

 	return self.valuesDic[key];
 }
 
+- (void) setPonderation:(double) ponderation forKey:(NSString *) key {
+	BMFAssertReturn(ponderation>0 && ponderation<2);
+
+	dispatch_sync(self.serialQueue, ^{
+		BMFAverageValue *averageValue = [self valueForKey:key];
+		averageValue.ponderation = ponderation;
+		[self save];
+	});
+}
+
 - (void) setDefaultValue:(double) value forKey:(NSString *) key {
 	BMFAssertReturn(key.length>0);
 	

File bmf/shared/stats/BMFAverageTime.m

 
 #import "BMFAverageStats.h"
 
+#define DEFAULT_PONDERATION 1.2
+
 static BMFAverageTime *averageTime = nil;
 
 @interface BMFAverageTime()
 		
 		[averageTime.timesDic removeObjectForKey:key];
 		
+		[averageTime.stats setPonderation:DEFAULT_PONDERATION forKey:key];
+		
 		[averageTime.stats addValue:time forKey:key];
 		
 		NSNumber *effort = averageTime.effortsDic[key];

File bmf/shared/values/BMFAverageValue.h

 
 @property (nonatomic, strong) NSNumber *defaultValue;
 
+/// 1 by default, which means no ponderation. The next value will be multiplied by this value, and the previous average will be multiplied by 2-ponderation
+@property (nonatomic, assign) double ponderation;
+
 - (instancetype) initWithDefaultValue:(NSNumber *) value;
 
 - (void) clear;

File bmf/shared/values/BMFAverageValue.m

 	self = [super init];
 	if (self) {
 		_defaultValue = value;
+		_ponderation = 1;
 	}
 	return self;
 }
 	double average = self.averageValue.doubleValue;
 	NSUInteger nextNumValues = self.numValues+1;
 	
-	average = average*self.numValues/nextNumValues + newItem/nextNumValues;
+	average = average*(2-self.ponderation)*self.numValues/nextNumValues + newItem*self.ponderation/nextNumValues;
 	
 	self.numValues = nextNumValues;
 	self.averageValue = @(average);
 	[aCoder encodeObject:self.defaultValue forKey:@"defaultValue"];
 	[aCoder encodeObject:self.averageValue forKey:@"averageValue"];
 	[aCoder encodeInteger:self.numValues forKey:@"numValues"];
+	[aCoder encodeDouble:self.ponderation forKey:@"ponderation"];
 }
 
 - (instancetype) initWithCoder:(NSCoder *)aDecoder {
 		_defaultValue = [aDecoder decodeObjectForKey:@"defaultValue"];
 		_averageValue = [aDecoder decodeObjectForKey:@"averageValue"];
 		_numValues = [aDecoder decodeIntegerForKey:@"numValues"];
+		_ponderation = [aDecoder decodeDoubleForKey:@"ponderation"];
 	}
 	return self;
 }