Apple beats earnings forecast despite decline in iPhone sales