Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Apress committed Oct 25, 2016
0 parents commit 671dd75
Show file tree
Hide file tree
Showing 320 changed files with 16,352 additions and 0 deletions.
Binary file added 9781484215616.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions Chapter 2-1-Impossible Constants/Objective-C/Constants.h
@@ -0,0 +1,16 @@
//
// Constants.h
// BarButtonItemColor
//
// Created by Magno Urbano on 16/07/15.
// Copyright © 2015 -. All rights reserved.
// Part of the book Troubleshooting Xcode, published by Apress


#import <Foundation/Foundation.h>

@interface Constants : NSObject

+ (NSArray *) myConstantArray;

@end
30 changes: 30 additions & 0 deletions Chapter 2-1-Impossible Constants/Objective-C/Constants.m
@@ -0,0 +1,30 @@
//
// Constants.m
// BarButtonItemColor
//
// Created by Magno Urbano on 16/07/15.
// Copyright © 2015 -. All rights reserved.
// Part of the book Troubleshooting Xcode, published by Apress

#import "Constants.h"

@implementation Constants


+ (NSArray *) myConstantArray {
// by declaring the static on the .m we guarantee that other
// classes using this one will not make their
// own copy of the static
static NSArray *_myConstantArray = nil;

@synchronized (_myConstantArray) {
if (_myConstantArray == nil) {
_myConstantArray = @[ /*… your array here … */ ];
}
return _myConstantArray;
}
}



@end
@@ -0,0 +1,18 @@
//
// UIView+IndependentCorners.h
// Vacations
//
// Created by Fireball on 11/07/15.
// Copyright (c) 2015 Magno Urbano. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface UIView (IndependentCorners)


- (void)setCorners:(UIRectCorner)corners withRadius:(CGFloat)radius;



@end
@@ -0,0 +1,32 @@
//
// UIView+IndependentCorners.m
// Vacations
//
// Created by Fireball on 11/07/15.
// Copyright (c) 2015 Magno Urbano. All rights reserved.
//

#import "UIView+IndependentCorners.h"

@implementation UIView (IndependentCorners)


- (void)setCorners:(UIRectCorner)corners withRadius:(CGFloat)radius
{

// UIButton requires this
// [self layer].cornerRadius = 0.0;

UIBezierPath *shapePath = [UIBezierPath bezierPathWithRoundedRect:[self bounds]
byRoundingCorners:corners
cornerRadii:CGSizeMake(radius, radius)];

CAShapeLayer *newCornerLayer = [CAShapeLayer layer];
newCornerLayer.frame = [self bounds];
newCornerLayer.path = shapePath.CGPath;
[self layer].mask = newCornerLayer;

}


@end
@@ -0,0 +1,27 @@
//
// UIView+IndependentCorners.swift
//
//
// Created by Fireball on 10/07/15.
//
//

import UIKit
import QuartzCore


extension UIView {


func corners(corners: UIRectCorner, radius : CGFloat) {

let maskPath = UIBezierPath(roundedRect: bounds, byRoundingCorners: corners, cornerRadii: CGSizeMake(radius, radius))

let cornerLayer = CAShapeLayer()
cornerLayer.frame = self.bounds
cornerLayer.path = maskPath.CGPath
layer.mask = cornerLayer

}

}
@@ -0,0 +1,36 @@
//
// NSView+CompatibleUIView.h
// MacOBJC
//
// Created by Fireball on 11/07/15.
// Copyright (c) 2015 -. All rights reserved.
//

#import <Cocoa/Cocoa.h>

@interface NSView (CompatibleUIView)


- (void)setAlpha:(CGFloat)point;
- (CGFloat)alpha;

- (void)setCenter:(CGPoint)point;
- (CGPoint)center;

+(void)fadeOut:(NSView*)viewToDissolve
withDuration:(NSTimeInterval)duration;

+(void)fadeIn:(NSView*)viewToFadeIn
withDuration:(NSTimeInterval)duration;

+ (void)animateWithDuration:(NSTimeInterval)duration
animations:(void (^)(void))animations;

+ (void)animateWithDuration:(NSTimeInterval)duration
animations:(void (^)(void))animations
completion:(void (^)(BOOL
finished))completion;



@end
@@ -0,0 +1,99 @@
//
// NSView+CompatibleUIView.m
// MacOBJC
//
// Created by Fireball on 11/07/15.
// Copyright (c) 2015 -. All rights reserved.
//

#import "NSView+CompatibleUIView.h"

@implementation NSView (CompatibleUIView)


- (void)setAlpha:(CGFloat)point {
[self setAlphaValue:point];
}

- (CGFloat)alpha {
return self.alphaValue;
}

- (void)setCenter:(CGPoint)point {
CGSize size = self.frame.size;

CGRect newFrame = CGRectZero;
newFrame.size = size;

CGFloat width = CGRectGetWidth(self.frame);
CGFloat height = CGRectGetHeight(self.frame);

CGFloat x = floorf(point.x - (width / 2.0f) );
CGFloat y = floorf(point.y - (height / 2.0f) );

newFrame.origin.x = x;
newFrame.origin.y = y;

[self setFrame:newFrame];
}

- (CGPoint)center {

return CGPointMake(CGRectGetMidX(self.frame),
CGRectGetMidY(self.frame));

}

+(void)fadeOut:(NSView*)viewToDissolve
withDuration:(NSTimeInterval)duration
{
[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext] setDuration:duration];
[[viewToDissolve animator] setAlphaValue:0.0];
[NSAnimationContext endGrouping];

}

+(void)fadeIn:(NSView*)viewToFadeIn
withDuration:(NSTimeInterval)duration
{
[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext] setDuration:duration];
[[viewToFadeIn animator] setAlphaValue:1.0f];
[NSAnimationContext endGrouping];
}

+ (void)animateWithDuration:(NSTimeInterval)duration
animations:(void (^)(void))animations
{
[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext] setDuration:duration];
animations();
[NSAnimationContext endGrouping];
}

+ (void)animateWithDuration:(NSTimeInterval)duration
animations:(void (^)(void))animations
completion:(void (^)(BOOL finished))completion
{
[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext] setDuration:duration];
animations();
[NSAnimationContext endGrouping];

if(animations)
{
id completionBlock = [completion copy];
[self performSelector:@selector(runEndBlock:)
withObject:completionBlock
afterDelay:duration];
}
}

+ (void)runEndBlock:(void (^)(void))completionBlock
{
completionBlock();
}


@end
@@ -0,0 +1,104 @@
//
// NSVIew+CompatibleUIVIew.swift
// MacSwift
//
// Created by Fireball on 11/07/15.
// Copyright (c) 2015 -. All rights reserved.
//

import Foundation
import AppKit

extension NSView {

typealias AnimationHandler = () -> Void
typealias CompletionHandler = (finished : Bool) -> Void


var center:CGPoint {

get {
let midX = CGRectGetMidX(frame)
let midY = CGRectGetMidY(frame)

return CGPointMake(midX, midY)
}

set(newCenter) {
var newFrame = CGRectZero
newFrame.size = frame.size

let myWidth = CGRectGetWidth(frame)
let myHeight = CGRectGetHeight(frame)

let x = floor(newCenter.x - (myWidth / 2.0) )
let y = floor(newCenter.y - (myHeight / 2.0) )

newFrame.origin.x = x
newFrame.origin.y = y

frame = newFrame
}


}


var alpha : CGFloat {

get{
return alphaValue
}

set(value) {
alphaValue = value
}

}

func fadeInWithDuration (duration : NSTimeInterval) {
wantsLayer = true
NSAnimationContext.beginGrouping()
NSAnimationContext.currentContext().duration = duration
animator().alphaValue = 1.0
NSAnimationContext.endGrouping()
}

func fadeOutWithDuration (duration : NSTimeInterval) {
wantsLayer = true
NSAnimationContext.beginGrouping()
NSAnimationContext.currentContext().duration = duration
animator().alphaValue = 0.0
NSAnimationContext.endGrouping()
}

func animateWithDuration (duration : NSTimeInterval, animations:AnimationHandler) {
wantsLayer = true
NSAnimationContext.runAnimationGroup({ (context: NSAnimationContext) -> Void in

context.duration = duration
context.allowsImplicitAnimation = true

animations()
}, completionHandler: { () -> Void in

})
}


func animateWithDuration (duration : NSTimeInterval, animations:AnimationHandler, completion:CompletionHandler) {
wantsLayer = true

NSAnimationContext.runAnimationGroup({ (context: NSAnimationContext) -> Void in

context.duration = duration
context.allowsImplicitAnimation = true

animations()
}, completionHandler: { () -> Void in
completion(finished:true)

})

}
}

0 comments on commit 671dd75

Please sign in to comment.