问:
How to build structure from cfquery?
I have cffunction that should return JSON structure. There is more than 50 columns that I have to return. Instead of building my structure manually I would like to build that dynamically. So first loop through query then loop through each table column. Here is example:

```<code>     <cffunction name="getRecords" access="remote" output="true" returnformat="JSON">
            <cfargument name="userID" type="string" required="true">

            <cfset fnResults = StructNew()>

            <cfquery name="myQuery" datasource="test">
                SELECT
                   ur_first,
                   ur_last,
                   ur_dob,
                   ur_gender,
                   ur_email,
                   ur_address,
                   ... and the rest of the columns
                FROM Users
                WHERE ur_id = <cfqueryparam value="#trim(arguments.userID)#" cfsqltype="cf_sql_char" maxlength="15">
                ORDER BY ur_createDt
            </cfquery>

            <cfset fnResults.recordcount = myQuery.recordcount>

            <cfloop query="myQuery">
                <cfset qryRecs = StructNew()>
                <cfloop array="#myQuery.getColumnList()#" index="columnName">
                    <cfset qryRecs.'#columnName#' = URLEncodedFormat('#columnName#')>
                </cfloop>
             </cfloop>

             <cfset fnResults.data = qryRecs>

          <cfreturn fnResults>
     </cffunction>
</code>```

This error I'm getting back after Ajax call:

```<code>CFML variable name cannot end with a "." character.
The variable qryRecs. ends with a "." character. You must either provide an additional structure key or delete the "." character.
</code>```

Referencing to this line:

```<code>443 : <cfset qryRecs.'#columnName#' = URLEncodedFormat('#columnName#')>
</code>```

I want to set column name to structure qryRecs like this:

```<code><cfset qryRecs.ur_first = URLEncodedFormat(myQuery.ur_first)>
</code>```

This way I don't have to set 50 plus columns manually. They all should be created dynamically. If anyone can help please let me know.

答:
I created an ArrayCollection object that can convert a ColdFusion query to a few different JSON formats. Take a look and see if this fits your needs.

For example, this query:

```<code><cfquery name="rs.q" datasource="cfbookclub">
    SELECT DISTINCT
        bookid,
        title,
        genre
    FROM
        books
    WHERE
        title LIKE <cfqueryparam value="%#arguments.term#%" cfsqltype="cf_sql_varchar" />
    ORDER BY
        genre, title
</cfquery></code>```

will be converted to this JSON:

```<code>{
    "data": [
        {
            "bookid": 8,
            "genre": "Fiction",
            "title": "Apparition Man"
        },
        {
            "bookid": 2,
            "genre": "Non-fiction",
            "title": "Shopping Mart Mania"
        }
    ]
}</code>```

I'm also working on an update that adds meta data to the return message:

```<code>{
    "success": true,
    "message": "Array Collection created.",
    "meta": {
        "offset": 0,
        "pageSize": 0,
        "totalRecords": 0
    },
    "data": []
};</code>```

Title: How to build structure from cfquery?

Body:
I have cffunction that should return JSON structure. There is more than 50 columns that I have to return. Instead of building my structure manually I would like to build that dynamically. So first loop through query then loop through each table column. Here is example:

     <cffunction name="getRecords" access="remote" output="true" returnformat="JSON">
            <cfargument name="userID" type="string" required="true">

            <cfset fnResults = StructNew()>

            <cfquery name="myQuery" datasource="test">
                SELECT
                   ur_first,
                   ur_last,
                   ur_dob,
                   ur_gender,
                   ur_email,
                   ur_address,
                   ... and the rest of the columns
                FROM Users
                WHERE ur_id = <cfqueryparam value="#trim(arguments.userID)#" cfsqltype="cf_sql_char" maxlength="15">
                ORDER BY ur_createDt
            </cfquery>

            <cfset fnResults.recordcount = myQuery.recordcount>

            <cfloop query="myQuery">
                <cfset qryRecs = StructNew()>
                <cfloop array="#myQuery.getColumnList()#" index="columnName">
                    <cfset qryRecs.'#columnName#' = URLEncodedFormat('#columnName#')>
                </cfloop>
             </cfloop>

             <cfset fnResults.data = qryRecs>

          <cfreturn fnResults>
     </cffunction>

This error I'm getting back after Ajax call:

CFML variable name cannot end with a "." character.
The variable qryRecs. ends with a "." character. You must either provide an additional structure key or delete the "." character.

Referencing to this line:

443 : <cfset qryRecs.'#columnName#' = URLEncodedFormat('#columnName#')>

I want to set column name to structure qryRecs like this:

<cfset qryRecs.ur_first = URLEncodedFormat(myQuery.ur_first)>

This way I don't have to set 50 plus columns manually. They all should be created dynamically. If anyone can help please let me know.

Body:
I created an ArrayCollection object that can convert a ColdFusion query to a few different JSON formats. Take a look and see if this fits your needs.

For example, this query:

<cfquery name="rs.q" datasource="cfbookclub">
    SELECT DISTINCT
        bookid,
        title,
        genre
    FROM
        books
    WHERE
        title LIKE <cfqueryparam value="%#arguments.term#%" cfsqltype="cf_sql_varchar" />
    ORDER BY
        genre, title
</cfquery>

will be converted to this JSON:

{
    "data": [
        {
            "bookid": 8,
            "genre": "Fiction",
            "title": "Apparition Man"
        },
        {
            "bookid": 2,
            "genre": "Non-fiction",
            "title": "Shopping Mart Mania"
        }
    ]
}

I'm also working on an update that adds meta data to the return message:

{
    "success": true,
    "message": "Array Collection created.",
    "meta": {
        "offset": 0,
        "pageSize": 0,
        "totalRecords": 0
    },
    "data": []
};


来源: stackexchange

问:
Proper indentation in array initialization, PDT/Zend Studio
I'm using the following style of array initialization in the code:

```<code>$a = array(
    'one' => 123,
    'two' => 456
);
</code>```

But PDT/Zend Studio doesn't work properly in this case; after pressing [Return] key it places cursor under the $a (in my example) and ignores indentation. If array keys are numbers (at least not start with quotation marks) everything is working fine.

This is how it works currently (| — is a position where edtitor places caret after pressing [Return])

```<code>$a = array(
    'one' => 123,[RETURN]
|
);
</code>```

This is expected result:

```<code>$a = array(
    'one' => 123,[RETURN]
    |
);
</code>```

So is it possible to force editor follow my indentation rules?

答:
I had recently exactly the same issue. I solved it in the Zend Studio (Eclipse based IDE) by going to

Preferences -> PHP -> Code Style -> Formatter

and then choose edit on the screen next to the fortmatter preset name. In the opened window go to the Line Wrapping tab and in the list choose

Expressions -> Array Initializers.

Play with the settings to your likings.

Regards

Lukas

ContentLicense: CC BY-SA 2.5

Body:
I'm using the following style of array initialization in the code:

$a = array(
    'one' => 123,
    'two' => 456
);

But PDT/Zend Studio doesn't work properly in this case; after pressing [Return] key it places cursor under the $a (in my example) and ignores indentation. If array keys are numbers (at least not start with quotation marks) everything is working fine.

This is how it works currently (| — is a position where edtitor places caret after pressing [Return])

$a = array(
    'one' => 123,[RETURN]
|
);

This is expected result:

$a = array(
    'one' => 123,[RETURN]
    |
);

So is it possible to force editor follow my indentation rules?


问:
Connect to Java socket via hostname
Is it possible to connect to Java WebSocket through flash using server hostname, not IP? The reason is the specifications of Cloud9, they don't give any IPs, only hostnames. Tests showed that WebSocket gets requests to connect through browser, but not from Socket class in Flash</p>

答:
programming for a Client:

```<code>Socket MyClient;
try {
       MyClient = new Socket("Machine name", PortNumber);
}
catch (IOException e) {
    System.out.println(e);
}
</code>```

programming for a Server:

```<code>ServerSocket MyService;
try {
   MyServerice = new ServerSocket(PortNumber);
    }
    catch (IOException e) {
       System.out.println(e);
    }
</code>```

for further you can refer below URL :-

http://www.javaworld.com/article/2077322/core-java/core-java-sockets-programming-in-java-a-tutorial.html

ContentLicense: CC BY-SA 3.0

Title: Connect to Java socket via hostname

Body:
programming for a Client:

Socket MyClient;
try {
       MyClient = new Socket("Machine name", PortNumber);
}
catch (IOException e) {
    System.out.println(e);
}

programming for a Server:

ServerSocket MyService;
try {
   MyServerice = new ServerSocket(PortNumber);
    }
    catch (IOException e) {
       System.out.println(e);
    }

for further you can refer below URL :-

http://www.javaworld.com/article/2077322/core-java/core-java-sockets-programming-in-java-a-tutorial.html


答:
Throwing this into the mix:</p>

```<code>df.loc[[x for x in df.index if x[-1].isalpha()]]
</code>```

Title: filter df based on index condition

Body:
I have a df with lots of rows:

13790226       0.320  0.001976
9895d5dis    182.600  0.040450
105066007     18.890  0.006432
109067019     52.500  0.034011
111845014     16.400  0.023974
11668574e      7.180  0.070714
113307021      4.110  0.017514
113679I37      8.180  0.010837

I would like to filter this df in order to obtain the rows where the index last char is not a digit

Desired df:

9895d5dis    182.600  0.040450
11668574e      7.180  0.070714

How can I do it?

Body:
Throwing this into the mix:

df.loc[[x for x in df.index if x[-1].isalpha()]]


问:
Recognizing a link on a website to click on it in a using screen visual only

What I want to do is to write a Python script to recognize a specific link and make a left-click on it. To be more explanatory, here are two images from websites:

Page 1

and

Page 2

I want the script to click on "enter site" in page 1 and "try again" on page 2. If possible I want to use machine learning having only the screen image input. It is probably easier to go through the site source, but I want to be further challenged. I gave this a thought but couldn't figure out where to start.

答:
Using screen visual only, you can use:

```<code>import pyautogui
</code>```

and then look for the

pyautogui.locateOnScreen() or pyautogui.locateCenterOfScreen() functions.

Body:
Using screen visual only, you can use:

import pyautogui

and then look for the

pyautogui.locateOnScreen() or pyautogui.locateCenterOfScreen() functions.


问:
How to start a django cms project
I decided to take a look to django-cms. After looking at the docs I cloned the repository using

```<code>git clone https://github.com/divio/django-cms.git
</code>```

Then I installed it using

```<code>sudo python setup.py install
</code>```

I already have django 1.2.3 installed. I moved to the example directory an ran syncdb which created the following tables:

```<code>Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_user_permissions
Creating table auth_user_groups
Creating table auth_user
Creating table auth_message
Creating table django_content_type
Creating table django_session
Creating table django_admin_log
Creating table django_site
Creating table sampleapp_category
Creating table sampleapp_picture
Creating table south_migrationhistory

You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): yes...
</code>```

We can clearly see that the cms tables are not created. I'm obviously facing that problem when running the server and browsing http://localhost:8000/

```<code>DatabaseError: no such table: cms_page
</code>```

I've looked at the docs and seen that I meet the requirements regarding the versions but clearly, I'm doing something wrong. Any help would be greatly appreciated.

答:
In general, if tables are not created there can be some errors in the application itself:
try running Django shell and import a model from the application:

```<code>python manage.py shell

>>> from csm import models
</code>```

and check if you get a traceback.

Hope this can help.

Title: How to start a django cms project

Body:
I decided to take a look to django-cms. After looking at the docs I cloned the repository using

git clone https://github.com/divio/django-cms.git

Then I installed it using

sudo python setup.py install

I already have django 1.2.3 installed. I moved to the example directory an ran syncdb which created the following tables:

Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_user_permissions
Creating table auth_user_groups
Creating table auth_user
Creating table auth_message
Creating table django_content_type
Creating table django_session
Creating table django_admin_log
Creating table django_site
Creating table sampleapp_category
Creating table sampleapp_picture
Creating table south_migrationhistory

You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): yes...

We can clearly see that the cms tables are not created. I'm obviously facing that problem when running the server and browsing http://localhost:8000/

DatabaseError: no such table: cms_page

I've looked at the docs and seen that I meet the requirements regarding the versions but clearly, I'm doing something wrong. Any help would be greatly appreciated.

Body:
In general, if tables are not created there can be some errors in the application itself:
try running Django shell and import a model from the application:

python manage.py shell

>>> from csm import models

and check if you get a traceback.

Hope this can help.


问:
I am having problems with "error ';' expected"
Im having problem with this code. The console shows this error to me and I cannot figure it out. "file.java on line 7: error: ';' expected"

```<code>int adjacentElementsProduct(int[] inputArray) {
    int numberofElements = inputArray.length();
    int [] products = new int [numberofElements];
    for (int firstNumber = 0; numberofElements > firstNumber; firstNumber++) {
         products [firstNumber] = product (inputArray [firstNumber], inputArray [1+firstNumber]);
    };
    int maxValue () {
        int x = products [0];
        for (int i = 1; i < products.length; i++) {
            if (products [i] > x){
                x = products [i];
            }
        }
        return x;
    }
    return maxValue;
}
</code>```

If anyone could help me with this, I would really appreciate.
Thank you.

答:
Code is not properly formated because you have a method maxValue inside of method adjacentElementsProduct.

This is how it should be:

```<code>int adjacentElementsProduct(int[] inputArray) {
    int numberofElements = inputArray.length();
    int [] products = new int [numberofElements];
    for (int firstNumber = 0; numberofElements > firstNumber; firstNumber++) {
         products [firstNumber] = product (inputArray [firstNumber], inputArray [1+firstNumber]);
    }
    return maxValue;
}

int maxValue () {
    int x = products [0];
    for (int i = 1; i < products.length; i++) {
        if (products [i] > x){
            x = products [i];
        }
    }
    return x;
}
</code>```

Also, you have one one extra/useless semicolon after closing for loop, before declaration of maxValue method

Hope it helped

Body:
Im having problem with this code. The console shows this error to me and I cannot figure it out. "file.java on line 7: error: ';' expected"

int adjacentElementsProduct(int[] inputArray) {
    int numberofElements = inputArray.length();
    int [] products = new int [numberofElements];
    for (int firstNumber = 0; numberofElements > firstNumber; firstNumber++) {
         products [firstNumber] = product (inputArray [firstNumber], inputArray [1+firstNumber]);
    };
    int maxValue () {
        int x = products [0];
        for (int i = 1; i < products.length; i++) {
            if (products [i] > x){
                x = products [i];
            }
        }
        return x;
    }
    return maxValue;
}

If anyone could help me with this, I would really appreciate.
Thank you.

Body:
Code is not properly formated because you have a method maxValue inside of method adjacentElementsProduct.

This is how it should be:

int adjacentElementsProduct(int[] inputArray) {
    int numberofElements = inputArray.length();
    int [] products = new int [numberofElements];
    for (int firstNumber = 0; numberofElements > firstNumber; firstNumber++) {
         products [firstNumber] = product (inputArray [firstNumber], inputArray [1+firstNumber]);
    }
    return maxValue;
}

int maxValue () {
    int x = products [0];
    for (int i = 1; i < products.length; i++) {
        if (products [i] > x){
            x = products [i];
        }
    }
    return x;
}

Also, you have one one extra/useless semicolon after closing for loop, before declaration of maxValue method

Hope it helped


问:
Sitecore 8 easy way to get Item in internal link?
I have several General Link Fields, that are used as internal Links, so a Sitecore Item.

I need that "target" Items in my code, and I have the feeling that I am doing it in a horrible complex way:

LinkField lf = myItem.Fields["My Link"];
if (lf != null)
{
    if (lf.Value != null)
    {
        ID targetID;
        if (ID.TryParse(lf.Value, out targetID))
        {
            Item targetItem = Sitecore.Context.Database.GetItem(targetID);
            {
                if (targetItem != null)
                {
                    // go on with code
                }
            }
        }
    }
}
```

Does someone know a more easy way to get this target Item?

Regards

答:
You can use TargetItem property of the LinkField without custom code:

Item targetItem;

LinkField linkField = myItem.Fields["My Link"];
if (linkField != null && linkField.IsInternal)
{
    targetItem = linkField.TargetItem;
}
```

Body:
I have several General Link Fields, that are used as internal Links, so a Sitecore Item.

I need that "target" Items in my code, and I have the feeling that I am doing it in a horrible complex way:

LinkField lf = myItem.Fields["My Link"];
if (lf != null)
{
    if (lf.Value != null)
    {
        ID targetID;
        if (ID.TryParse(lf.Value, out targetID))
        {
            Item targetItem = Sitecore.Context.Database.GetItem(targetID);
            {
                if (targetItem != null)
                {
                    // go on with code
                }
            }
        }
    }
}

Does someone know a more easy way to get this target Item?

Regards


问:
inbox returning null while trying to access Lotus mail inbox using c#
I am using c# to integrate Lotus mail inbox woth my application.I am trying to debug my c# code and in that process i m getting a null value at my inbox near the code db.GetView("$Inbox").I am accessing Lotus mail client8 in my company and i tried accessing the same with my c# application. while debugging i even closed my mail client and tried but result remained same.Please help me where i went wrong..as its very urgent.Thanks in Advance...</p>

答:
It's a hidden folder, use</p>

```<code>GetView("($Inbox)")
</code>```

Body:
It's a hidden folder, use

GetView("($Inbox)")


问:
Autolayout Warning : Will attempt to recover by breaking constraint <NSLayoutConstraint in CollectionView
I'm using UICollectionView & Flow Layout and Class for layout of collectionView Cell is as to achieve slide animation like feedly app Or insorts app

```<code>import UIKit
class UltravisualLayout: UICollectionViewLayout {
    fileprivate var contentWidth:CGFloat!
    fileprivate var contentHeight:CGFloat!
    fileprivate var yOffset:CGFloat = 0

    var maxAlpha:CGFloat = 1
    var minAlpha:CGFloat = 0

    var widthOffset:CGFloat = 0
    var heightOffset:CGFloat = 0

    fileprivate var cache = [UICollectionViewLayoutAttributes]()

    fileprivate var itemWidth:CGFloat{
        return (collectionView?.bounds.width)!
    }
    fileprivate var itemHeight:CGFloat{
        return (collectionView?.bounds.height)!
    }
    fileprivate var collectionViewHeight:CGFloat{
        return (collectionView?.bounds.height)!
    }

    fileprivate var numberOfItems:Int{
        return (collectionView?.numberOfItems(inSection: 0))!
    }

    fileprivate var dragOffset:CGFloat{
        return (collectionView?.bounds.height)!
    }
    fileprivate var currentItemIndex:Int{
        return max(0, Int(collectionView!.contentOffset.y / collectionViewHeight))
    }

    var nextItemBecomeCurrentPercentage:CGFloat{
        return (collectionView!.contentOffset.y / (collectionViewHeight)) - CGFloat(currentItemIndex)
    }

    override func prepare() {
        cache.removeAll(keepingCapacity: false)
        yOffset = 0

        for item in 0 ..< numberOfItems{

            let indexPath = IndexPath(item: item, section: 0)
            let attribute = UICollectionViewLayoutAttributes(forCellWith: indexPath)
            attribute.zIndex = -(indexPath as NSIndexPath).row

            if ((indexPath as NSIndexPath).item == currentItemIndex+1) && ((indexPath as NSIndexPath).item < numberOfItems){

                attribute.alpha = minAlpha + max((maxAlpha-minAlpha) * nextItemBecomeCurrentPercentage, 0)
                let width = itemWidth - widthOffset + (widthOffset * nextItemBecomeCurrentPercentage)
                let height = itemHeight - heightOffset + (heightOffset * nextItemBecomeCurrentPercentage)

                let deltaWidth =  width/itemWidth
                let deltaHeight = height/itemHeight

                attribute.frame = CGRect(x: 0, y: yOffset, width: itemWidth, height: itemHeight)
                attribute.transform = CGAffineTransform(scaleX: deltaWidth, y: deltaHeight)

                attribute.center.y = (collectionView?.center.y)! +  (collectionView?.contentOffset.y)!
                attribute.center.x = (collectionView?.center.x)! + (collectionView?.contentOffset.x)!
                yOffset += collectionViewHeight

            }else{
                attribute.frame = CGRect(x: 0, y: yOffset, width: itemWidth, height: itemHeight)
                attribute.center.y = (collectionView?.center.y)! + yOffset
                attribute.center.x = (collectionView?.center.x)!
                yOffset += collectionViewHeight
            }
            cache.append(attribute)
        }
    }

    //Return the size of ContentView
    override var collectionViewContentSize : CGSize {
        contentWidth = (collectionView?.bounds.width)!
        contentHeight = CGFloat(numberOfItems) * (collectionView?.bounds.height)!
        return CGSize(width: contentWidth, height: contentHeight)
    }

    //Return Attributes  whose frame lies in the Visible Rect
    override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
        var layoutAttributes = [UICollectionViewLayoutAttributes]()
        for attribute in cache{
            if attribute.frame.intersects(rect){
                layoutAttributes.append(attribute)
            }
        }
        return layoutAttributes
    }

    override func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool {
        return true
    }

    override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint, withScrollingVelocity velocity: CGPoint) -> CGPoint {
        let itemIndex = round(proposedContentOffset.y / (dragOffset))
        let yOffset = itemIndex * (collectionView?.bounds.height)!
        return CGPoint(x: 0, y: yOffset)
    }
    override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? {

        // Logic that calculates the UICollectionViewLayoutAttributes of the item
        // and returns the UICollectionViewLayoutAttributes
        return UICollectionViewLayoutAttributes(forCellWith: indexPath)
    }

}
</code>```

I Created  custom view with Xib as

Class SmallStory

```<code>#import <UIKit/UIKit.h>
@interface SmallStory : UIView
@property (weak, nonatomic) IBOutlet UIImageView *image;
@property (weak, nonatomic) IBOutlet UILabel *title;
@property (weak, nonatomic) IBOutlet UILabel *pubDate;
@end
</code>```

SmallStory.m

```<code>#import "SmallStory.h"
@interface SmallStory()
@property (nonatomic, strong) UIView *containerView;
@property (nonatomic, strong) NSMutableArray *customConstraints;

@end
@implementation SmallStory

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self customInit];
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self customInit];
    }
    return self;
}

- (void)customInit
{
    _customConstraints = [[NSMutableArray alloc] init];

    UIView *view = nil;
    NSArray *objects = [[NSBundle mainBundle] loadNibNamed:@"SmallStory"
                                                     owner:self
                                                   options:nil];
    for (id object in objects) {
        if ([object isKindOfClass:[UIView class]]) {
            view = object;
            break;
        }
    }

    if (view != nil) {
        _containerView = view;
        view.translatesAutoresizingMaskIntoConstraints = NO;
        [self addSubview:view];
        [self setNeedsUpdateConstraints];
    }
}
- (void)updateConstraints
{
    [self removeConstraints:self.customConstraints];
    [self.customConstraints removeAllObjects];

    if (self.containerView != nil) {
        UIView *view = self.containerView;
        NSDictionary *views = NSDictionaryOfVariableBindings(view);
        [self.customConstraints addObjectsFromArray:
         [NSLayoutConstraint constraintsWithVisualFormat:
          @"H:|[view]|" options:0 metrics:nil views:views]];
        [self.customConstraints addObjectsFromArray:
         [NSLayoutConstraint constraintsWithVisualFormat:
          @"V:|[view]|" options:0 metrics:nil views:views]];
        [self addConstraints:self.customConstraints];
    }

    [super updateConstraints];
}

- (UIViewController*)getSuperViewController
{
    for (UIView* next = [self superview]; next; next = next.superview)
    {
        UIResponder* nextResponder = [next nextResponder];

        if ([nextResponder isKindOfClass:[UIViewController class]])
        {
            return (UIViewController*)nextResponder;
        }
    }

    return nil;
}
@end
</code>```

Xib Design Looks like

ided into 5 parts

and each small view is assigned as SmallStory Class

and Story Board Looks Like

When I run App There is Autolayout warnings as below

```<code>*2017-06-06 22:18:04.044717+0530 Jansatta[1096:258239] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want.
    Try this:
        (1) look at each constraint and try to figure out which you don't expect;
        (2) find the code that added the unwanted constraint or constraints and fix it.
    (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
    "<NSAutoresizingMaskLayoutConstraint:0x17028ca30 h=--& v=--& UIView:0x113d2c230.height == 0   (active)>",
    "<NSLayoutConstraint:0x1702875d0 UIImageView:0x113e32700.bottom == UIView:0x113e32e10.bottomMargin   (active)>",
    "<NSLayoutConstraint:0x170287260 UIImageView:0x113e32700.top == UIView:0x113e32e10.topMargin   (active)>",
    "<NSLayoutConstraint:0x17028af00 SmallStory:0x113e324f0.height == SmallStory:0x113d2c5e0.height   (active)>",
    "<NSLayoutConstraint:0x17028aff0 SmallStory:0x113d2c5e0.height == SmallStory:0x113d2c3d0.height   (active)>",
    "<NSLayoutConstraint:0x17028b270 SmallStory:0x113d2c3d0.height == 0.2*UIView:0x113d2c230.height   (active)>",
    "<NSLayoutConstraint:0x17028bea0 V:|-(0)-[UIView:0x113e32e10]   (active, names: '|':SmallStory:0x113e324f0 )>",
    "<NSLayoutConstraint:0x17028bef0 V:[UIView:0x113e32e10]-(0)-|   (active, names: '|':SmallStory:0x113e324f0 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x1702875d0 UIImageView:0x113e32700.bottom == UIView:0x113e32e10.bottomMargin   (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2017-06-06 22:18:04.047763+0530 Jansatta[1096:258239] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want.
    Try this:
        (1) look at each constraint and try to figure out which you don't expect;
        (2) find the code that added the unwanted constraint or constraints and fix it.
    (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
    "<NSAutoresizingMaskLayoutConstraint:0x17028cad0 h=--& v=--& UIView:0x113d2c230.width == 0   (active)>",
    "<NSLayoutConstraint:0x174285f00 H:|-(10)-[UIImageView:0x113d2c980]   (active, names: '|':UIView:0x113d2d090 )>",
    "<NSLayoutConstraint:0x174285f50 H:[UILabel:0x113d2ce00]-(10)-|   (active, names: '|':UIView:0x113d2d090 )>",
    "<NSLayoutConstraint:0x174285ff0 H:[UIImageView:0x113d2c980]-(10)-[UILabel:0x113d2ce00]   (active)>",
    "<NSLayoutConstraint:0x17028b130 SmallStory:0x113d2c3d0.width == UIView:0x113d2c230.width   (active)>",
    "<NSLayoutConstraint:0x17028b950 H:|-(0)-[UIView:0x113d2d090]   (active, names: '|':SmallStory:0x113d2c3d0 )>",
    "<NSLayoutConstraint:0x17028b9a0 H:[UIView:0x113d2d090]-(0)-|   (active, names: '|':SmallStory:0x113d2c3d0 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x174285ff0 H:[UIImageView:0x113d2c980]-(10)-[UILabel:0x113d2ce00]   (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2017-06-06 22:18:04.050793+0530 Jansatta[1096:258239] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want.
    Try this:
        (1) look at each constraint and try to figure out which you don't expect;
        (2) find the code that added the unwanted constraint or constraints and fix it.
    (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
    "<NSAutoresizingMaskLayoutConstraint:0x17028ca30 h=--& v=--& UIView:0x113d2c230.height == 0   (active)>",
    "<NSLayoutConstraint:0x170288840 UIImageView:0x113e331c0.bottom == UIView:0x113e33e00.bottomMargin   (active)>",
    "<NSLayoutConstraint:0x1702887a0 UIImageView:0x113e331c0.top == UIView:0x113e33e00.topMargin   (active)>",
    "<NSLayoutConstraint:0x1702892e0 SmallStory:0x113e32fb0.height == SmallStory:0x113e324f0.height   (active)>",
    "<NSLayoutConstraint:0x17028af00 SmallStory:0x113e324f0.height == SmallStory:0x113d2c5e0.height   (active)>",
    "<NSLayoutConstraint:0x17028aff0 SmallStory:0x113d2c5e0.height == SmallStory:0x113d2c3d0.height   (active)>",
    "<NSLayoutConstraint:0x17028b270 SmallStory:0x113d2c3d0.height == 0.2*UIView:0x113d2c230.height   (active)>",
    "<NSLayoutConstraint:0x17028c0d0 V:|-(0)-[UIView:0x113e33e00]   (active, names: '|':SmallStory:0x113e32fb0 )>",
    "<NSLayoutConstraint:0x17028c120 V:[UIView:0x113e33e00]-(0)-|   (active, names: '|':SmallStory:0x113e32fb0 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x170288840 UIImageView:0x113e331c0.bottom == UIView:0x113e33e00.bottomMargin   (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2017-06-06 22:18:04.054839+0530 Jansatta[1096:258239] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want.
    Try this:
        (1) look at each constraint and try to figure out which you don't expect;
        (2) find the code that added the unwanted constraint or constraints and fix it.
    (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
    "<NSAutoresizingMaskLayoutConstraint:0x17028ca30 h=--& v=--& UIView:0x113d2c230.height == 0   (active)>",
    "<NSLayoutConstraint:0x170287fd0 UIImageView:0x113e341b0.bottom == UIView:0x113e348c0.bottomMargin   (active)>",
    "<NSLayoutConstraint:0x170287f30 UIImageView:0x113e341b0.top == UIView:0x113e348c0.topMargin   (active)>",
    "<NSLayoutConstraint:0x1702892e0 SmallStory:0x113e32fb0.height == SmallStory:0x113e324f0.height   (active)>",
    "<NSLayoutConstraint:0x1702881b0 SmallStory:0x113e32fb0.height == SmallStory:0x113e33fa0.height   (active)>",
    "<NSLayoutConstraint:0x17028af00 SmallStory:0x113e324f0.height == SmallStory:0x113d2c5e0.height   (active)>",
    "<NSLayoutConstraint:0x17028aff0 SmallStory:0x113d2c5e0.height == SmallStory:0x113d2c3d0.height   (active)>",
    "<NSLayoutConstraint:0x17028b270 SmallStory:0x113d2c3d0.height == 0.2*UIView:0x113d2c230.height   (active)>",
    "<NSLayoutConstraint:0x17028c300 V:|-(0)-[UIView:0x113e348c0]   (active, names: '|':SmallStory:0x113e33fa0 )>",
    "<NSLayoutConstraint:0x17028c350 V:[UIView:0x113e348c0]-(0)-|   (active, names: '|':SmallStory:0x113e33fa0 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x170287fd0 UIImageView:0x113e341b0.bottom == UIView:0x113e348c0.bottomMargin   (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2017-06-06 22:18:04.058339+0530 Jansatta[1096:258239] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want.
    Try this:
        (1) look at each constraint and try to figure out which you don't expect;
        (2) find the code that added the unwanted constraint or constraints and fix it.
    (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
    "<NSAutoresizingMaskLayoutConstraint:0x17028cad0 h=--& v=--& UIView:0x113d2c230.width == 0   (active)>",
    "<NSLayoutConstraint:0x170287620 H:|-(10)-[UIImageView:0x113e32700]   (active, names: '|':UIView:0x113e32e10 )>",
    "<NSLayoutConstraint:0x170287670 H:[UILabel:0x113e32b80]-(10)-|   (active, names: '|':UIView:0x113e32e10 )>",
    "<NSLayoutConstraint:0x1702876c0 H:[UIImageView:0x113e32700]-(10)-[UILabel:0x113e32b80]   (active)>",
    "<NSLayoutConstraint:0x17028aeb0 SmallStory:0x113e324f0.width == SmallStory:0x113d2c5e0.width   (active)>",
    "<NSLayoutConstraint:0x17028b040 SmallStory:0x113d2c5e0.width == SmallStory:0x113d2c3d0.width   (active)>",
    "<NSLayoutConstraint:0x17028b130 SmallStory:0x113d2c3d0.width == UIView:0x113d2c230.width   (active)>",
    "<NSLayoutConstraint:0x17028be00 H:|-(0)-[UIView:0x113e32e10]   (active, names: '|':SmallStory:0x113e324f0 )>",
    "<NSLayoutConstraint:0x17028be50 H:[UIView:0x113e32e10]-(0)-|   (active, names: '|':SmallStory:0x113e324f0 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x1702876c0 H:[UIImageView:0x113e32700]-(10)-[UILabel:0x113e32b80]   (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2017-06-06 22:18:04.061159+0530 Jansatta[1096:258239] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want.
    Try this:
        (1) look at each constraint and try to figure out which you don't expect;
        (2) find the code that added the unwanted constraint or constraints and fix it.
    (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
    "<NSAutoresizingMaskLayoutConstraint:0x17028cad0 h=--& v=--& UIView:0x113d2c230.width == 0   (active)>",
    "<NSLayoutConstraint:0x17028a820 UIImageView:0x113e04f90.width == 180   (active)>",
    "<NSLayoutConstraint:0x17028aaf0 H:|-(10)-[UIImageView:0x113e04f90]   (active, names: '|':UIView:0x113e195a0 )>",
    "<NSLayoutConstraint:0x17028abe0 H:[UILabel:0x113e31dc0]-(10)-|   (active, names: '|':UIView:0x113e195a0 )>",
    "<NSLayoutConstraint:0x17028ac80 H:[UIImageView:0x113e04f90]-(10)-[UILabel:0x113e31dc0]   (active)>",
    "<NSLayoutConstraint:0x17028b040 SmallStory:0x113d2c5e0.width == SmallStory:0x113d2c3d0.width   (active)>",
    "<NSLayoutConstraint:0x17028b130 SmallStory:0x113d2c3d0.width == UIView:0x113d2c230.width   (active)>",
    "<NSLayoutConstraint:0x17028bbd0 H:|-(0)-[UIView:0x113e195a0]   (active, names: '|':SmallStory:0x113d2c5e0 )>",
    "<NSLayoutConstraint:0x17028bc20 H:[UIView:0x113e195a0]-(0)-|   (active, names: '|':SmallStory:0x113d2c5e0 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x17028a820 UIImageView:0x113e04f90.width == 180   (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2017-06-06 22:18:04.064548+0530 Jansatta[1096:258239] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want.
    Try this:
        (1) look at each constraint and try to figure out which you don't expect;
        (2) find the code that added the unwanted constraint or constraints and fix it.
    (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
    "<NSAutoresizingMaskLayoutConstraint:0x17028cad0 h=--& v=--& UIView:0x113d2c230.width == 0   (active)>",
    "<NSLayoutConstraint:0x17028aaf0 H:|-(10)-[UIImageView:0x113e04f90]   (active, names: '|':UIView:0x113e195a0 )>",
    "<NSLayoutConstraint:0x17028abe0 H:[UILabel:0x113e31dc0]-(10)-|   (active, names: '|':UIView:0x113e195a0 )>",
    "<NSLayoutConstraint:0x17028ac80 H:[UIImageView:0x113e04f90]-(10)-[UILabel:0x113e31dc0]   (active)>",
    "<NSLayoutConstraint:0x17028b040 SmallStory:0x113d2c5e0.width == SmallStory:0x113d2c3d0.width   (active)>",
    "<NSLayoutConstraint:0x17028b130 SmallStory:0x113d2c3d0.width == UIView:0x113d2c230.width   (active)>",
    "<NSLayoutConstraint:0x17028bbd0 H:|-(0)-[UIView:0x113e195a0]   (active, names: '|':SmallStory:0x113d2c5e0 )>",
    "<NSLayoutConstraint:0x17028bc20 H:[UIView:0x113e195a0]-(0)-|   (active, names: '|':SmallStory:0x113d2c5e0 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x17028ac80 H:[UIImageView:0x113e04f90]-(10)-[UILabel:0x113e31dc0]   (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2017-06-06 22:18:04.066582+0530 Jansatta[1096:258239] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want.
    Try this:
        (1) look at each constraint and try to figure out which you don't expect;
        (2) find the code that added the unwanted constraint or constraints and fix it.
    (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
    "<NSAutoresizingMaskLayoutConstraint:0x17028ca30 h=--& v=--& UIView:0x113d2c230.height == 0   (active)>",
    "<NSLayoutConstraint:0x17028aaa0 UIImageView:0x113e04f90.bottom == UIView:0x113e195a0.bottomMargin   (active)>",
    "<NSLayoutConstraint:0x17028ab40 UIImageView:0x113e04f90.top == UIView:0x113e195a0.topMargin   (active)>",
    "<NSLayoutConstraint:0x17028aff0 SmallStory:0x113d2c5e0.height == SmallStory:0x113d2c3d0.height   (active)>",
    "<NSLayoutConstraint:0x17028b270 SmallStory:0x113d2c3d0.height == 0.2*UIView:0x113d2c230.height   (active)>",
    "<NSLayoutConstraint:0x17028bc70 V:|-(0)-[UIView:0x113e195a0]   (active, names: '|':SmallStory:0x113d2c5e0 )>",
    "<NSLayoutConstraint:0x17028bcc0 V:[UIView:0x113e195a0]-(0)-|   (active, names: '|':SmallStory:0x113d2c5e0 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x17028aaa0 UIImageView:0x113e04f90.bottom == UIView:0x113e195a0.bottomMargin   (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2017-06-06 22:18:04.068461+0530 Jansatta[1096:258239] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want.
    Try this:
        (1) look at each constraint and try to figure out which you don't expect;
        (2) find the code that added the unwanted constraint or constraints and fix it.
    (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
    "<NSAutoresizingMaskLayoutConstraint:0x17028ca30 h=--& v=--& UIView:0x113d2c230.height == 0   (active)>",
    "<NSLayoutConstraint:0x174285e60 UIImageView:0x113d2c980.bottom == UIView:0x113d2d090.bottomMargin   (active)>",
    "<NSLayoutConstraint:0x174285eb0 UIImageView:0x113d2c980.top == UIView:0x113d2d090.topMargin   (active)>",
    "<NSLayoutConstraint:0x17028b270 SmallStory:0x113d2c3d0.height == 0.2*UIView:0x113d2c230.height   (active)>",
    "<NSLayoutConstraint:0x17028b9f0 V:|-(0)-[UIView:0x113d2d090]   (active, names: '|':SmallStory:0x113d2c3d0 )>",
    "<NSLayoutConstraint:0x17028ba40 V:[UIView:0x113d2d090]-(0)-|   (active, names: '|':SmallStory:0x113d2c3d0 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x174285e60 UIImageView:0x113d2c980.bottom == UIView:0x113d2d090.bottomMargin   (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2017-06-06 22:18:04.070615+0530 Jansatta[1096:258239] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want.
    Try this:
        (1) look at each constraint and try to figure out which you don't expect;
        (2) find the code that added the unwanted constraint or constraints and fix it.
    (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
    "<NSAutoresizingMaskLayoutConstraint:0x17028cad0 h=--& v=--& UIView:0x113d2c230.width == 0   (active)>",
    "<NSLayoutConstraint:0x1702873f0 UIImageView:0x113e331c0.width == 180   (active)>",
    "<NSLayoutConstraint:0x170287760 H:|-(10)-[UIImageView:0x113e331c0]   (active, names: '|':UIView:0x113e33e00 )>",
    "<NSLayoutConstraint:0x1702886b0 H:[UILabel:0x113e338d0]-(10)-|   (active, names: '|':UIView:0x113e33e00 )>",
    "<NSLayoutConstraint:0x170288570 H:[UIImageView:0x113e331c0]-(10)-[UILabel:0x113e338d0]   (active)>",
    "<NSLayoutConstraint:0x1702884d0 UILabel:0x113e338d0.leading == UILabel:0x113e333b0.leading   (active)>",
    "<NSLayoutConstraint:0x170288390 UILabel:0x113e333b0.trailing == UILabel:0x113e338d0.trailing   (active)>",
    "<NSLayoutConstraint:0x17028ae60 SmallStory:0x113e32fb0.width == SmallStory:0x113e324f0.width   (active)>",
    "<NSLayoutConstraint:0x17028aeb0 SmallStory:0x113e324f0.width == SmallStory:0x113d2c5e0.width   (active)>",
    "<NSLayoutConstraint:0x17028b040 SmallStory:0x113d2c5e0.width == SmallStory:0x113d2c3d0.width   (active)>",
    "<NSLayoutConstraint:0x17028b130 SmallStory:0x113d2c3d0.width == UIView:0x113d2c230.width   (active)>",
    "<NSLayoutConstraint:0x17028c030 H:|-(0)-[UIView:0x113e33e00]   (active, names: '|':SmallStory:0x113e32fb0 )>",
    "<NSLayoutConstraint:0x17028c080 H:[UIView:0x113e33e00]-(0)-|   (active, names: '|':SmallStory:0x113e32fb0 )>"
)*
</code>```

HOW TO SOLVE THIS PLEASE HELP

答:
Use stackView instead of 5 UIViews.

Why?

StackView works much more better than UIView that you are creating right now.

You can easily drop in any view, hide , show. No need to think about auto-layout between views in stackView.

I have just made what you made using one stackView.Just see the hierarchy

I have just set Fill equally in insepector

And the output without auto-layout issue.Just set top left bottom right constraint to 0 to superView for stackView

ContentLicense: CC BY-SA 4.0

Body:
I'm using UICollectionView & Flow Layout and Class for layout of collectionView Cell is as to achieve slide animation like feedly app Or insorts app

import UIKit
class UltravisualLayout: UICollectionViewLayout {
    fileprivate var contentWidth:CGFloat!
    fileprivate var contentHeight:CGFloat!
    fileprivate var yOffset:CGFloat = 0

    var maxAlpha:CGFloat = 1
    var minAlpha:CGFloat = 0

    var widthOffset:CGFloat = 0
    var heightOffset:CGFloat = 0

    fileprivate var cache = [UICollectionViewLayoutAttributes]()

    fileprivate var itemWidth:CGFloat{
        return (collectionView?.bounds.width)!
    }
    fileprivate var itemHeight:CGFloat{
        return (collectionView?.bounds.height)!
    }
    fileprivate var collectionViewHeight:CGFloat{
        return (collectionView?.bounds.height)!
    }

    fileprivate var numberOfItems:Int{
        return (collectionView?.numberOfItems(inSection: 0))!
    }

    fileprivate var dragOffset:CGFloat{
        return (collectionView?.bounds.height)!
    }
    fileprivate var currentItemIndex:Int{
        return max(0, Int(collectionView!.contentOffset.y / collectionViewHeight))
    }

    var nextItemBecomeCurrentPercentage:CGFloat{
        return (collectionView!.contentOffset.y / (collectionViewHeight)) - CGFloat(currentItemIndex)
    }

    override func prepare() {
        cache.removeAll(keepingCapacity: false)
        yOffset = 0

        for item in 0 ..< numberOfItems{

            let indexPath = IndexPath(item: item, section: 0)
            let attribute = UICollectionViewLayoutAttributes(forCellWith: indexPath)
            attribute.zIndex = -(indexPath as NSIndexPath).row

            if ((indexPath as NSIndexPath).item == currentItemIndex+1) && ((indexPath as NSIndexPath).item < numberOfItems){

                attribute.alpha = minAlpha + max((maxAlpha-minAlpha) * nextItemBecomeCurrentPercentage, 0)
                let width = itemWidth - widthOffset + (widthOffset * nextItemBecomeCurrentPercentage)
                let height = itemHeight - heightOffset + (heightOffset * nextItemBecomeCurrentPercentage)

                let deltaWidth =  width/itemWidth
                let deltaHeight = height/itemHeight

                attribute.frame = CGRect(x: 0, y: yOffset, width: itemWidth, height: itemHeight)
                attribute.transform = CGAffineTransform(scaleX: deltaWidth, y: deltaHeight)

                attribute.center.y = (collectionView?.center.y)! +  (collectionView?.contentOffset.y)!
                attribute.center.x = (collectionView?.center.x)! + (collectionView?.contentOffset.x)!
                yOffset += collectionViewHeight

            }else{
                attribute.frame = CGRect(x: 0, y: yOffset, width: itemWidth, height: itemHeight)
                attribute.center.y = (collectionView?.center.y)! + yOffset
                attribute.center.x = (collectionView?.center.x)!
                yOffset += collectionViewHeight
            }
            cache.append(attribute)
        }
    }

    //Return the size of ContentView
    override var collectionViewContentSize : CGSize {
        contentWidth = (collectionView?.bounds.width)!
        contentHeight = CGFloat(numberOfItems) * (collectionView?.bounds.height)!
        return CGSize(width: contentWidth, height: contentHeight)
    }

    //Return Attributes  whose frame lies in the Visible Rect
    override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
        var layoutAttributes = [UICollectionViewLayoutAttributes]()
        for attribute in cache{
            if attribute.frame.intersects(rect){
                layoutAttributes.append(attribute)
            }
        }
        return layoutAttributes
    }

    override func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool {
        return true
    }

    override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint, withScrollingVelocity velocity: CGPoint) -> CGPoint {
        let itemIndex = round(proposedContentOffset.y / (dragOffset))
        let yOffset = itemIndex * (collectionView?.bounds.height)!
        return CGPoint(x: 0, y: yOffset)
    }
    override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? {

        // Logic that calculates the UICollectionViewLayoutAttributes of the item
        // and returns the UICollectionViewLayoutAttributes
        return UICollectionViewLayoutAttributes(forCellWith: indexPath)
    }

}

I Created  custom view with Xib as

Class SmallStory

#import <UIKit/UIKit.h>
@interface SmallStory : UIView
@property (weak, nonatomic) IBOutlet UIImageView *image;
@property (weak, nonatomic) IBOutlet UILabel *title;
@property (weak, nonatomic) IBOutlet UILabel *pubDate;
@end

SmallStory.m

#import "SmallStory.h"
@interface SmallStory()
@property (nonatomic, strong) UIView *containerView;
@property (nonatomic, strong) NSMutableArray *customConstraints;

@end
@implementation SmallStory

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self customInit];
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self customInit];
    }
    return self;
}

- (void)customInit
{
    _customConstraints = [[NSMutableArray alloc] init];

    UIView *view = nil;
    NSArray *objects = [[NSBundle mainBundle] loadNibNamed:@"SmallStory"
                                                     owner:self
                                                   options:nil];
    for (id object in objects) {
        if ([object isKindOfClass:[UIView class]]) {
            view = object;
            break;
        }
    }

    if (view != nil) {
        _containerView = view;
        view.translatesAutoresizingMaskIntoConstraints = NO;
        [self addSubview:view];
        [self setNeedsUpdateConstraints];
    }
}
- (void)updateConstraints
{
    [self removeConstraints:self.customConstraints];
    [self.customConstraints removeAllObjects];

    if (self.containerView != nil) {
        UIView *view = self.containerView;
        NSDictionary *views = NSDictionaryOfVariableBindings(view);
        [self.customConstraints addObjectsFromArray:
         [NSLayoutConstraint constraintsWithVisualFormat:
          @"H:|[view]|" options:0 metrics:nil views:views]];
        [self.customConstraints addObjectsFromArray:
         [NSLayoutConstraint constraintsWithVisualFormat:
          @"V:|[view]|" options:0 metrics:nil views:views]];
        [self addConstraints:self.customConstraints];
    }

    [super updateConstraints];
}

- (UIViewController*)getSuperViewController
{
    for (UIView* next = [self superview]; next; next = next.superview)
    {
        UIResponder* nextResponder = [next nextResponder];

        if ([nextResponder isKindOfClass:[UIViewController class]])
        {
            return (UIViewController*)nextResponder;
        }
    }

    return nil;
}
@end

Xib Design Looks like

ided into 5 parts

and each small view is assigned as SmallStory Class

and Story Board Looks Like

When I run App There is Autolayout warnings as below

*2017-06-06 22:18:04.044717+0530 Jansatta[1096:258239] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want.
    Try this:
        (1) look at each constraint and try to figure out which you don't expect;
        (2) find the code that added the unwanted constraint or constraints and fix it.
    (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
    "<NSAutoresizingMaskLayoutConstraint:0x17028ca30 h=--& v=--& UIView:0x113d2c230.height == 0   (active)>",
    "<NSLayoutConstraint:0x1702875d0 UIImageView:0x113e32700.bottom == UIView:0x113e32e10.bottomMargin   (active)>",
    "<NSLayoutConstraint:0x170287260 UIImageView:0x113e32700.top == UIView:0x113e32e10.topMargin   (active)>",
    "<NSLayoutConstraint:0x17028af00 SmallStory:0x113e324f0.height == SmallStory:0x113d2c5e0.height   (active)>",
    "<NSLayoutConstraint:0x17028aff0 SmallStory:0x113d2c5e0.height == SmallStory:0x113d2c3d0.height   (active)>",
    "<NSLayoutConstraint:0x17028b270 SmallStory:0x113d2c3d0.height == 0.2*UIView:0x113d2c230.height   (active)>",
    "<NSLayoutConstraint:0x17028bea0 V:|-(0)-[UIView:0x113e32e10]   (active, names: '|':SmallStory:0x113e324f0 )>",
    "<NSLayoutConstraint:0x17028bef0 V:[UIView:0x113e32e10]-(0)-|   (active, names: '|':SmallStory:0x113e324f0 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x1702875d0 UIImageView:0x113e32700.bottom == UIView:0x113e32e10.bottomMargin   (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2017-06-06 22:18:04.047763+0530 Jansatta[1096:258239] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want.
    Try this:
        (1) look at each constraint and try to figure out which you don't expect;
        (2) find the code that added the unwanted constraint or constraints and fix it.
    (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
    "<NSAutoresizingMaskLayoutConstraint:0x17028cad0 h=--& v=--& UIView:0x113d2c230.width == 0   (active)>",
    "<NSLayoutConstraint:0x174285f00 H:|-(10)-[UIImageView:0x113d2c980]   (active, names: '|':UIView:0x113d2d090 )>",
    "<NSLayoutConstraint:0x174285f50 H:[UILabel:0x113d2ce00]-(10)-|   (active, names: '|':UIView:0x113d2d090 )>",
    "<NSLayoutConstraint:0x174285ff0 H:[UIImageView:0x113d2c980]-(10)-[UILabel:0x113d2ce00]   (active)>",
    "<NSLayoutConstraint:0x17028b130 SmallStory:0x113d2c3d0.width == UIView:0x113d2c230.width   (active)>",
    "<NSLayoutConstraint:0x17028b950 H:|-(0)-[UIView:0x113d2d090]   (active, names: '|':SmallStory:0x113d2c3d0 )>",
    "<NSLayoutConstraint:0x17028b9a0 H:[UIView:0x113d2d090]-(0)-|   (active, names: '|':SmallStory:0x113d2c3d0 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x174285ff0 H:[UIImageView:0x113d2c980]-(10)-[UILabel:0x113d2ce00]   (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2017-06-06 22:18:04.050793+0530 Jansatta[1096:258239] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want.
    Try this:
        (1) look at each constraint and try to figure out which you don't expect;
        (2) find the code that added the unwanted constraint or constraints and fix it.
    (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
    "<NSAutoresizingMaskLayoutConstraint:0x17028ca30 h=--& v=--& UIView:0x113d2c230.height == 0   (active)>",
    "<NSLayoutConstraint:0x170288840 UIImageView:0x113e331c0.bottom == UIView:0x113e33e00.bottomMargin   (active)>",
    "<NSLayoutConstraint:0x1702887a0 UIImageView:0x113e331c0.top == UIView:0x113e33e00.topMargin   (active)>",
    "<NSLayoutConstraint:0x1702892e0 SmallStory:0x113e32fb0.height == SmallStory:0x113e324f0.height   (active)>",
    "<NSLayoutConstraint:0x17028af00 SmallStory:0x113e324f0.height == SmallStory:0x113d2c5e0.height   (active)>",
    "<NSLayoutConstraint:0x17028aff0 SmallStory:0x113d2c5e0.height == SmallStory:0x113d2c3d0.height   (active)>",
    "<NSLayoutConstraint:0x17028b270 SmallStory:0x113d2c3d0.height == 0.2*UIView:0x113d2c230.height   (active)>",
    "<NSLayoutConstraint:0x17028c0d0 V:|-(0)-[UIView:0x113e33e00]   (active, names: '|':SmallStory:0x113e32fb0 )>",
    "<NSLayoutConstraint:0x17028c120 V:[UIView:0x113e33e00]-(0)-|   (active, names: '|':SmallStory:0x113e32fb0 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x170288840 UIImageView:0x113e331c0.bottom == UIView:0x113e33e00.bottomMargin   (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2017-06-06 22:18:04.054839+0530 Jansatta[1096:258239] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want.
    Try this:
        (1) look at each constraint and try to figure out which you don't expect;
        (2) find the code that added the unwanted constraint or constraints and fix it.
    (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
    "<NSAutoresizingMaskLayoutConstraint:0x17028ca30 h=--& v=--& UIView:0x113d2c230.height == 0   (active)>",
    "<NSLayoutConstraint:0x170287fd0 UIImageView:0x113e341b0.bottom == UIView:0x113e348c0.bottomMargin   (active)>",
    "<NSLayoutConstraint:0x170287f30 UIImageView:0x113e341b0.top == UIView:0x113e348c0.topMargin   (active)>",
    "<NSLayoutConstraint:0x1702892e0 SmallStory:0x113e32fb0.height == SmallStory:0x113e324f0.height   (active)>",
    "<NSLayoutConstraint:0x1702881b0 SmallStory:0x113e32fb0.height == SmallStory:0x113e33fa0.height   (active)>",
    "<NSLayoutConstraint:0x17028af00 SmallStory:0x113e324f0.height == SmallStory:0x113d2c5e0.height   (active)>",
    "<NSLayoutConstraint:0x17028aff0 SmallStory:0x113d2c5e0.height == SmallStory:0x113d2c3d0.height   (active)>",
    "<NSLayoutConstraint:0x17028b270 SmallStory:0x113d2c3d0.height == 0.2*UIView:0x113d2c230.height   (active)>",
    "<NSLayoutConstraint:0x17028c300 V:|-(0)-[UIView:0x113e348c0]   (active, names: '|':SmallStory:0x113e33fa0 )>",
    "<NSLayoutConstraint:0x17028c350 V:[UIView:0x113e348c0]-(0)-|   (active, names: '|':SmallStory:0x113e33fa0 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x170287fd0 UIImageView:0x113e341b0.bottom == UIView:0x113e348c0.bottomMargin   (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2017-06-06 22:18:04.058339+0530 Jansatta[1096:258239] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want.
    Try this:
        (1) look at each constraint and try to figure out which you don't expect;
        (2) find the code that added the unwanted constraint or constraints and fix it.
    (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
    "<NSAutoresizingMaskLayoutConstraint:0x17028cad0 h=--& v=--& UIView:0x113d2c230.width == 0   (active)>",
    "<NSLayoutConstraint:0x170287620 H:|-(10)-[UIImageView:0x113e32700]   (active, names: '|':UIView:0x113e32e10 )>",
    "<NSLayoutConstraint:0x170287670 H:[UILabel:0x113e32b80]-(10)-|   (active, names: '|':UIView:0x113e32e10 )>",
    "<NSLayoutConstraint:0x1702876c0 H:[UIImageView:0x113e32700]-(10)-[UILabel:0x113e32b80]   (active)>",
    "<NSLayoutConstraint:0x17028aeb0 SmallStory:0x113e324f0.width == SmallStory:0x113d2c5e0.width   (active)>",
    "<NSLayoutConstraint:0x17028b040 SmallStory:0x113d2c5e0.width == SmallStory:0x113d2c3d0.width   (active)>",
    "<NSLayoutConstraint:0x17028b130 SmallStory:0x113d2c3d0.width == UIView:0x113d2c230.width   (active)>",
    "<NSLayoutConstraint:0x17028be00 H:|-(0)-[UIView:0x113e32e10]   (active, names: '|':SmallStory:0x113e324f0 )>",
    "<NSLayoutConstraint:0x17028be50 H:[UIView:0x113e32e10]-(0)-|   (active, names: '|':SmallStory:0x113e324f0 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x1702876c0 H:[UIImageView:0x113e32700]-(10)-[UILabel:0x113e32b80]   (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2017-06-06 22:18:04.061159+0530 Jansatta[1096:258239] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want.
    Try this:
        (1) look at each constraint and try to figure out which you don't expect;
        (2) find the code that added the unwanted constraint or constraints and fix it.
    (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
    "<NSAutoresizingMaskLayoutConstraint:0x17028cad0 h=--& v=--& UIView:0x113d2c230.width == 0   (active)>",
    "<NSLayoutConstraint:0x17028a820 UIImageView:0x113e04f90.width == 180   (active)>",
    "<NSLayoutConstraint:0x17028aaf0 H:|-(10)-[UIImageView:0x113e04f90]   (active, names: '|':UIView:0x113e195a0 )>",
    "<NSLayoutConstraint:0x17028abe0 H:[UILabel:0x113e31dc0]-(10)-|   (active, names: '|':UIView:0x113e195a0 )>",
    "<NSLayoutConstraint:0x17028ac80 H:[UIImageView:0x113e04f90]-(10)-[UILabel:0x113e31dc0]   (active)>",
    "<NSLayoutConstraint:0x17028b040 SmallStory:0x113d2c5e0.width == SmallStory:0x113d2c3d0.width   (active)>",
    "<NSLayoutConstraint:0x17028b130 SmallStory:0x113d2c3d0.width == UIView:0x113d2c230.width   (active)>",
    "<NSLayoutConstraint:0x17028bbd0 H:|-(0)-[UIView:0x113e195a0]   (active, names: '|':SmallStory:0x113d2c5e0 )>",
    "<NSLayoutConstraint:0x17028bc20 H:[UIView:0x113e195a0]-(0)-|   (active, names: '|':SmallStory:0x113d2c5e0 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x17028a820 UIImageView:0x113e04f90.width == 180   (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2017-06-06 22:18:04.064548+0530 Jansatta[1096:258239] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want.
    Try this:
        (1) look at each constraint and try to figure out which you don't expect;
        (2) find the code that added the unwanted constraint or constraints and fix it.
    (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
    "<NSAutoresizingMaskLayoutConstraint:0x17028cad0 h=--& v=--& UIView:0x113d2c230.width == 0   (active)>",
    "<NSLayoutConstraint:0x17028aaf0 H:|-(10)-[UIImageView:0x113e04f90]   (active, names: '|':UIView:0x113e195a0 )>",
    "<NSLayoutConstraint:0x17028abe0 H:[UILabel:0x113e31dc0]-(10)-|   (active, names: '|':UIView:0x113e195a0 )>",
    "<NSLayoutConstraint:0x17028ac80 H:[UIImageView:0x113e04f90]-(10)-[UILabel:0x113e31dc0]   (active)>",
    "<NSLayoutConstraint:0x17028b040 SmallStory:0x113d2c5e0.width == SmallStory:0x113d2c3d0.width   (active)>",
    "<NSLayoutConstraint:0x17028b130 SmallStory:0x113d2c3d0.width == UIView:0x113d2c230.width   (active)>",
    "<NSLayoutConstraint:0x17028bbd0 H:|-(0)-[UIView:0x113e195a0]   (active, names: '|':SmallStory:0x113d2c5e0 )>",
    "<NSLayoutConstraint:0x17028bc20 H:[UIView:0x113e195a0]-(0)-|   (active, names: '|':SmallStory:0x113d2c5e0 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x17028ac80 H:[UIImageView:0x113e04f90]-(10)-[UILabel:0x113e31dc0]   (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2017-06-06 22:18:04.066582+0530 Jansatta[1096:258239] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want.
    Try this:
        (1) look at each constraint and try to figure out which you don't expect;
        (2) find the code that added the unwanted constraint or constraints and fix it.
    (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
    "<NSAutoresizingMaskLayoutConstraint:0x17028ca30 h=--& v=--& UIView:0x113d2c230.height == 0   (active)>",
    "<NSLayoutConstraint:0x17028aaa0 UIImageView:0x113e04f90.bottom == UIView:0x113e195a0.bottomMargin   (active)>",
    "<NSLayoutConstraint:0x17028ab40 UIImageView:0x113e04f90.top == UIView:0x113e195a0.topMargin   (active)>",
    "<NSLayoutConstraint:0x17028aff0 SmallStory:0x113d2c5e0.height == SmallStory:0x113d2c3d0.height   (active)>",
    "<NSLayoutConstraint:0x17028b270 SmallStory:0x113d2c3d0.height == 0.2*UIView:0x113d2c230.height   (active)>",
    "<NSLayoutConstraint:0x17028bc70 V:|-(0)-[UIView:0x113e195a0]   (active, names: '|':SmallStory:0x113d2c5e0 )>",
    "<NSLayoutConstraint:0x17028bcc0 V:[UIView:0x113e195a0]-(0)-|   (active, names: '|':SmallStory:0x113d2c5e0 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x17028aaa0 UIImageView:0x113e04f90.bottom == UIView:0x113e195a0.bottomMargin   (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2017-06-06 22:18:04.068461+0530 Jansatta[1096:258239] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want.
    Try this:
        (1) look at each constraint and try to figure out which you don't expect;
        (2) find the code that added the unwanted constraint or constraints and fix it.
    (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
    "<NSAutoresizingMaskLayoutConstraint:0x17028ca30 h=--& v=--& UIView:0x113d2c230.height == 0   (active)>",
    "<NSLayoutConstraint:0x174285e60 UIImageView:0x113d2c980.bottom == UIView:0x113d2d090.bottomMargin   (active)>",
    "<NSLayoutConstraint:0x174285eb0 UIImageView:0x113d2c980.top == UIView:0x113d2d090.topMargin   (active)>",
    "<NSLayoutConstraint:0x17028b270 SmallStory:0x113d2c3d0.height == 0.2*UIView:0x113d2c230.height   (active)>",
    "<NSLayoutConstraint:0x17028b9f0 V:|-(0)-[UIView:0x113d2d090]   (active, names: '|':SmallStory:0x113d2c3d0 )>",
    "<NSLayoutConstraint:0x17028ba40 V:[UIView:0x113d2d090]-(0)-|   (active, names: '|':SmallStory:0x113d2c3d0 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x174285e60 UIImageView:0x113d2c980.bottom == UIView:0x113d2d090.bottomMargin   (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2017-06-06 22:18:04.070615+0530 Jansatta[1096:258239] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want.
    Try this:
        (1) look at each constraint and try to figure out which you don't expect;
        (2) find the code that added the unwanted constraint or constraints and fix it.
    (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
    "<NSAutoresizingMaskLayoutConstraint:0x17028cad0 h=--& v=--& UIView:0x113d2c230.width == 0   (active)>",
    "<NSLayoutConstraint:0x1702873f0 UIImageView:0x113e331c0.width == 180   (active)>",
    "<NSLayoutConstraint:0x170287760 H:|-(10)-[UIImageView:0x113e331c0]   (active, names: '|':UIView:0x113e33e00 )>",
    "<NSLayoutConstraint:0x1702886b0 H:[UILabel:0x113e338d0]-(10)-|   (active, names: '|':UIView:0x113e33e00 )>",
    "<NSLayoutConstraint:0x170288570 H:[UIImageView:0x113e331c0]-(10)-[UILabel:0x113e338d0]   (active)>",
    "<NSLayoutConstraint:0x1702884d0 UILabel:0x113e338d0.leading == UILabel:0x113e333b0.leading   (active)>",
    "<NSLayoutConstraint:0x170288390 UILabel:0x113e333b0.trailing == UILabel:0x113e338d0.trailing   (active)>",
    "<NSLayoutConstraint:0x17028ae60 SmallStory:0x113e32fb0.width == SmallStory:0x113e324f0.width   (active)>",
    "<NSLayoutConstraint:0x17028aeb0 SmallStory:0x113e324f0.width == SmallStory:0x113d2c5e0.width   (active)>",
    "<NSLayoutConstraint:0x17028b040 SmallStory:0x113d2c5e0.width == SmallStory:0x113d2c3d0.width   (active)>",
    "<NSLayoutConstraint:0x17028b130 SmallStory:0x113d2c3d0.width == UIView:0x113d2c230.width   (active)>",
    "<NSLayoutConstraint:0x17028c030 H:|-(0)-[UIView:0x113e33e00]   (active, names: '|':SmallStory:0x113e32fb0 )>",
    "<NSLayoutConstraint:0x17028c080 H:[UIView:0x113e33e00]-(0)-|   (active, names: '|':SmallStory:0x113e32fb0 )>"
)*

HOW TO SOLVE THIS PLEASE HELP


问:
React - render() not called with setState with axios
I am trying to fetch an array of movies and after it fetches the list it updates the state and the list should render, but the problem is the render method never calls from inside the axios callback, here is my code below

```<code>export default class Movies extends Component {
    constructor(props){
      super(props);

      this.state={movies:[]};
    }

    componentDidMount(){

      axios.get('URL')
            .then(response => {
              this.setState({movies:response.data});
              console.log("Movies",this.state);// I get the values here see screenshot..

      });
  }

  render(){
    return(
      <div className="row">
        <div className="col-md-3">
          <MovieList movies={this.state.movies}/>
        </div>
        <div className="col-md-6">Movie Details</div>
      </div>
    );
  }
}
</code>```

As you can see the code above, in function componentDidMount in the axios callback I am setting the response values to the state, but it doesn't call the render after doing it, the block does execute well as I get the log properly see screenshot below

I am not understanding why it doesn't call render() ? I have tried couple of solutions available but none works for me, if I hardcode the videos array in default state it works fine, please help if anyone know the solution.

Update(Adding MovieList Code)

```<code>class ListItem extends Component {
  render(){
    return(
      <li className="list-group-item">{this.props.moviename}</li>
    );
  }
}

export default class MoviesList extends Component {
  constructor(props) {
    super(props);
    console.log("Props",props);
    this.state={movies:props.movies};
  }

  renderList(){

    const items=this.state.movies.map((movie) => <ListItem moviename={movie.name} key={movie.name}/>);

    return items;
  }

  render(){
    return(
      <ul className="list-group">
        <li className="list-group-item"><h3>Movies</h3></li>
        {this.renderList()}
      </ul>
    );
  }
}
</code>```

Thanks.

答:
The problem you are getting is in ListItem Component.
In order to get it work you need to work with componentWillReceiveProps

In this case, construct is called only once
Because of that your component won't update. You need to use function componentWillReceiveProps , this function will run every time component receive new data.

Example:

```<code>componentwillreceiveprops(nextProps){
 this.setState({
   movies: nextProps.movies
})
}
</code>```

Body:
I am trying to fetch an array of movies and after it fetches the list it updates the state and the list should render, but the problem is the render method never calls from inside the axios callback, here is my code below

export default class Movies extends Component {
    constructor(props){
      super(props);

      this.state={movies:[]};
    }

    componentDidMount(){

      axios.get('URL')
            .then(response => {
              this.setState({movies:response.data});
              console.log("Movies",this.state);// I get the values here see screenshot..

      });
  }

  render(){
    return(

          <MovieList movies={this.state.movies}/>

Movie Details

    );
  }
}

As you can see the code above, in function componentDidMount in the axios callback I am setting the response values to the state, but it doesn't call the render after doing it, the block does execute well as I get the log properly see screenshot below

I am not understanding why it doesn't call render() ? I have tried couple of solutions available but none works for me, if I hardcode the videos array in default state it works fine, please help if anyone know the solution.

Update(Adding MovieList Code)

class ListItem extends Component {
  render(){
    return(

{this.props.moviename}

    );
  }
}

export default class MoviesList extends Component {
  constructor(props) {
    super(props);
    console.log("Props",props);
    this.state={movies:props.movies};
  }

  renderList(){

    const items=this.state.movies.map((movie) => <ListItem moviename={movie.name} key={movie.name}/>);

    return items;
  }

  render(){
    return(

Movies

        {this.renderList()}

    );
  }
}

Thanks.

Body:
The problem you are getting is in ListItem Component.
In order to get it work you need to work with componentWillReceiveProps

In this case, construct is called only once
Because of that your component won't update. You need to use function componentWillReceiveProps , this function will run every time component receive new data.

Example:

componentwillreceiveprops(nextProps){
 this.setState({
   movies: nextProps.movies
})
}


问:
IronPython For Unit Testing over C#
We know that Python provides a  lot of productivity over any compiled languages. We have programming in C# & need to write the unit test cases in C# itself. If we see the amount of code we write for unit test is approximately ten times more than the original code.

Is it ideal choice to write unit test cases in IronPython instead of C#? Any body has done like that? I wrote few test cases, they seems to be good. But hairy pointy managers won't accept.

答:
I gotta go with Will and Jon..

I would prefer my tests be in the same language as the code I'm testing; it causes fewer cognitive context switches.  But maybe I'm just not as mentally agile as I once was.

Jon

OwnerDisplayName: Krish

Title: IronPython For Unit Testing over C#

LastEditorDisplayName: Kozyarchuk

OwnerDisplayName: jdharley


问:
Blackberry http connection problem
My app uses an http connection to a server.
On the 9550 BlackBerry simulator, it runs fine but when I run it on an 8520 simulator it gives the error

java.io.IOException:Tunnel Failed.

Why is this happening?

答:
Have a look at these StackOverflow topics:

Tunnel Failed, BlackBerry Curve 8900

Are socket connections faster than http on Blackberry?.

Title: Blackberry http connection problem


问:
How do I execute a Java/Python program multiple times?
I am currently working on an assignment, where the task is to measure the execution time for a number of programs in both Python and Java, for the purpose of measuring and comparing performance for the two computer languages. I have 10 tests in total, in sets of 2; for every set, one test is written in Java and the corresponding one is written in Python, and so forth. I want to run every test multiple times, e.g. 100 times, and measure the time for every run. Then I'd like to compute the sum of the obtained execution time(s). How would I do this in Python/Java? I have tried writing a double for-loop like this:

```<code>for i in range(1, 100):
for j in range(1, 10000000):
# do integer division
</code>```

...but it doesn't seem to work. Also I'd like to do the same thing in Java. How would I do this?

答:
```<code>            long startTime = 0;
            for(int i = 0; i <= 100; i++){
                startTime = System.nanoTime();
                for(int j = 0; j <= 10000000; j++){
                    //Do integer division
                }
            }
            long endTime = System.nanoTime();
            long duration = (endTime - startTime);
            System.out.println(duration);
</code>```

I think that's what i'ts going to look like in Java.

Body:
I am currently working on an assignment, where the task is to measure the execution time for a number of programs in both Python and Java, for the purpose of measuring and comparing performance for the two computer languages. I have 10 tests in total, in sets of 2; for every set, one test is written in Java and the corresponding one is written in Python, and so forth. I want to run every test multiple times, e.g. 100 times, and measure the time for every run. Then I'd like to compute the sum of the obtained execution time(s). How would I do this in Python/Java? I have tried writing a double for-loop like this:

for i in range(1, 100):
for j in range(1, 10000000):
# do integer division

...but it doesn't seem to work. Also I'd like to do the same thing in Java. How would I do this?

Body:
            long startTime = 0;
            for(int i = 0; i <= 100; i++){
                startTime = System.nanoTime();
                for(int j = 0; j <= 10000000; j++){
                    //Do integer division
                }
            }
            long endTime = System.nanoTime();
            long duration = (endTime - startTime);
            System.out.println(duration);

I think that's what i'ts going to look like in Java.


问:
finding non linear equation python scipy
I am new to analytics , I am looking for a solution to find a model to solve non linear equation of the form Y=a(X1^b) + c(X2^d) + e ( where X1 , X2 are independent variables)
Below is a full set , unfortunately we dont have much observations , all we need is any simple fit.But this data does not have any outliers , every observations has to be considered.

```<code>import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
import numpy as np
import sympy as sym

x1=np.array([217,160,97,75])
x2=np.array([5.319751464,6.88536761,5.319751464,5.319751464])
x3=np.array([143.420635344,36.7384534912,23.420635344,1.420635344])
y=np.array([14,7,7,1])

def func(X, a, b, c ,d , e ):
    x1,x2 = X
    return a*x1**b + c*x2**d + e

popt, pcov = curve_fit(func, (x1,x2), y)

plt.plot(y, func((x1,x2), *popt), label="Fitted Curve")
plt.legend(loc='upper left')
plt.show()
</code>```

but running curve_fit gives me error saying that the

TypeError: Improper input: N=5 must not exceed M=4

Then i had to add few more dummy inputs as observations of almost similar values adding decimal point difference which resulted in error

```<code>x1=np.array([217,160,97,75,76,219])
x2=np.array([5.319751464,6.88536761,5.319751464,5.319751464,5.319751464,5.319751464])
x3=np.array([143.420635344,36.7384534912,23.420635344,1.420635344,1.420635344,143.420635344])
y=np.array([14,7,7,1,1,14])
</code>```

RuntimeError: Optimal parameters not found: Number of calls to
  function has reached maxfev = 1200.

Then I had to remove variable d and keep function as

```<code>def func(X, a, b, c ,e ):
    x1,x2 = X
    return a*x1**b + c*x2 + e
</code>```

Finally it did run but again with below warning , but results are not good

RuntimeWarning: overflow encountered in power

Note that

x3 = max(x2 - {(x1^2)*2.6},0)

and solving

y=a*(x3^b) gives a=0.89 and b=0.58 with r2=0.98 and error=0.19 which is the best one i could get so far

But i would like to have the result in a generalised form without me trying to equate a relation. Because based on data set ,the function x3=f(x1,x2) can change and it is not a fixed equation for all cases.

答: A very good approach to get acceptable fit results is the use of initial guesses of the free parameters. curve_fit takes a p0 argument. If your data does not vary too much between two data sets, this should be a proper way. In my experience, taking some afford to guess good start values p0 and set limits by the parameter boundsis a good approach. Otherwise you could try to interpolate the data, if you don't have to know the mathematical relation.

Body:
I am new to analytics , I am looking for a solution to find a model to solve non linear equation of the form Y=a(X1^b) + c(X2^d) + e ( where X1 , X2 are independent variables)
Below is a full set , unfortunately we dont have much observations , all we need is any simple fit.But this data does not have any outliers , every observations has to be considered.

import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
import numpy as np
import sympy as sym

x1=np.array([217,160,97,75])
x2=np.array([5.319751464,6.88536761,5.319751464,5.319751464])
x3=np.array([143.420635344,36.7384534912,23.420635344,1.420635344])
y=np.array([14,7,7,1])

def func(X, a, b, c ,d , e ):
    x1,x2 = X
    return a*x1**b + c*x2**d + e

popt, pcov = curve_fit(func, (x1,x2), y)

plt.plot(y, func((x1,x2), *popt), label="Fitted Curve")
plt.legend(loc='upper left')
plt.show()

but running curve_fit gives me error saying that the

TypeError: Improper input: N=5 must not exceed M=4

Then i had to add few more dummy inputs as observations of almost similar values adding decimal point difference which resulted in error

x1=np.array([217,160,97,75,76,219])
x2=np.array([5.319751464,6.88536761,5.319751464,5.319751464,5.319751464,5.319751464])
x3=np.array([143.420635344,36.7384534912,23.420635344,1.420635344,1.420635344,143.420635344])
y=np.array([14,7,7,1,1,14])

RuntimeError: Optimal parameters not found: Number of calls to
  function has reached maxfev = 1200.

Then I had to remove variable d and keep function as

def func(X, a, b, c ,e ):
    x1,x2 = X
    return a*x1**b + c*x2 + e

Finally it did run but again with below warning , but results are not good

RuntimeWarning: overflow encountered in power

Note that

x3 = max(x2 - {(x1^2)*2.6},0)

and solving

y=a*(x3^b) gives a=0.89 and b=0.58 with r2=0.98 and error=0.19 which is the best one i could get so far

But i would like to have the result in a generalised form without me trying to equate a relation. Because based on data set ,the function x3=f(x1,x2) can change and it is not a fixed equation for all cases.


问:
Can't install twython on Python 3.2 (Raspberry Pi)
I'm trying to install twython, but keep getting errors.

First attempt:

```<code>pi@raspberrypi ~/twython $ sudo pip-3.2 install twython
</code>```

```<code> Running setup.py egg_info for package requests
    Traceback (most recent call last):
      File "<string>", line 14, in <module>
      File "/home/pi/twython/build/requests/setup.py", line 52, in <module>
        exec(f.read(), about)
      File "<string>", line 14
        __cake__ = u'\u2728 \U0001f370 \u2728'
                                             ^
    SyntaxError: invalid syntax
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):

  File "<string>", line 14, in <module>

  File "/home/pi/twython/build/requests/setup.py", line 52, in <module>

    exec(f.read(), about)

  File "<string>", line 14

    __cake__ = u'\u2728 \U0001f370 \u2728'

                                         ^

SyntaxError: invalid syntax

----------------------------------------
Command python setup.py egg_info failed with error code 1 in /home/pi/twython/build/requests
</code>```

Next I searched on the last line of the error and followed some suggestions that said to make sure setuptools and ez_install were installed and up to date, but that didn't help.

Then I followed the backup instructions on ReadtheDocs that said to try to install it this way:

```<code>git clone git://github.com/ryanmcgrath/twython.git
cd twython
sudo python3 setup.py install
</code>```

but it failed again:

```<code>  File "/usr/lib/python3/dist-packages/setuptools/command/easy_install.py", line 640, in install_item
    self.process_distribution(spec, dist, deps)
  File "/usr/lib/python3/dist-packages/setuptools/command/easy_install.py", line 692, in process_distribution
    [requirement], self.local_index, self.easy_install
  File "/usr/lib/python3/dist-packages/pkg_resources.py", line 576, in resolve
    dist = best[req.key] = env.best_match(req, self, installer)
  File "/usr/lib/python3/dist-packages/pkg_resources.py", line 822, in best_match
    return self.obtain(req, installer) # try and download/install
  File "/usr/lib/python3/dist-packages/pkg_resources.py", line 834, in obtain
    return installer(requirement)
  File "/usr/lib/python3/dist-packages/setuptools/command/easy_install.py", line 608, in easy_install
    return self.install_item(spec, dist.location, tmpdir, deps)
  File "/usr/lib/python3/dist-packages/setuptools/command/easy_install.py", line 638, in install_item
    dists = self.install_eggs(spec, download, tmpdir)
  File "/usr/lib/python3/dist-packages/setuptools/command/easy_install.py", line 828, in install_eggs
    return self.build_and_install(setup_script, setup_base)
  File "/usr/lib/python3/dist-packages/setuptools/command/easy_install.py", line 1105, in build_and_install
    self.run_setup(setup_script, setup_base, args)
  File "/usr/lib/python3/dist-packages/setuptools/command/easy_install.py", line 1094, in run_setup
    run_setup(setup_script, args)
  File "/usr/lib/python3/dist-packages/setuptools/sandbox.py", line 31, in run_setup
    lambda: exec(compile(open(
  File "/usr/lib/python3/dist-packages/setuptools/sandbox.py", line 73, in run
    return func()
  File "/usr/lib/python3/dist-packages/setuptools/sandbox.py", line 34, in <lambda>
    {'__file__':setup_script, '__name__':'__main__'})
  File "setup.py", line 52, in <module>

Error in atexit._run_exitfuncs:
TypeError: 'NoneType' object is not callable
</code>```

答:
It turns out that Twython cannot work with Python v3.2 because it depends on the requests module which apparently is not supported in Python 3.2.

One of the developers of Twython just explained this to me on Twitter.

Body:
I'm trying to install twython, but keep getting errors.

First attempt:

pi@raspberrypi ~/twython $ sudo pip-3.2 install twython

 Running setup.py egg_info for package requests
    Traceback (most recent call last):
      File "<string>", line 14, in <module>
      File "/home/pi/twython/build/requests/setup.py", line 52, in <module>
        exec(f.read(), about)
      File "<string>", line 14
        __cake__ = u'\u2728 \U0001f370 \u2728'
                                             ^
    SyntaxError: invalid syntax
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):

  File "<string>", line 14, in <module>

  File "/home/pi/twython/build/requests/setup.py", line 52, in <module>

    exec(f.read(), about)

  File "<string>", line 14

    __cake__ = u'\u2728 \U0001f370 \u2728'

                                         ^

SyntaxError: invalid syntax

----------------------------------------
Command python setup.py egg_info failed with error code 1 in /home/pi/twython/build/requests

Next I searched on the last line of the error and followed some suggestions that said to make sure setuptools and ez_install were installed and up to date, but that didn't help.

Then I followed the backup instructions on ReadtheDocs that said to try to install it this way:

git clone git://github.com/ryanmcgrath/twython.git
cd twython
sudo python3 setup.py install

but it failed again:

  File "/usr/lib/python3/dist-packages/setuptools/command/easy_install.py", line 640, in install_item
    self.process_distribution(spec, dist, deps)
  File "/usr/lib/python3/dist-packages/setuptools/command/easy_install.py", line 692, in process_distribution
    [requirement], self.local_index, self.easy_install
  File "/usr/lib/python3/dist-packages/pkg_resources.py", line 576, in resolve
    dist = best[req.key] = env.best_match(req, self, installer)
  File "/usr/lib/python3/dist-packages/pkg_resources.py", line 822, in best_match
    return self.obtain(req, installer) # try and download/install
  File "/usr/lib/python3/dist-packages/pkg_resources.py", line 834, in obtain
    return installer(requirement)
  File "/usr/lib/python3/dist-packages/setuptools/command/easy_install.py", line 608, in easy_install
    return self.install_item(spec, dist.location, tmpdir, deps)
  File "/usr/lib/python3/dist-packages/setuptools/command/easy_install.py", line 638, in install_item
    dists = self.install_eggs(spec, download, tmpdir)
  File "/usr/lib/python3/dist-packages/setuptools/command/easy_install.py", line 828, in install_eggs
    return self.build_and_install(setup_script, setup_base)
  File "/usr/lib/python3/dist-packages/setuptools/command/easy_install.py", line 1105, in build_and_install
    self.run_setup(setup_script, setup_base, args)
  File "/usr/lib/python3/dist-packages/setuptools/command/easy_install.py", line 1094, in run_setup
    run_setup(setup_script, args)
  File "/usr/lib/python3/dist-packages/setuptools/sandbox.py", line 31, in run_setup
    lambda: exec(compile(open(
  File "/usr/lib/python3/dist-packages/setuptools/sandbox.py", line 73, in run
    return func()
  File "/usr/lib/python3/dist-packages/setuptools/sandbox.py", line 34, in <lambda>
    {'__file__':setup_script, '__name__':'__main__'})
  File "setup.py", line 52, in <module>

Error in atexit._run_exitfuncs:
TypeError: 'NoneType' object is not callable


问:
iOS simulator test multi-player games
I'm using iOS SpriteKit and Socket.io to create a simple multiplayer game, what is a elegant way to build and test it on multiple simulator (or actual iOS devices) and be able to see logs?

I see some post like this one Xcode6: Run two instances of the simulator which you can run two simulator, but I will have to run it on one simulator, stop it and start the second one. In this way it's making testing complicated and I'm not able to see logs of the first simulator.

Is there a better solution?

答: Xcode9 will support running multiple simulator at same time.</p>

Title: iOS simulator test multi-player games