Posts Tagged ipad

How to insert BOOL (boolean) value into ManagedObject in Core Data – iOS, iPad, iPhone

If you want to insert BOOL type into core data, you can do it with NSNumber’s member method +numberWithBool:

BOOL myBool = YES;
NSNumber *boolAsNumber = [NSNumber numberWithBool:myBool];
//now you can pass boolAsNumber into you managed object for storage!

If you want to retrieve a BOOL from NSNumber you can use -boolValue.

NSNumber *boolAsNumber = [NSNumber numberWithBool:NO];

BOOL getBool = [boolAsNumber boolValue];
Advertisements

, , , ,

Leave a comment

How to remove all views inside another view – iOS, iPhone, iPad

Let’s say we have a UIScrollView (myScrollView) in our application view. Inside UIScrollView we have couple of different subclasses of UIView (UILabel, UISegmentedControl, UIButton), like shown on the picture below.

Every subclass of UIView has a method subviews, which returns NSArray of all the views that are nested inside the view. Since UIScrollView is the subclass of UIView, we can do the following, for example inside viewDidLoad:

- (void)viewDidLoad {
    [super viewDidLoad];
	UISeg
	for (UIView *aView in [myScrollView subviews]){
		NSLog(@"Class: %@", [aView class]);
	}
}
//Returnes 
//Class: UISegmentedControl
//Class: UILabel
//Class: UILabel
//Class: UILabel
//Class: UIRoundedRectButton
//Class: UITextField
//Class: UIImageView
//Class: UIImageView

Now if we wanted to delete all the subviews inside UIScrollView we would do

[aView removeFromSuperview];

and thus our UIScrollView would now be empty.

If we wanted to remove just UILabels from our UIScrollView we would do:

if ([aView isKindOfClass:[UILabel class]]){
			[aView removeFromSuperview];
		}

, , , ,

2 Comments

How to trim NSString in Objective C 2.0 – iOS, iPad, iPhone

When you want to trim a NSString in Objective C you can use NSString’s method stringByTrimmingCharactersInSet and passing it a [NSCharacterSet whitespaceAndNewlineCharacterSet] characterSet. This will trim your NSString from all newline and whitespace characters.

NSString *trimMe = @"    Trim this string      ";
trimMe = [trimMe stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSLog(@"Trimmed String: ++%@++", trimMe);
//returnes Trimmed String: ++Trim this string+++

You can also trim just whitespace by passing [NSCharacterSet whitespaceCharacterSet] or trim just newline characters by passing [NSCharacterSet newlineCharacterSet]

, , , , ,

1 Comment

Social Calc just released on the App Store

My first app that I submitted to the App Store was just approved. It can be found on: Social Calc

Social Calc calculates how two names get along for love, friendship, business, kids and partying.

Algorithm to calculate percentage is what we used when we were kids in elementary school, it was fun then and I guess it is still fun now (after 20 years).

Application consistis of 5 calculators:

  • Love Calculator
  • Friendship Calculator
  • Business Partner Calculator
  • Kids Calculator
  • Party Calculator
 

, , , ,

Leave a comment